Localization in ASP.NET MVC

Visual studio 2008

I want to add some localization to my ASP.NET MVC site.

Someone suggested creating the resource file "Strings.resx" as a publicly strongly typed resource that works great and allows me to write

<title><%= Strings.MyView_Title %></title> 

Then I proceeded to add the file "Strings.da.resx". This file is created directly next to the first, and the default is "Access modifier: no compilation", while the first (the one who does not have a language modifier) ​​defaults to "Interal".

I can see in the bin directory that the directory was created ("da") with resource.dll, however I do not see any translated text on my site.

I checked in the browser that the only preferred langauge is Danish (da-DK), but I only see English texts.

Questions: 1) Do I need to activate something in web.config? 2) I am creating the correct files with the correct types (i.e. Should # 2 have "No compilation")?

+4
source share
2 answers

Do you have a page pointer in your views? If so, do you have UICulture = "Auto" and "Culture" = "Auto"?

For instance...

 <%@ Page Language="C#" Inherits="..." culture="auto" uiculture="auto" %> 

This ensures that the Accept-Language header passed by the browser in the request is used to set Thread cultures. This is a UICulture that affects the resource file to select.

More about ASP.NET i18n this book is very good ...

http://www.amazon.co.uk/NET-Internationalization-Developers-Guide-Building/dp/0321341384/ref=sr_1_1?ie=UTF8&s=books&qid=1241010151&sr=8-1

It does not cover MVC, but it covers ASP.NET and, as such, many things continue to be relevant.

+6
source

First you need to create an action filter that will switch the culture of the request flow. OR Set the globalization element to UICulture = "Auto" and Culture = "Auto"

Check the screencast , it is in Russian, but the code examples are clear.

+2
source

All Articles