Last post Feb 25, 2012 08:11 AM by tugberk_ugurlu_
Feb 24, 2012 11:33 PM|kvh|LINK
what is a best way to create a multi language MVC3 application. For example in model Required field ErrorMessage texts in several languages?
and how in razor view cshtml pages to display labels, headings in several languages? I have googled and found some samples, but they required creating new cshtml page for each language. is there a way to just create one page and through resource files somehow
display label in different language?
Feb 25, 2012 12:14 AM|jerryjoseph|LINK
For example in model Required field ErrorMessage texts in several languages?
Add and use a resource file say ErrorMessage.resx in App_GlobalResources.
how in razor view cshtml pages to display labels, headings in several languages?
Add local resource files and access the resource like @Html.Resource("ResourceName").
I have googled and found some samples, but they required creating new cshtml page for each language.
It is unnecessary to create separate cshtml files for each language. It is an option if you want to do it that way.
Feb 25, 2012 05:23 AM|worldspawn|LINK
If you are not using the MVC Html editor extension methods (and thus have full control) you could use a library like i18n. It's key advantage is you don't need to create keys for all your strings, you just write your strings in english (or your preferred
language) and then provide translations for it in the "po" language files it creates.
So in your cshtml and cs files you would have for example:
Note the "_" function it's calling. That will pull the value from the translation files. Also when you build your application an additional process is run that scans your files for anything matching the _("some string") pattern and adds it to your translation
Then in ~/locale/fr/messages.po (for French translations) you would have and entry like:
You then edit it to:
When the view is run the user will see the translated value if the site is running in French.
https://github.com/danielcrenna/i18n - its also a nuget package.
Feb 25, 2012 08:11 AM|tugberk_ugurlu_|LINK
have a look: http://stackoverflow.com/questions/5513993/asp-net-mvc3-multilingual-route-rewriting/5531191#5531191