ASP.NET - MVC 3: Localization

只谈情不闲聊 提交于 2019-11-28 16:41:16

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

I found that post extremely useful. The method explained there is very clean. Here is a snippet of my newly created index view using that method:

@using Resources.Index
@{
    ViewBag.Title = "Index";
}

<h1>@Index.Title</h1>

I don't think there is a definitive do-it-this-way-or-else method, so going for the cleanest method seems to me like a good deal.

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 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.

Read about it here: http://blog.gauffin.org/2011/09/easy-model-and-validation-localization-in-asp-net-mvc3/

Edit

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!