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:
- Display any date in Liquid using the format
%A %e %B %Y - 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)
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.csto theLocalizationfeature.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!
It won’t have any effect as OC’s View engine is overriding
TemplateOptionswithCurrentUICulture