11.5 Using Fallback Resource for Unsupported Regions

 <  Day Day Up  >  

You want cultures that are not supported by your application to use neutral culture resources.


Technique

The ResourceManager class uses a hierarchical searching algorithm based on the CurrentUICulture of the executing thread to find the correct resources for that culture. To ensure that unsupported specific cultures still receive the correct language strings for their culture, set the Language property to a neutral culture when localizing the application.

Comments

Localized resources are created in a hierarchical fashion. When the ResourceManager class begins a data lookup for the correct resources to use within an application, it first looks for the resources of the specific culture defined in the CurrentUICulture property of the executing thread. For instance, if we were using an English system whose country code was set to Canada, the ResourceManager would look for a corresponding en-CA resource assembly. Because the application being run doesn't use the word color ( colour in Canada), it doesn't have an en-CA resource assembly. The ResourceManager then moves up the hierarchy and checks for a neutral resource assembly. In this case, it checks whether an en resource is present. If that also fails, it uses the default values embedded within the main assembly.

You might be wondering why we keep referring to the resources as assemblies. Recipe 11.2, "Localizing Windows Forms Controls," showed that a .resx file is created whenever you change the Language property of a form within the forms designer. This .resx filename is a combination of the class name of the Windows Form followed by the culture identifier. If you select a neutral culture, the two-letter ISO identifier is used, and if you select a specific culture, an additional two-letter country/region code is used. You can view the list of .resx files within the Solution Explorer by clicking on the Show All Files toolbar button at the top of the Solution Explorer and then expanding the associated Windows Form class. When you select a .resx file and view its properties within the Property Browser, you see that the Build Action property is set to Embedded Resource , as shown in Figure 11.3. This setting tells the compiler to generate a satellite assembly within a subdirectory of the output folder corresponding to the ISO identifier of the culture specified. The ResourceManager , using the ISO information within the CurrentUICulture object, searches the subdirectories of the executing assembly, and if it finds the correct satellite assembly, it loads it and extracts the correct string information being requested for that culture. All of this functionality happens behind the scenes without any extra work needed on your part. However, being able to perform this method using ordinary resources is a valuable technique to learn and is discussed in Recipe 11.9, "Creating and Using Satellite Assemblies."

Figure 11.3. When Build Action is set to Embedded Resource , the compiler automatically generates satellite assemblies.

graphics/11fig03.gif

 <  Day Day Up  >  


Microsoft Visual C# .Net 2003
Microsoft Visual C *. NET 2003 development skills Daquan
ISBN: 7508427505
EAN: 2147483647
Year: 2003
Pages: 440

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net