Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

By using the following code

string[] languages = HttpContext.Current.Request.UserLanguages;
string chosenLanguage = languages[0];

if I have installed 3 languages (ex. "da (danish)", "sv (swedish)" and "en (english)"), then the languages array looks like this:

[0]: "en-US"
[1]: "en;q=0.8"
[2]: "da;q=0.6"
[3]: "sv;q=0.4"

Even if I change the display language to "Danish" instead of "English" then the array doesn't change any of the values. As far as I can read from what other people have written about this subject, the [0] value should be the chosen language of the browser, but it is still "en-US".

Is there some other way to register the language of the browser or am I doing something wrong?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
136 views
Welcome To Ask or Share your Answers For Others

1 Answer

Setting the UICulture and Culture on the page directive worked for me:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebApplication1.Default" UICulture="auto" Culture="auto" %>

I then set my chrome language to French and made sure to re-order the languages - chrome will take the topmost language as default for the browser.

I then used:

Response.Write(System.Threading.Thread.CurrentThread.CurrentUICulture);

Which correctly gave me fr

You can set the culture on the page level or globally, see here.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...