使用 ASP.Net MVC3 国际化(用户选择首选语言一次查看)

Internationalization with ASP.Net MVC3(User Select Preferred language once for all View)(使用 ASP.Net MVC3 国际化(用户选择首选语言一次查看))
本文介绍了使用 ASP.Net MVC3 国际化(用户选择首选语言一次查看)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望用户为整个应用选择一次首选语言.建议我最简单的步骤.
这样用户在登录后只选择一次首选语言,然后所有应用程序的视图都以所选文化呈现.
我发现了一些相关的这里

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 国际化(用户选择首选语言一次查看)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

c# Generic Setlt;Tgt; implementation to access objects by type(按类型访问对象的C#泛型集实现)
InvalidOperationException When using Context Injection in ASP.Net Core(在ASP.NET核心中使用上下文注入时发生InvalidOperationException)
how do i pass parameters to aspnet reportviewer(如何将参数传递给aspnet report查看器)
Bind multiple parameters from route and body to a model in ASP.NET Core(在ASP.NET Core中将路由和主体中的多个参数绑定到一个模型)
Custom model binding in AspNet Core WebApi?(AspNet Core WebApi中的自定义模型绑定?)
How to minify in .net core mvc view?(如何在.Net核心MVC视图中缩小?)