How do I get a custom localized string in the front end?

211 Views Asked by At

I'm having trouble accessing localizations, the value always appears in the default language.

I have two resource files in App_GlobalResources:

  • Resource.resx contains a string with the name "Hello" and the value of "World".

  • Resource.fr.resx contains a string with the name "Hello" and the value of "Monde"

In my Razor template:

<lang:string key="Resource, Resources.Resource.Hello" xmlns:lang="http://www.composite.net/ns/localization/1.0" />

"World" is always displayed, never "Monde", even when viewing the page in French.


In a vanilla asp.net website template, with the same resources, the following code within a Razor template displays "Monde"

String cultureInfo = "fr-CA";
System.Threading.Thread.CurrentThread.CurrentCulture = 
System.Globalization.CultureInfo.CreateSpecificCulture(cultureInfo);
System.Threading.Thread.CurrentThread.CurrentUICulture = new 
System.Globalization.CultureInfo(cultureInfo);
Response.Write(ObjectInfo.Print(Resources.Resource.Hello));

However, within C1 it results in "World".


How should I be going about this?

Thanks!

1

There are 1 best solutions below

3
Pauli Østerø On

The <lang:string construct is mainly meant for XSLT templates and functions where you can't as easily fallback to calling c# code directly as in Razor.

Have you tried printing out the resource on your Razor template like this instead @Resources.Resource.Hello ?