多语言Web应用程序 - 我该如何检测用户在ASP.NET语言? [英] Multi-lingual web application - how do I detect the user's language in ASP.NET?

查看:153
本文介绍了多语言Web应用程序 - 我该如何检测用户在ASP.NET语言?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要建一个ASP.NET Web应用程序,以及所有我的琴弦都存储在一个资源文件。我想第二语言添加到我的应用程序,理想情况下,我想自动检测用户的浏览器语言(或Windows语言),并默认为,与其让他们选择英语以外的东西。目前,我手动处理所有的资源群体,因此添加第二个资源文件和语言是从我的角度来看微不足道的,如果我有一个简单的方法来自动计算出要显示的语言。

I'm building an ASP.NET web application, and all of my strings are stored in a resource file. I'd like to add a second language to my application, and ideally, I'd like to auto-detect the user's browser language (or windows language) and default to that, instead of making them choose something besides English. Currently, I'm handling all the resource population manually, so adding a second resource file and language is trivial from my point of view, if I had an easy way to automatically figure out what language to display.

有没有人这样做,或者你有,我怎么可能会检索该值的任何想法?由于ASP.NET是基于服务器的,我似乎不具有特定的浏览器设置任何访问。

Has anybody done this, or do you have any thoughts about how I might retrieve that value? Since ASP.NET is server-based, I don't seem to have any access to specific browser settings.

解决方案:这是我落得这样做。我用了一个为每一个要经过HttpContext.Current.Request.UserLanguages​​并搜索一个我支持。实际上,我只是检查左侧的两个字符,因为我们不支持任何方言尚未 - 只是英语和西班牙语。感谢所有帮助!

RESOLUTION: Here's what I ended up doing. I used a "For Each" to go through "HttpContext.Current.Request.UserLanguages" and search for one I support. I'm actually just checking the left two characters, since we don't support any dialects yet - just English and Spanish. Thanks for all the help!

推荐答案

这<一个href=\"http://web.archive.org/web/20080930115525/http://microsoft.a$p$pss.com/asptodayarchive/71804/website-internationalization-using-asp\"相对=nofollow>文章(链接到archive.org作为原始链接现在死了)可能与自动检测浏览器的语言设置有帮助的。

This article (linked to archive.org as original link is now dead) might be helpful with auto detecting the browser's language setting.

是的。援引的条款不使用ASP.NET。这文章一样。

Yes. The quoted article does not use ASP.NET. This article does.

这篇关于多语言Web应用程序 - 我该如何检测用户在ASP.NET语言?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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