ASP.NET - MVC 3:本地化 [英] ASP.NET - MVC 3: Localization

查看:236
本文介绍了ASP.NET - MVC 3:本地化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我即将实现国产化,为我的MVC3 Web应用程序。通过大量的方法来做到这一点谷歌搜索我的路,我被留下不确定要实现这个哪种方式。我发现几个方法如何做到这一点:

I am about to implement localization for my MVC3 web application. Googling my way through large amounts of ways to do it, I was left unsure which way to implement this. I found few ways how to do it:

我发现第一种选择是使用App_GlobalResources文件和ViewData的文化与地图路由选择。 (<一href=\"http://geekswithblogs.net/shaunxu/archive/2010/05/06/localization-in-asp.net-mvc-ndash-3-days-investigation-1-day.aspx\">Link)

First option I found was to use App_GlobalResources and ViewData and culture select with Map Routing. (Link)

二是做一个单独的资源文件夹在我的项目,它的结构像模型和视图文件夹。然后创建这些文件夹中的资源文件。要使用这些资源串会像使用Viewbag。然后编辑在Global.asax处理文化变化,并创建一个局部视图,允许改变文化。该指令要做到这一点是非常彻底所以这可能是最好的选择。
链接

Second was to make a separate Resources folder in my project and structure it like Model and View folders. Then create the resource files in those folders. To use those resource strings would be like using the Viewbag. Then edit the Global.asax to handle culture changing and create a partial view to allow changing cultures. The instructions to do this are very thorough so this might be the best bet. (Link)

三是使用DisplayAttribute和RESX-文件。这一个是有点朦胧,我找不到什么信息,这样我可以掌握如何真正实现其限制。 (链接

Third was to use DisplayAttribute and resx-files. This one was a bit hazy, I could not find the sort of information so that I could grasp how this actually is implemented and its restrictions. (Link)

四是要建立一个自定义的类来处理资源。这似乎pretty幻想和易于实施和使用,但没有发现真实的信息,如果它实际工作。 (链接

Fourth was to create a custom class to handle resources. This seemed pretty fancy and easy to implement and use but no real information was found if it actually worked. (Link)

后来我发现,警告使用App_GlobalResouces和App_LocalResources文件后。 (<一href=\"http://odeto$c$c.com/Blogs/scott/archive/2009/07/16/resource-files-and-asp-net-mvc-projects.aspx\">Link)

Then I found a post that warned about using the App_GlobalResouces and App_LocalResources. (Link)

通过做本地化的可能的方式去后。我找不到它被普遍认可或接受的一种方式。这让我琢磨,这其中还是有些我没找到,就在ASP.NET中实现本地化MVC3最好的方式?

After going through possible ways of doing localization. I could not find a way which was universally approved or accepted. This left me pondering, which of these, or some I didn't find, would be the best way to implement localization in ASP.NET MVC3?

推荐答案

我想出了一个简单的方法来处理本地化,你不必使用资源文件或属性。它包括自定义元数据提供商。

I've come up with an easier way to handle localization where you don't have to use resource files or attributes. It involves custom metadata providers.

MVC3使用元数据提供商获取所有文本字符串。我的方法可以让你既可以使用字符串表,数据库,平面文件或任何其他来源提供的翻译。所有你需要做的就是要继承两个接口。

MVC3 uses metadata providers to get all text strings. My approach allows you to either use string tables, a database, flat files or any other source to provide the translations. All you need to do is to inherit two interfaces.

阅读在这里:的http://blog.gauffin.org/2011/09/easy-model-and-validation-localization-in-asp-net-mvc3/

修改

一切都记录在案,现在在GitHub上,有包的NuGet: https://github.com/jgauffin/ griffin.mvccontrib

Everything is now documented at github and there are nuget packages: https://github.com/jgauffin/griffin.mvccontrib

这篇关于ASP.NET - MVC 3:本地化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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