Hello,
how can I change culture and hostname of an Umbraco node using razor?
I tried using this code:
@using System.Globalization
System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("fr-FR");
System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("fr-FR");
But, for example, the dictionary items of this node are in english, instead of french.
Yes, my suggestion will only work in a Razor View, as it is the context of the View that enables you to set the underlying culture in this way.
You could handle changing the language, by putting something like this in /Views/_ViewStart.cshtml and you'd trigger a languag change by requesting ?lang=Fr-fr on a url / set and read from your cookie here:
@using System.Globalization
@using System.Web.Services.Protocols
@{
Layout = null;
var lang = "en-GB";
if (!Request["lang"].IsEmpty())
{
lang = Request["lang"];
// check if valid culture
if (CultureInfo.GetCultures(CultureTypes.SpecificCultures).Any(f=>f.TwoLetterISOLanguageName == lang || f.Name.ToLower() == lang.ToLower()))
{
// set cookie...
Culture = UICulture = lang;
}
}
else {
// is cookie set
// get lang from cookie
// set culture
Culture = UICulture = lang;
}
}
Change culture and hostname in razor
Hello, how can I change culture and hostname of an Umbraco node using razor?
I tried using this code:
But, for example, the dictionary items of this node are in english, instead of french.
Hi Bob
Yes you can set the Culture and UICulture for the 'WebPageRenderingBase' class used by your razor view. Umbraco Dictionary works off of the UICulture.
You could set this in your razor view by just having:
and this would output
Bonjour
regards
Marc
Hello marc and thank you for your response.
I tried your code but the dictionary item still remains in english...
Sorry Marc, the page remained in english because of the cache.
Now I receive a compiler error CS0103:
And I still use this namespace:
... strange ...
Hi Bob
veryy strange... my whole razor file is just:
what is the model for your view ?
I use this code on an helper method.
And now it works... I had the dictionary item in the language that I take from the cookie.
If I add your code, I receive the previous error.
Hi Bob
Yes, my suggestion will only work in a Razor View, as it is the context of the View that enables you to set the underlying culture in this way.
You could handle changing the language, by putting something like this in /Views/_ViewStart.cshtml and you'd trigger a languag change by requesting ?lang=Fr-fr on a url / set and read from your cookie here:
if that makes sense ?
Yup, this is another interesting solution :) thank you
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.