更改 ResourceManager(使其可更新)
我有一个 MVC 3 (Razor) 项目,为了本地化,我们使用强类型资源。 我们希望能够更新“在线”已有的翻译。这意味着应该可以在网站上编辑翻译。 (例如,如果网址中存在“translateLanguage=on”等参数)基本上,使用当前解决方案不可能做到这一点,因为如果资源已更改,则必须重新编译。
当然,我们可以编写自己的资源管理器来使用数据库,但是这样我们就必须将所有翻译重写到数据库中,这将非常耗时。这也意味着我们必须更改所有代码以反映这个“新”资源管理器。
很难在所有事情上实施它。现在,我们可以在属性中使用它 例如
[Required(ErrorMessageResourceType = typeof(_SomeResource), ErrorMessageResourceName = "SomeResouceElement")
SomeProperty
以及代码:
string translatedResource = _SomeResource.SomeResourceElement;
您能给我提供一些如何在 mvc 3 中执行此操作的信息吗?
I have a project in MVC 3 (Razor) For localization we are using Strongly typed resources.
We want to have possibility to update translation that already exist "on-line". It means, that it should be possible to edit translation on the website. (e.g. If in the url there is parameter like "translateLanguage=on") Basically, it is not possible to do that with current solution, because if resource has been changed, then it must be recompiled.
Of course we can write our own Resource Manager that will be using a database, but then we would have to rewrite all of our translations to the database and that would be time consuming. It would also mean that we would have to change all of our code to reflect this "new" resource manager.
It would be hard to implement it in all things. Now, we can use it in attributes
e.g.
[Required(ErrorMessageResourceType = typeof(_SomeResource), ErrorMessageResourceName = "SomeResouceElement")
SomeProperty
As well as in code:
string translatedResource = _SomeResource.SomeResourceElement;
Could you provide me with some information how to do this in mvc 3?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一般来说,资源文件由两部分组成:xml + 自动生成的cs代码。如果您打开资源设计器文件,您将看到
所以您可以做什么,您可以使用 ResourceManager.GetString("Key")
为了使其更智能,您可以重写 BaseView
然后您将能够在您的剃刀视图中使用 GetTranslation (要运行这个基本视图需要从 Views 文件夹修改 web.config)
,然后编辑 xml 后就可以访问资源数据。
Generally resource file consists of two parts xml + autogenerated cs code. If you open resource designer file you will see
So what you can do you can use ResourceManager.GetString("Key")
To make it more smart you can rewrite BaseView
And then you will be able to use GetTranslation in your razor view (To run this base view you need to modify web.config from Views folder)
And then you will be able after editing xml access to resource data.