Using resources for localization in MVC4

I follow this tutorial, which was given as an answer to this question, however I am stuck when displaying a resource.

As in the tutorial, I created two files

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

I made a data annotation class that works and adds a cookie without errors, which means that it correctly injects local data into the current stream. When I try to infer a resource, it cannot find it.

I 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 

In addition, on this training site I do not see any logic that would enter the correct resource file, how it can do something like (in the tutorial) @Global.HomeHello , and he will know that if url /en/ he needs use Global.en.resx

Please help, using resources for the first time and introducing several languages, it feels 100 times more complicated and confusing than using *.yml files in other frameworks / languages ​​...

+4
source share
1 answer

You took a bad example to follow, I think. Please read the following article:

ASP.NET MVC Resource Files and Projects

Remember to change the Custom Tool to PublicResXFileCodeGenerator and the Custom Tool Namespace to Resources .

Hope this helps and good luck.

+12
source

Source: https://habr.com/ru/post/1436807/


All Articles