This is the code for the helper class. I have read that it only changes the language for the current request, but it is one of the solutions that pop up, again and again, so I included it in my list of "stuff I have already tried"..
public static void SetLanguage(string language)
{
CultureInfo newLanguage = new CultureInfo(language);
System.Threading.Thread.CurrentThread.CurrentCulture = newLanguage;
System.Threading.Thread.CurrentThread.CurrentUICulture = newLanguage;
}
Maybe your code is working, because it's inside code for Authorization. Such could would possibly be called on every request, and thus the culture is always switched.
Finally found a solution.
We made an extention method for IIdentity, that uses the code from Alex. We then just call this code on every template, and it works.
Changing current culture on the fly
Hello!
I have been searching high and low, for a solution to my problem. Most of the solutions are the same, but none of them seems to work.
I want to change the culture of my website, on the fly, but I just can't get it to work.
I have mainly tried two different things:
Calling it from a helper class, this does not work. I also tried:
Did not work either.
So, do any of you know what works?
Hi Andreas
Where are you inserting this code?
The top code is in a helper class. I have tried to call it from a template, and from a surface controller.
The bottom code, I have tried to call it from the template.
The template is the "highest" parent template.
Can you show your helper class?
This code changes the culture for the current request.
This is the code for the helper class. I have read that it only changes the language for the current request, but it is one of the solutions that pop up, again and again, so I included it in my list of "stuff I have already tried"..
Hi Andreas,
This code is working for me:
I use it in "UmbracoAuthorizedJsonController", and culture is really switching after calling this code.
What version of Umbraco are you using?
Alex
I use v. 7.5.14.
Maybe your code is working, because it's inside code for Authorization. Such could would possibly be called on every request, and thus the culture is always switched.
Finally found a solution. We made an extention method for IIdentity, that uses the code from Alex. We then just call this code on every template, and it works.
is working on a reply...