问题描述
我希望用户为整个应用选择一次首选语言.建议我最简单的步骤.
这样用户在登录后只选择一次首选语言,然后所有应用程序的视图都以所选文化呈现.
我发现了一些相关的这里
I want user to select preferred language once for the whole app. suggest me the easiest possible steps.
Such that user select preferred language only once just after login and then all app's view rendered with selected culture.
I found somehting related here
因为我是国际化的新手,所以我没有正确理解它.
我创建了一个示例应用程序,它可以在浏览器特定的文化中正常工作,但在这里我希望用户选择首选语言.
Because i am new in Internationalization i am not getting it properly.
I created a sample application which is working fine with browser specific Culture but here i want user to select preferred language.
推荐答案
通常,.NET 将使用与用户最匹配的 CultureSetting,然后确定用于全球化的适当资源文件.
Typically, .NET will use the CultureSetting that best matches the user and then determines the appropriate resource file to use for globalization.
一旦您保存"了用户适当的文化,就会出现在数据库、会话或 cookie 中.
Once you have "saved" the users appropriate culture be in a database, session, or cookie.
我所做的是将线程更改为适当的语言:
What I do is change the thread to the appropriate language:
var language = "fr"; // Pull from your "saved" location (database, session, cookie, etc.)
// This changes UI only
Thread.CurrentThread.CurrentUICulture = new CultureInfo(language);
// This changes how number, date formatting is handled
Thread.CurrentThread.CurrentCulture = new CultureInfo(language);
希望有帮助!
这篇关于使用 ASP.Net MVC3 国际化(用户选择首选语言一次查看)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!