Culture and UICulture in ASP.NET

When I was working on multilanguage/culture web application, I knew about UICulture setting but didn’t know about culture until there is a need for it.  So I thought it’s good topic to share.

This blog post is all about

  • difference between UICulture and Culture (UICulture vs Culture)
  • when you need to set UICulture and Culture
  • how to set UICulture and Culture declaratively and programmatically.

UICulture value determines what resource file ASP.NET needs to load. That drives all the content of the website.

Culture value determines the results of culture-dependent functions, such as the date, number, and currency formatting, and so on.

It is NOT necessary that you need to have both values are same.  You can set different values as per your application needs. Good example is that Web Auction web site.  You won’t to display english text for english speaking country but you might want to display spanish text for spanish speaking country. This setting is UICulture.   But there is one thing that would stay constant “currency” for both english or spanish speaking country. This setting is Culture.

You can set UICulture and Culture properties to ASP.NET web page.
For example..

<%@ Page UICulture="es" Culture="es-MX" %>

You can also set UICulture and Culture for all pages by adding globalization section in web.config.
For example.

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

And if your site has a feature to allow user to choose their preferred language(on website landing page you ask user to pick their preffered language),  you need to overrider InitializeCulture method of page class and set appropriate value.
For Example.

Thread.CurrentThread.CurrentCulture =
CultureInfo.CreateSpecificCulture(selectedLanguage);

Note: In above example I set “es” to uiCulture.  You can’t set just language like “es” to culture because that is NOT a valid culture.  It has to be specific culture. FYI “es” is a neutral culture and “es-MX” is a specific culture.

One more important things I need to discuss is about resource fallback process.  In my case I had specified “en-US” for UICulture settings and the resource file that I had ResourceFile.resx.  .NET first looks for ResourceFile.en-US.resx resource file because I set en-US UICulture in web.config.  If it doesn’t find ResourceFile.en-US.resx, then it looks for ResourceFile.en.resx(netural culture file).  Eventhough it doesn’t find ResourceFile.en.resx, then it looks for ResourceFile.resx.  So you can see in this case it is searching unnecessary bcoz I didn’t think of that. In my case I had all the english text in .resx file and I set “en-US” uiculture in web.config.  So I have to rename all my .resx resource file to .en-US.resx file to reduce extra search steps.

Finally here is the link where you will find list of all valid UICulture and Culture.

Posted in Microsoft Technology Tagged with:
One comment on “Culture and UICulture in ASP.NET
  1. Ajith kumar says:

    Thanks for this helpful informations

Ads

OutbackDirect.co.uk is a trading site of World of Power.co.uk Limited. Outback Direct is the official Outback Consumer Warranty, Parts and Accessory Partners for the UK. We currently hold in stock 1000’s of parts and accessories for current and older Outback barbecues. We endeavour to ensure rapid and secure product delivery the length and breadth of mainland United Kingdom, this factor coupled with our excellent customer service has led to the market position we currently enjoy.
outback barbecue
omega 300 gas barbecue
Omega 250 Gas Hooded BBQ
Blog
Blog
------------------------------------------------------------ Silver Sky Imports is a unique online marketplace that offers unique handicrafts from Tibet and Nepal. Launched in 2003, Silver Sky Imports is currently the largest supplier of handmade items from the Himalayas. We specialize in the largest variety of Tibetan Singing Bowls and Crystal Singing Bowls online and include individual sound samples, pictures and descriptions for each bowl. Some of our other products include Tibetan Prayer Flags, Tingshas, Bell and Dorje, Incense, Felted Wool Handbags, Wood Masks, Prayer Wheels, Gongs, Bronze Statues, and Tibetan Meditation Rugs. monks
Blog
------------------------------------------------------------ Airpush, a mobile ad network that is only two years old, has quickly grown to one with over 5,000 advertisers. One thing they've heard from that sea of advertisers over the past 12 months, and especially over the past six, is that real-time bidding (RTB) capabilities are now a must. To answer those needs, the company today unveiled AirDSP, a platform meant to easily connect advertisers to RTB exchanges. Read more: Mobile RTB
Blog
Blog
------------------------------------------------------------ Danish site about electronic cigarettes E Cigarette, Electronic Cigarette and E Cigarettes e cigaret
------------------------------------------------------------ DrugRisks.com drugrisk​ recall ​informat​ion​ drugrisk​ yaz​
------------------------------------------------------------