0

I am saving data in a database for multiple countries. Nvarchar is the type for the column for the table.

Sample of the data is

**Culture -- DisplayText**
En-Us   -- Howdy
En-Gb   -- Hello
De-De   -- Guten Tag
Fr-Fr   -- Bonjour

On my aspx page I have

var culture = CultureInfo.CurrentCulture;

I then use the culture variable to get the data

getDatabyCulture(culture.Name);

I then change my browser language setting to French but it always defaults to my local culture and not the culture I'm testing against? Whether that be France or Germany, it still returns data back in my local culture.

What am I doing wrong?

Computer
  • 2,149
  • 7
  • 34
  • 71
  • 1
    I expect the culture of the server-side code is the culture of the server, not the browser, right? – Wyck Mar 06 '20 at 20:37
  • @Wyck is correct. That is c# code and will run server-side. It will always use the web server culture. – djv Mar 06 '20 at 20:38
  • Good question/thoughts.... I'm on my local browser at present.... So how do I go about getting the culture from the browser? – Computer Mar 06 '20 at 20:40
  • start with `navigator.language`. Then read https://stackoverflow.com/questions/1043339/javascript-for-detecting-browser-language-preference – Wyck Mar 06 '20 at 20:48
  • Have a look at resource file (resx). I would advice using it to print localized text from your system if this is what you're trying to do. – André Sanson Mar 06 '20 at 20:56
  • @André Sanson I have resx files but the data for each country is stored in a database and would be retrieved by culture. Any examples I could follow to get the idea of how to do this? I looked at that link but it seems more JavaScript led and not C# backend code? – Computer Mar 06 '20 at 21:00
  • I think the [HttpRequest.UserLanguages Property](https://learn.microsoft.com/en-us/dotnet/api/system.web.httprequest.userlanguages?redirectedfrom=MSDN&view=netframework-4.8#System_Web_HttpRequest_UserLanguages) is probably what you are looking for, it returns _"a sorted string array of client language preferences"_, which you could then use to get the correct text from your DB for a request. – bassfader Mar 06 '20 at 21:26

0 Answers0