检测浏览器的显示语言 [英] Detecting browser display language

查看:367
本文介绍了检测浏览器的显示语言的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通过下面的code

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

如果我已经安装了3种语言(如DA(丹麦),SV(瑞典)和en(英语)),那么语言数组是这样的:

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"

即使我更改显示语言为丹麦而不是英语,那么数组不会更改任何值。至于我可以从其他什么人都写关于这个主题,在 [0] 值应该是浏览器的选择的语言,但它仍然是<$ C阅读$ C>EN-US。

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?

推荐答案

设置的UICulture 文化的页面指​​令为我工作:

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.

然后我用:

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

这正确地给了我 FR

您可以设置页面级别的文化还是全球范围内,看到这里

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

这篇关于检测浏览器的显示语言的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆