What is the difference between NeutralResourcesLanguageAttribute and uiCulture in asp.net mvc project

I created an asp.net MVC4 web project that should be available in several languages.

I want to set the default language for this web project. After some research, it seems that the default language can be installed in two places.

NeutralResourcesLanguageAttribute in AssemblyInfo

[assembly: NeutralResourcesLanguageAttribute("en")] 

From msdn: Informs the resource manager of the default culture for the application. This class cannot be inherited.

uiCultur globalization in web.config

  <system.web> <globalization uiCulture="en"/> 

From mdsn: Specifies the default culture for handling locale-dependent requests. For valid culture strings, see the System.Globalization.CultureInfo Section.

Now my questions are:

What is the correct way to set the default language in a web project (NeutralResourcesLanguageAttribute or globalization uiCultur)?

+6
source share
4 answers

Resource File Examples

  • Stuff.resx (contains English, is the default resource file)
  • Stuff.de.resx (contains German)
  • Stuff.fr.resx (contains French)

Now in web.config use

 <globalization enableClientBasedCulture="true" uiCulture="auto:en" culture="auto:en" /> 

This ("auto") will allow the browser settings to be solved (German browsers get German resources, etc.)

However (in the example above), if a Swedish browser is used, the default will be ru , since there is no se (Swedish) resource file and backup English ("auto: ru "). uiCulture will be used.

So ... then:

 [assembly: NeutralResourcesLanguageAttribute("en")] 

Allows the app to now query English queries directly to default.resx without another ru resx search.

In addition, if the English browser asks for it, it should go directly to the default resource file without trying to do something first. Thus, the NeutralResourcesLanguageAttribute parameter is also present here. The app knows to go directly to resx by default.

+1
source

According to this article, important settings for the Asp.Net web application are in the web.config in the "globalization" element. The article proposes to establish both culture and culture as best practice. For instance:

 <globalization uiCulture="es" culture="es-MX" /> 
0
source

NeutralResourcesLanguageAttribute - ONE way to let the application resource manager know the default culture and location of your application resources. This attribute can be used for any type of .NET application: desktop, web, win8, wcf, etc.

The globalization attribute is another way to tell your web application what the default culture for your application is.

Note that the key difference is that the globalization attribute only works for web applications and does not allow you to specify a different location for resources.

Recommendation: for a web project, I would use the config attribute.

0
source

The NeutralResourcesLanguage attribute informs the ResourceManager of the language that was used to display neutral culture resources for the assembly. When it searches for resources in the same culture as the language of neutral resources, the ResourceManager automatically uses the resources that are in the main assembly.

He does this instead of looking for a satellite assembly that has a current UI culture for the current stream. NeutralResourcesLanguage improves search performance for the first loadable resource and can reduce your working set.

from http://technet.microsoft.com/en-us/subscriptions/bb385967.aspx

0
source

All Articles