如何做本地化的MVC3的@Model财产之一 [英] how to do Localization for one of the @Model property in mvc3

查看:141
本文介绍了如何做本地化的MVC3的@Model财产之一的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经开始在一个MVC项目工作,我就翻过的一些情形,我觉得我卡住了。我需要在已有的MVC3网站为多语言转换工作。由于我是新的,我可以同时explaing所以请裸跟我用错了字/ definations /关键字MVC3。

I have started working on an MVC project and I came accross some scenarios where I feel I am stuck. I need to convert the exisiting MVC3 site to work for multiple language. As I am new, I may use wrong words/definations/keywords for MVC3 while explaing so please bare with me.

我有一个HeaderPage.cshtml它具有绑定到它的视图模型通过

I have one HeaderPage.cshtml and it has a view model binded to it by

@model IHeaderPage

和它这个OUPUTS模型的属性:

And it ouputs a property of this model:

<h3>@Model.HeaderName</h3>

我打电话从MainPage.cshtml这个观点

I called this view from MainPage.cshtml

@Html.Partial("HeaderPage")

现在在控制器的操作方法,我更改模型的属性。

Now in the Controller's Action method I change the model's property

objHeaderPage.HeaderName="Fill your Registeration details";

当我运行该项目,我看到了文字你填写的详细信息Registeration。

And when i run the project i see the the text "Fill your Registeration details".

现在我怎么能更改文本值,即应该从我的RESX文件中读取。
我已经在 App_LocalResources文件文件夹中创建的resx文件。
我听说,它可以通过显示属性来完成..但我怎么做,或是否有任何其他更好的办法?

Now how can I change the text value, i.e. it should read from my resx file. I have already created resx files in App_LocalResources folder. I heard that, it can be done by Display Attribute.. but how do i do that or is there any other better way?

推荐答案

应该回答您关于使用问题DisplayAttribute。

This should answer your question regarding the use of DisplayAttribute.

我用 DisplayAttribute 我的ViewModel的每个属性,但是如果你要处理像自定义消息的记录不能因为错误而被保存。 ,或类似的东西,你可以简单地用

I use DisplayAttribute for every property of my ViewModel, but if you have to handle custom messages like "The record can not be saved because of an error...", or something similar, you can simply use

 objHeaderPage.HeaderName = Resources.ResourceMessageName; 

该框架将自动选择正确的文化。
我preFER把我所有的资源在一个单独的项目,这样我就可以在需要的情况下只部署资源的DLL,但你也可以认为部署RESX文件直接编辑它们生产的机器上。我想这是给你preFER /需要。

The framework will choose automatically the correct culture. I prefer to put all my resources in a separate projects so I can deploy only the dll of the resources in case of need, but you can also think to deploy the resx files to edit them directly on the production machine. I guess it's up to what you prefer/need.

这篇关于如何做本地化的MVC3的@Model财产之一的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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