OrchardCore: Can't specify a culture when rendering dates in liquid

Describe the bug

Can’t specify culture when rendering dates in liquid. For example the code…

{{ Model.ContentItem.Content.Session.Date.Value | date: "%A %e %B %Y" }}

…renders ‘Zaterdag 6 november 2021’ on my development machine with a Dutch OS. But when I deploy this code to my webserver with an English OS, it renders ‘Saturday 6 November 2021’. As the site is completely in Dutch, I want to able to specify a culture here.

I tried this piece of code in startup.cs…

services.Configure<TemplateOptions>(options =>
{
    options.CultureInfo = new System.Globalization.CultureInfo("nl-BE");
});

…but it made no difference.

To Reproduce

Steps to reproduce the behavior:

  1. Display any date in Liquid using the format %A %e %B %Y
  2. Try to show the results in a different language than your OS.

Expected behavior

I want to able to specify a culture.

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 15 (15 by maintainers)

Most upvoted comments

Also if you enable the localization module this will be done automcatically

Actually, I should have listened to this advice.

Dug deeper in what happened to the default culture, and saw https://github.com/OrchardCMS/OrchardCore/pull/3732 and https://github.com/OrchardCMS/OrchardCore/issues/3559. The default culture setting was moved from SiteSettings.cs to the Localization feature.

After enabling this feature, everything worked fine. I hestitated to enable the feature because I thought it would also enable content item localization, which I do not want. However, that is a seperate feature.

Hope my experience can help someone in the future.

Thanks guys!

Try to Set the CurrentCulture

It won’t have any effect as OC’s View engine is overriding TemplateOptions with CurrentUICulture