As one of the most powerful features came with the ASP.NET 2.0 is the out of the box globalization and localization features. Today websites and web applications is usually became a multilingual ones and ASP.NET provides us with a flexible, easy to use and time saving localization mechanism. I ran into a silly issue about localizing a project I am working with and after losing my mind and finished tearing up my hair I said “opps .. I missed something .. the fallback file”
Ok .. to localize your application you need to make use resources files which ends with the *.resx extension local resources or global resource there is no difference. Anyway in the most simple case if you have a Default.aspx form to localize it you must have a related .resx files. One file per culture using this naming convention Default.aspx.[culture].resx … So if you you application supports 3 languages say: English, Arabic, French you must have one resource file for each language. This means we need to have:
- Default.aspx.en-US.resx for the English page with USA specifications
- Default.aspx.ar-SA.resx for the Arabic page with Saudi Arabia specifications
- Default.aspx.fr-CA.resx for the French page with Canada specifications
You may use neutral cultures which related to language rather than a specific region culture e.g en, ar and fr … anyway after doing this you think you are fine but when you run the application you will discover that your pages does not read any values form those files and you still have those you filled when developing the form.
This occurs because in all circumstances you need to provide a default resource file which called “Fallback” resource file –will look like this Default.aspx.resx- which CLR will use when the users culture does not have its own resources file. e.g say that we have a visitor with the Chinese culture on his browser then the fallback resources will be used to get the required resources to serve his request.
What make me forget about the fallback resources file in my case is the truth that I am forcing users to choose between en-US and ar-SA –which is the default- culture. I thought: who need this file while the users will have a default culture and can only switch to another predefined one. Plus the resource mechanism works by searching for the users specific culture first –which in my case is forced by code to use ar-SA - in the cultures hierarchy and then move to the parent culture and so on!!
Hint
You need to make sure that you ever never forget about providing Default or Fallback resource file in your application. I will make another detailed post about how CLR handle resources. Hope that helps