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

查看:24
本文介绍了多语言 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.

解决方案:这就是我最终要做的事情.我使用For Each"来浏览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!

推荐答案

这个 文章(链接到 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天全站免登陆