6

The Razor mediator allows for some formatting of datetime fields when they are rendered. For example,

@Metadata.EventDate.ToString("MMMM")

will render out the full text of the month. However, for translated sites I need to be able to select the language of the month it produces, ie. "janvier" instead of "January".

I've tried passing in a culture info indicator:

@{
var culture = new CultureInfo("fr-FR");
var month = Metadata.EventDate.ToString("MMMM", culture);
}

and doing the same in a single line:

@{
var month = Metadata.EventDate.ToString("MMMM", new CultureInfo("fr-FR"))
}

However neither option passes the validation in order to save my TBB. I also haven't been able to find any mention of this scenario in the Razor Mediator documentation.

Is there a way to define what language the month in a datetime will be displayed in?

8

It turns out that I was on the correct path, but had missed adding the proper using statement to my TBB. By inserting

@using System.Globalization;

at the top of my TBB I was able to use either of the methods that I tried originally without issue.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.