asp.net-mvc 在 MVC4 中使用资源进行本地化

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12640196/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 02:17:40  来源:igfitidea点击:

Using resources for localization in MVC4

asp.net-mvcasp.net-mvc-3localizationasp.net-mvc-4globalization

提问by Stan

I'm following thistutorial that was given as answer in thisquestion, however I'm stuck at displaying the resource.

我正在关注在这个问题中作为答案给出的教程,但是我一直坚持显示资源。

Just like in tutorial I've created two files

就像在教程中我创建了两个文件

App_GlobalResources
   /Global.en.resx
   /Global.ru.resx

I've made data annotation class that works and adds a cookie with no errors, it means it injects the local data into current thread properly. When I try to output resource it cannot find it.

我已经制作了数据注释类,该类可以正常工作并添加一个没有错误的 cookie,这意味着它将本地数据正确地注入到当前线程中。当我尝试输出资源时,它找不到它。

I've tried to output it like this and none of these works:

我试图像这样输出它,但这些都不起作用:

@Global.HomeHello
@Global.en.HomeHello
@Resources.Global.Homhello
// The name 'Resources/Global/etc...' does not exist in the current context

Also, in this tutorial site I see no logic that will inject the proper resource file, how it can do something like (in tutorial) @Global.HomeHelloand it will know that if url is /en/he needs to use Global.en.resx

此外,在本教程站点中,我看不到任何逻辑可以注入正确的资源文件,它如何执行(在教程中)之类的操作,@Global.HomeHello并且它会知道如果 url 是/en/他需要使用的Global.en.resx

Please help, first time using resources and implementing multiple languages, feels 100 times more harder and confusing than using *.ymlfiles in other frameworks/languages...

请帮忙,第一次使用资源和实现多种语言,感觉比使用*.yml其他框架/语言中的文件要困难和混乱 100 倍......

回答by Display Name

You took a bad example to follow I guess. Please look into the following article:

我猜你举了一个坏榜样。请查看以下文章:

Resource Files and ASP.NET MVC Projects

资源文件和 ASP.NET MVC 项目

Don't forget to change Custom Toolto PublicResXFileCodeGeneratorand Custom Tool Namespaceto Resources.

不要忘了改Custom ToolPublicResXFileCodeGeneratorCustom Tool NamespaceResources

Hope this helps & good luck.

希望这有帮助,祝你好运。