Hi Colin,
What do you mean by storing some data in the database? Do you mean some custom tables or Umbraco content? Can you describe in more details the question?
By that I mean for Germany I have a custom table which stores a record for them in German. I'm also storing the language/country against that record.
On the other hand I am storing data for USA in English (again storing the language/country) against that record.
So if I'm a user from Germany I would like to display the record in German. How could I ensure the data displayed for the German user is in German and USA user is in English?
I have setup the global resources folder with minor translations. So it's a matter of working out how to display the appropriate record for the user of that country.
Hi Colin,
Yes, you can get the culture in your controllers with the following line:
var culture = CultureInfo.CurrentCulture;
Keep in mind that if you use Ajax requests this code will not work. In case you use Ajax you need to get the current Culture from the Umbraco view (using the same code above) and pass it as parameter in your ajax GET/POST request. Ajax requests doesn't know anything about Umbraco context and culture.
There is another option: Create a default cotrnoller where you can get the current culture and set a cookie. After that you can work only with your cookie. Here you can find information how to create default controller. If you need I can share some code about this approach.
Just to ensure there's no twist or turns, I am using a web control. This control has a public property for the culture where I was planning on adding the country/language.
Using your method I won't need to do that I assume? If that's the case could I use one web control/macro for multiple sites by just adding the culture code you provided above which will then get data by country and for any new countries I add in future?
As long as you are in Umbraco context you can always get the current culture. It is not needed to pass it as additional parameter. I am not very sure how your macro works so if you want you can post some details here.
Hi Colin,
Did you set correct the culture and hostnames of your home node. And can you give more details where exactly you try to get culture - in your controller, view... A bit more information about the setup you have.
So I have a web forms control with only the above culture code on page load (so there is no inheritance or anything as such.
I have set the culture under hostnames for each country.
I'm not setting any cookies. To test, I add the language to the browser settings and make that the default/highest priority.
I changed the HTML template and added the language to it which showed the correct data. I'm testing this as I write to see if this works under all browsers/scenarios.
Finally if a user is in Germany I would like to give them the option to change to UK. I thought to add this in in case it changes anything.
How to retrieve data for country
Hi
I have two international sites and have set the culture, hostname.
I am storing some data in a database. I know how to retrieve data but how could I ensure I get the data for the correct country?
Thanks
Anyone got any thoughts or ideas?
Thanks
Hi Colin, What do you mean by storing some data in the database? Do you mean some custom tables or Umbraco content? Can you describe in more details the question?
Hi Mila
By that I mean for Germany I have a custom table which stores a record for them in German. I'm also storing the language/country against that record.
On the other hand I am storing data for USA in English (again storing the language/country) against that record.
So if I'm a user from Germany I would like to display the record in German. How could I ensure the data displayed for the German user is in German and USA user is in English?
I have setup the global resources folder with minor translations. So it's a matter of working out how to display the appropriate record for the user of that country.
Let me know if you require more info. Thanks
Hi Colin, You can get current language (user's language) and pass this as parameter to your query and get the data from the custom table.
Does it makes sence?
Mila
It does but how do I do that? I've read on cultureInfo class but not sure if this is the correct way? Thanks
Hi Colin, Yes, you can get the culture in your controllers with the following line:
Keep in mind that if you use Ajax requests this code will not work. In case you use Ajax you need to get the current Culture from the Umbraco view (using the same code above) and pass it as parameter in your ajax GET/POST request. Ajax requests doesn't know anything about Umbraco context and culture.
There is another option: Create a default cotrnoller where you can get the current culture and set a cookie. After that you can work only with your cookie. Here you can find information how to create default controller. If you need I can share some code about this approach.
Hope that this will help Mila
Hi Mila, thanks for that I will check it out.
Just to ensure there's no twist or turns, I am using a web control. This control has a public property for the culture where I was planning on adding the country/language.
Using your method I won't need to do that I assume? If that's the case could I use one web control/macro for multiple sites by just adding the culture code you provided above which will then get data by country and for any new countries I add in future?
Thanks again
Hi Colin,
As long as you are in Umbraco context you can always get the current culture. It is not needed to pass it as additional parameter. I am not very sure how your macro works so if you want you can post some details here.
Mila
Hi Mika
I appreciate your thoughts and help. Currently im storing records as below (I've cut this down dramatically)
country - languageCode - name USA - en-US - Hello Canada - ca-En - Hi Canada -ca-Fr - Bonjour UK - en-GB - Hiya Germany - de-AT - Guten tag
I will give what you have recommended a go and see how i go. Once i know i dont have any issues i will mark your reply as an answer.
Thanks
Hi
I did a quick test on the above but that code always returns the culture that's on the server/pc and not the browser? Anything I need to do?
Thanks
Hi Colin, Did you set correct the culture and hostnames of your home node. And can you give more details where exactly you try to get culture - in your controller, view... A bit more information about the setup you have.
Hi Mila
So I have a web forms control with only the above culture code on page load (so there is no inheritance or anything as such.
I have set the culture under hostnames for each country.
I'm not setting any cookies. To test, I add the language to the browser settings and make that the default/highest priority.
I changed the HTML template and added the language to it which showed the correct data. I'm testing this as I write to see if this works under all browsers/scenarios.
Finally if a user is in Germany I would like to give them the option to change to UK. I thought to add this in in case it changes anything.
Many thanks for your help.
is working on a reply...