Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Whats the difference of NeutralResourcesLanguageAttribute and uiCulture in a asp.net mvc project

I have created an asp.net MVC4 web project which must be available in more than one language.

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

NeutralResourcesLanguageAttribute in AssemblyInfo

[assembly: NeutralResourcesLanguageAttribute("en")]

From msdn: Informs the resource manager of an app's default culture. This class cannot be inherited.

globalization uiCultur in web.config

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

From mdsn: Specifies the default culture for processing locale-dependent resource searches. For valid culture strings, see System.Globalization.CultureInfo Class.

Now my questions:

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

like image 525
Manuel Avatar asked Apr 15 '13 07:04

Manuel


People also ask

What is UICulture property in asp net?

In an ASP.NET Web page, you can set to two culture values, the Culture and UICulture properties. The Culture value determines the results of culture-dependent functions, such as the date, number, and currency formatting, and so on. The UICulture value determines which resources are loaded for the page.


1 Answers

Example resource files

  • Stuff.resx (contains english, is the default resources 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 let the browser settings decide (german browsers gets the german resources, etc)

However (in the above example) if a Swedish browser comes it will default to en as there is no se (swedish) resource file and the fallback english ("auto: en ") uiCulture will be used.

So... then:

[assembly: NeutralResourcesLanguageAttribute("en")]

lets the application now that english requests go direct to the default.resx with no other lookup for en resx first.

Also if an english browser is requesting it should go directly to the default resource file without trying something else first. So the NeutralResourcesLanguageAttribute setting comes in play also here. The app knows to go to the default resx directly.

like image 128
Max Avatar answered Sep 20 '22 00:09

Max