Chap 16 Globalization
Chap 16 Globalization
70-536 Chapitre 16
Plan
Globalization
Mohamed Romdhani
INSAT, Octobre 2007 2
M. Romdhani, Décembre 2007
Introduction to globalization
Lesson 1 : Using Culture Information The .NET Framework 2.0 has an incredibly feature rich set of tools that
can be used to create applications that will run in dispersed
geographical regions.
An application can be written that will function equally well in Japan as it
will in Great Britain, with virtually no changes needed to the code. To
accomplish such tasks, the System.Globalization namespace is
provided.
1
Chapitre 1- Introduction aux technologies J2EE
One important reason to use the CultureInfo class is to allow for culturally
If one culture has a date format in mm/dd/yyyy format and the other stores aware string comparisons.
the values in dd/mm/yyyy format, what would happen if you tried to
compare them? To do this, the CultureInfo class has a CompareInfo property, which is an
instance of the CompareInfo class. You can create a new instance of the
Chances are that you'd end up with erroneous comparisons. However, by CompareInfo class or, more practically, you can set it to the CompareInfo
specifying that the dates are from different cultures, comparisons will work property of the CurrentCulture.
correctly. CompareInfo DemoInfo = Thread.CurrentThread.CurrentCulture.CompareInfo;
The same problem exists when dealing with numbers and currency, and The most basic approach to using the CompareInfo class is to call the
essentially the same solution is in place—using the NumberFormatInfo Compare method, passing in the values to be compared. The following code
class instead of the DateFormatInfo class. This can be easily illustrated by illustrates comparing two words for equivalency using the Compare method
using the same code we used previously, but with a slight modification: of the CompareInfo class:
CultureInfo UsersCulture = new CultureInfo("es-VE"); String FirstString = "Coté";
Console.WriteLine("Venezuelan Currency Symbol: " + String SecondString = "coté";
sersCulture.NumberFormat.CurrencySymbol); CompareInfo DemoInfo = new CultureInfo("fr-FR").CompareInfo;
Console.WriteLine("Number Decimal Symbol: " + DemoInfo.Compare(FirstString, SecondString);
UsersCulture.NumberFormat.NumberDecimalSeparator);
If you run this code, the two strings will not be considered equal.
However, you can use options from the "CompareOptions Enumeration" to
The output from this code, will show that Venezuelan currency ignore case for example, etc…
abbreviation is "Bs" and a comma is used as the decimal separator DemoInfo.Compare(FirstString, SecondString, CompareOptions.IgnoreCase);
when writing numbers.
If you run this code, the two strings will be considered equal.
2
Chapitre 1- Introduction aux technologies J2EE
Lesson 1 Summary
Cultures are represented by the CultureInfo class.
The date and time formatting of a custom class can be manipulated through the
GregorianDateTimeFormat property of the CultureAndRegionInfoBuilder class.