|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
|
Announcements
Want a new Job?
Chapters
Services
Feature Zones
|
IntroductionOn an Internet-linked world, is not too hard that our applications travel may be to Madagascar or something. Besides, as the time pass, the software working teams are more heterogeneous as our possible clients. In this article I describe in a fast way, the basis for the treatment of globalization in our applications. Lets understand globalization as the fact of allowing an application behave correctly in any culture defined inside an operating system. In general, like in Microsoft(R) Windows(R), we realize that we can set some aspects choosing a culture, using the option Language from the Control Panel. This culture determines the way in which the numbers are displayed on screen, the date format, the format for negative numbers, the language for some emergent messages, etc. In general, the cultures' identification has been standardized is such a way that with a single string, each one is well established. This string is formed by two components separated by a hyphen. The first of them identifies the base for a given culture and the second one specifies the possible culture variations derived from the application of such a culture in a given region or country. Thus, some valid culture name examples are:
Three important details:
BackgroundOn the .NET framework there are two special objects which allow us to globalize our applications:
The main idea is that with the How is this? For instance, if we are going to make our application available in English as well as in Spanish, it doesn't mean that we have to write two different code list. The idea is having two resources files (one for each language, containing the equivalent strings). Using the codeLet's get into the code creating the globalized HelloWorld which could divide two numbers (this is in order to see how the multi-language exceptions handling would be). So, we want our program detect the actual machine configuration (specially the culture settings) and allow to change the language in run time. This is: if Windows(r) setting is configured as Spanish, the program will start in Spanish; nevertheless, at any time we could change the language to English. Ok, now we start creating a Windows Application Project and add two textboxes and two command buttons to the main form:
The textboxes are intended to write two numbers for the program and divide them (in order to generate a multi-language exception when we try to divide by zero). The first brings up the Hello World message box and the second one makes the division of the numbers. Now, we're going to add the two files we'll use. One, for the culture "es-CO" and the other one for the default culture: English:
The default source file will be called myRes.resx. The file for the "es-CO" culture MUST be called like this: Once the files have been added to the project, they look like this:
The relevant columns are name and value. For each string we need in our program, we have to add a dictionary pair name-value. For instance, we want the button's
We can see that same names (though different values) are included in both tables... values for comment, type and mimetype aren't relevant for this application. Now, we can add a using System.Resources;
using System.Globalization;
After this, we can add the attribute I just mentioned, just after the declaration of the visual attributes (buttons, textboxes, etc.): private CultureInfo culture;
In order to get the initial machine culture configuration just at the beginning of the application, we use the following command when the form is created: culture=CultureInfo.CurrentCulture;
You might want to change the language of the application in runtime... so let's add some more controls:
In this way, when a radio button is checked, the culture must be changed. For example, if the Spanish flag is checked the code would be like this: culture=CultureInfo.CreateSpecificCulture("es-CO");
Now... how to change the captions and messages?? ResourceManager rm=new ResourceManager("HelloWorldGlobed.myRes",typeof(Form1).Assembly); string btnHello=rm.GetString("btnHello",culture); We create a Then, we can use the Points of interest
|
||||||||||||||||||||||