Im using Umbraco 7 with a web user control. I have a template set with culture and hostnames set as inherited and on my user control page load event i add
Thread.CurrentThread.CurrentCulture = new CultureInfo("de-DE");
Thread.CurrentThread.CurrentUICulture = new CultureInfo("de-DE");
I have an resx file setup but the info never pulls through for Germany?
Ah i think i know what you're asking. So i right clicked the root node at the top of the page and that is set to en-US against the domain name.
I then have a usercontrol further down the line, where i would like to override or set a new culture and language so the content in me resx would display.
Sorry for the multiple edits. How about Page load? I can set it there to get the info from my resx file (unless it can be automatically which is great)?
just tried this and this didnt work either :-(
var Newculture = new System.Globalization.CultureInfo("de-DE");
System.Globalization.CultureInfo.DefaultThreadCurrentCulture = Newculture;
System.Globalization.CultureInfo.DefaultThreadCurrentUICulture = Newculture;
lblInfo.Text = (string)GetGlobalResourceObject("Resource", "Info");
The template lang is set to en and inherit on the nodes but on page load i look at the variables and theyre set to German (or whatever i set it to) if i enter the below code i can see the name set by the above code
Newculture.EnglishName;
not sure what the heck is going on? I then viewed page source and can see href lang="en". Changed to "de" which didnt make a difference unless im missing something?
Hoping someone could point me in the right direction?
THANK YOU Alex - This is now working. Thanks again very much. Hopefully i dont come across any more issues but really thankful for getting me on track.
Just a side question :-). If i want to swap between languages could i store the value in session so if a user goes from German to English to Russian over multiple pages it would display the appropriate language selected?
You can store in the session selected language, but as I understood page language is English but you need to show German - isn't it an issue we solved?
Yes it is an issue that's resolved but just in case I need to add more languages in future.
I didn't want to complicate things but I save the data in the database for Germany and United Kingdom. I have one template/page and can load the data. The problem I was having certain static words on the template were not displaying in German.
The above resolved that but I thought to make it a little more reusable where if I need to add another country in future I could save the language in session and load the same template with another country's language.
How to set culture from code-behind
Im using Umbraco 7 with a web user control. I have a template set with culture and hostnames set as inherited and on my user control page load event i add
I have an resx file setup but the info never pulls through for Germany?
Any pointers please?
Hi J
Can you check what culture is set to the domain you are running in Umbraco? Check hostnames and cultures for the root node
Thanks,
Alex
Hi Alex the root is set to inherit?
Thanks
Hi J
What about the domains section? Did you add the domain you use?
Ah i think i know what you're asking. So i right clicked the root node at the top of the page and that is set to en-US against the domain name.
I then have a usercontrol further down the line, where i would like to override or set a new culture and language so the content in me resx would display.
Many thanks
J, if you want to render "de-DE" in the English version page I think you have to set the culture in the correct event handler in the user control.
Where do you try to set it? In Which event?
Hey Alex
Sorry for the multiple edits. How about Page load? I can set it there to get the info from my resx file (unless it can be automatically which is great)?
just tried this and this didnt work either :-(
The template lang is set to en and inherit on the nodes but on page load i look at the variables and theyre set to German (or whatever i set it to) if i enter the below code i can see the name set by the above code
not sure what the heck is going on? I then viewed page source and can see href lang="en". Changed to "de" which didnt make a difference unless im missing something?
Hoping someone could point me in the right direction?
Thanks again
Hey J
You can pass CultureInfo to the method: GetGlobalResourceObject(String, String, CultureInfo)
Hey Alex
I get the error
I then thought about changing the Resource name as my France resource file is called Resource.fr-FR
(Note the new Resource class name - but this threw an error :-(
Thanks
What about this way?
try to use GetLocalResourceObject method like this:
HttpContext.GetLocalResourceObject("Resource", "Info", New CultureInfo("de"))
THANK YOU Alex - This is now working. Thanks again very much. Hopefully i dont come across any more issues but really thankful for getting me on track.
Just a side question :-). If i want to swap between languages could i store the value in session so if a user goes from German to English to Russian over multiple pages it would display the appropriate language selected?
Thanks again
Amazing, happy to help.
You can store in the session selected language, but as I understood page language is English but you need to show German - isn't it an issue we solved?
Yes it is an issue that's resolved but just in case I need to add more languages in future.
I didn't want to complicate things but I save the data in the database for Germany and United Kingdom. I have one template/page and can load the data. The problem I was having certain static words on the template were not displaying in German.
The above resolved that but I thought to make it a little more reusable where if I need to add another country in future I could save the language in session and load the same template with another country's language.
Thanks
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.