Top Banner
Represents information about a specific culture including the names of the culture, the writing system, and the calendar used, as well as access to culture-specific objects that provide information for common operations, such as formatting dates and sorting strings. For a list of all members of this type, see CultureInfo Members . System.Object System.Globalization.CultureInfo [Visual Basic] <Serializable> Public Class CultureInfo Implements ICloneable, IFormatProvider [C#] [Serializable] public class CultureInfo : ICloneable, IFormatProvider [C++] [Serializable] public __gc class CultureInfo : public ICloneable, IFormatProvider [JScript] public Serializable class CultureInfo implements ICloneable, IFormatProvider Thread Safety Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe. Remarks The CultureInfo class holds culture-specific information, such as the associated language, sublanguage, country/region, calendar, and cultural conventions. This class also provides access to culture-specific instances of DateTimeFormatInfo , NumberFormatInfo , CompareInfo , and TextInfo . These objects contain the information required for culture-specific operations, such as casing, formatting dates and numbers, and comparing strings. The String class indirectly uses this class to obtain information about the default culture.
45

Represents Information About a Specific Culture Including the Names of the Culture

Mar 10, 2015

Download

Documents

Kamal Kannan
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Represents Information About a Specific Culture Including the Names of the Culture

Represents information about a specific culture including the names of the culture, the writing system, and the calendar used, as well as access to culture-specific objects that provide information for common operations, such as formatting dates and sorting strings.

For a list of all members of this type, see CultureInfo Members.

System.Object   System.Globalization.CultureInfo

[Visual Basic]<Serializable>Public Class CultureInfo Implements ICloneable, IFormatProvider[C#][Serializable]public class CultureInfo : ICloneable, IFormatProvider[C++][Serializable]public __gc class CultureInfo : public ICloneable, IFormatProvider[JScript]public Serializableclass CultureInfo implements ICloneable, IFormatProvider

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Remarks

The CultureInfo class holds culture-specific information, such as the associated language, sublanguage, country/region, calendar, and cultural conventions. This class also provides access to culture-specific instances of DateTimeFormatInfo, NumberFormatInfo, CompareInfo, and TextInfo. These objects contain the information required for culture-specific operations, such as casing, formatting dates and numbers, and comparing strings.

The String class indirectly uses this class to obtain information about the default culture.

The culture names follow the RFC 1766 standard in the format "<languagecode2>-<country/regioncode2>", where <languagecode2> is a lowercase two-letter code derived from ISO 639-1 and <country/regioncode2> is an uppercase two-letter code derived from ISO 3166. For example, U.S. English is "en-US". In cases where a two-letter language code is not available, the three-letter code derived from ISO 639-2 is used; for example, the three-letter code "div" is used for cultures that use the Dhivehi language. Some culture names have suffixes that specify the script; for example, "-Cyrl" specifies the Cyrillic script, "-Latn" specifies the Latin script.

The following predefined CultureInfo names and identifiers are accepted and used by this class and other classes in the System.Globalization namespace.

Culture Name Culture Identifier Language-Country/Region

Page 2: Represents Information About a Specific Culture Including the Names of the Culture

"" (empty string) 0x007F invariant cultureaf 0x0036 Afrikaansaf-ZA 0x0436 Afrikaans - South Africasq 0x001C Albaniansq-AL 0x041C Albanian - Albaniaar 0x0001 Arabicar-DZ 0x1401 Arabic - Algeriaar-BH 0x3C01 Arabic - Bahrainar-EG 0x0C01 Arabic - Egyptar-IQ 0x0801 Arabic - Iraqar-JO 0x2C01 Arabic - Jordanar-KW 0x3401 Arabic - Kuwaitar-LB 0x3001 Arabic - Lebanonar-LY 0x1001 Arabic - Libyaar-MA 0x1801 Arabic - Moroccoar-OM 0x2001 Arabic - Omanar-QA 0x4001 Arabic - Qatarar-SA 0x0401 Arabic - Saudi Arabiaar-SY 0x2801 Arabic - Syriaar-TN 0x1C01 Arabic - Tunisiaar-AE 0x3801 Arabic - United Arab Emiratesar-YE 0x2401 Arabic - Yemenhy 0x002B Armenianhy-AM 0x042B Armenian - Armeniaaz 0x002C Azeriaz-AZ-Cyrl 0x082C Azeri (Cyrillic) - Azerbaijanaz-AZ-Latn 0x042C Azeri (Latin) - Azerbaijaneu 0x002D Basqueeu-ES 0x042D Basque - Basquebe 0x0023 Belarusianbe-BY 0x0423 Belarusian - Belarusbg 0x0002 Bulgarianbg-BG 0x0402 Bulgarian - Bulgariaca 0x0003 Catalanca-ES 0x0403 Catalan - Catalanzh-HK 0x0C04 Chinese - Hong Kong SARzh-MO 0x1404 Chinese - Macau SARzh-CN 0x0804 Chinese - Chinazh-CHS 0x0004 Chinese (Simplified)zh-SG 0x1004 Chinese - Singaporezh-TW 0x0404 Chinese - Taiwanzh-CHT 0x7C04 Chinese (Traditional)hr 0x001A Croatianhr-HR 0x041A Croatian - Croatiacs 0x0005 Czech

Page 3: Represents Information About a Specific Culture Including the Names of the Culture

cs-CZ 0x0405 Czech - Czech Republicda 0x0006 Danishda-DK 0x0406 Danish - Denmarkdiv 0x0065 Dhivehidiv-MV 0x0465 Dhivehi - Maldivesnl 0x0013 Dutchnl-BE 0x0813 Dutch - Belgiumnl-NL 0x0413 Dutch - The Netherlandsen 0x0009 Englishen-AU 0x0C09 English - Australiaen-BZ 0x2809 English - Belizeen-CA 0x1009 English - Canadaen-CB 0x2409 English - Caribbeanen-IE 0x1809 English - Irelanden-JM 0x2009 English - Jamaicaen-NZ 0x1409 English - New Zealanden-PH 0x3409 English - Philippinesen-ZA 0x1C09 English - South Africaen-TT 0x2C09 English - Trinidad and Tobagoen-GB 0x0809 English - United Kingdomen-US 0x0409 English - United Statesen-ZW 0x3009 English - Zimbabweet 0x0025 Estonianet-EE 0x0425 Estonian - Estoniafo 0x0038 Faroesefo-FO 0x0438 Faroese - Faroe Islandsfa 0x0029 Farsifa-IR 0x0429 Farsi - Iranfi 0x000B Finnishfi-FI 0x040B Finnish - Finlandfr 0x000C Frenchfr-BE 0x080C French - Belgiumfr-CA 0x0C0C French - Canadafr-FR 0x040C French - Francefr-LU 0x140C French - Luxembourgfr-MC 0x180C French - Monacofr-CH 0x100C French - Switzerlandgl 0x0056 Galiciangl-ES 0x0456 Galician - Galicianka 0x0037 Georgianka-GE 0x0437 Georgian - Georgiade 0x0007 Germande-AT 0x0C07 German - Austriade-DE 0x0407 German - Germanyde-LI 0x1407 German - Liechtenstein

Page 4: Represents Information About a Specific Culture Including the Names of the Culture

de-LU 0x1007 German - Luxembourgde-CH 0x0807 German - Switzerlandel 0x0008 Greekel-GR 0x0408 Greek - Greecegu 0x0047 Gujaratigu-IN 0x0447 Gujarati - Indiahe 0x000D Hebrewhe-IL 0x040D Hebrew - Israelhi 0x0039 Hindihi-IN 0x0439 Hindi - Indiahu 0x000E Hungarianhu-HU 0x040E Hungarian - Hungaryis 0x000F Icelandicis-IS 0x040F Icelandic - Icelandid 0x0021 Indonesianid-ID 0x0421 Indonesian - Indonesiait 0x0010 Italianit-IT 0x0410 Italian - Italyit-CH 0x0810 Italian - Switzerlandja 0x0011 Japaneseja-JP 0x0411 Japanese - Japankn 0x004B Kannadakn-IN 0x044B Kannada - Indiakk 0x003F Kazakhkk-KZ 0x043F Kazakh - Kazakhstankok 0x0057 Konkanikok-IN 0x0457 Konkani - Indiako 0x0012 Koreanko-KR 0x0412 Korean - Koreaky 0x0040 Kyrgyzky-KZ 0x0440 Kyrgyz - Kazakhstanlv 0x0026 Latvianlv-LV 0x0426 Latvian - Latvialt 0x0027 Lithuanianlt-LT 0x0427 Lithuanian - Lithuaniamk 0x002F Macedonianmk-MK 0x042F Macedonian - FYROMms 0x003E Malayms-BN 0x083E Malay - Bruneims-MY 0x043E Malay - Malaysiamr 0x004E Marathimr-IN 0x044E Marathi - Indiamn 0x0050 Mongolianmn-MN 0x0450 Mongolian - Mongoliano 0x0014 Norwegian

Page 5: Represents Information About a Specific Culture Including the Names of the Culture

nb-NO 0x0414 Norwegian (Bokml) - Norwaynn-NO 0x0814 Norwegian (Nynorsk) -

Norwaypl 0x0015 Polishpl-PL 0x0415 Polish - Polandpt 0x0016 Portuguesept-BR 0x0416 Portuguese - Brazilpt-PT 0x0816 Portuguese - Portugalpa 0x0046 Punjabipa-IN 0x0446 Punjabi - Indiaro 0x0018 Romanianro-RO 0x0418 Romanian - Romaniaru 0x0019 Russianru-RU 0x0419 Russian - Russiasa 0x004F Sanskritsa-IN 0x044F Sanskrit - Indiasr-SP-Cyrl 0x0C1A Serbian (Cyrillic) - Serbiasr-SP-Latn 0x081A Serbian (Latin) - Serbiask 0x001B Slovaksk-SK 0x041B Slovak - Slovakiasl 0x0024 Sloveniansl-SI 0x0424 Slovenian - Sloveniaes 0x000A Spanishes-AR 0x2C0A Spanish - Argentinaes-BO 0x400A Spanish - Boliviaes-CL 0x340A Spanish - Chilees-CO 0x240A Spanish - Colombiaes-CR 0x140A Spanish - Costa Ricaes-DO 0x1C0A Spanish - Dominican Republices-EC 0x300A Spanish - Ecuadores-SV 0x440A Spanish - El Salvadores-GT 0x100A Spanish - Guatemalaes-HN 0x480A Spanish - Hondurases-MX 0x080A Spanish - Mexicoes-NI 0x4C0A Spanish - Nicaraguaes-PA 0x180A Spanish - Panamaes-PY 0x3C0A Spanish - Paraguayes-PE 0x280A Spanish - Perues-PR 0x500A Spanish - Puerto Ricoes-ES 0x0C0A Spanish - Spaines-UY 0x380A Spanish - Uruguayes-VE 0x200A Spanish - Venezuelasw 0x0041 Swahilisw-KE 0x0441 Swahili - Kenyasv 0x001D Swedish

Page 6: Represents Information About a Specific Culture Including the Names of the Culture

sv-FI 0x081D Swedish - Finlandsv-SE 0x041D Swedish - Swedensyr 0x005A Syriacsyr-SY 0x045A Syriac - Syriata 0x0049 Tamilta-IN 0x0449 Tamil - Indiatt 0x0044 Tatartt-RU 0x0444 Tatar - Russiate 0x004A Telugute-IN 0x044A Telugu - Indiath 0x001E Thaith-TH 0x041E Thai - Thailandtr 0x001F Turkishtr-TR 0x041F Turkish - Turkeyuk 0x0022 Ukrainianuk-UA 0x0422 Ukrainian - Ukraineur 0x0020 Urduur-PK 0x0420 Urdu - Pakistanuz 0x0043 Uzbekuz-UZ-Cyrl 0x0843 Uzbek (Cyrillic) - Uzbekistanuz-UZ-Latn 0x0443 Uzbek (Latin) - Uzbekistanvi 0x002A Vietnamesevi-VN 0x042A Vietnamese - Vietnam

The culture identifier "0x0c0a" for "Spanish - Spain" uses the default international sort order; the culture identifier "0x040A", which is also for "Spanish - Spain", uses the traditional sort order. If the CultureInfo is constructed using the "es-ES" culture name, the new CultureInfo uses the default international sort order. To construct a CultureInfo that uses the traditional sort order, use the culture identifier "0x040A" with the constructor. For more information on other cultures that have alternate sorts, see Using Alternate Sort Orders.

The cultures are generally grouped into three sets: the invariant culture, the neutral cultures, and the specific cultures.

The invariant culture is culture-insensitive. You can specify the invariant culture by name using an empty string ("") or by its culture identifier 0x007F. InvariantCulture retrieves an instance of the invariant culture. It is associated with the English language but not with any country/region. It can be used in almost any method in the Globalization namespace that requires a culture. If a security decision depends on a string comparison or a case-change operation, use the InvariantCulture to ensure that the behavior will be consistent regardless of the culture settings of the system. However, the invariant culture must be used only by processes that require culture-independent results, such as system services; otherwise, it produces results that might be linguistically incorrect or culturally inappropriate.

A neutral culture is a culture that is associated with a language but not with a country/region. A specific culture is a culture that is associated with a language and a country/region. For example, "fr" is a neutral culture and "fr-FR" is a specific culture. Note that "zh-CHS" (Simplified Chinese) and "zh-CHT" (Traditional Chinese) are neutral cultures.

Page 7: Represents Information About a Specific Culture Including the Names of the Culture

The cultures have a hierarchy, such that the parent of a specific culture is a neutral culture and the parent of a neutral culture is the InvariantCulture. The Parent property returns the neutral culture associated with a specific culture.

If the resources for the specific culture are not available in the system, the resources for the neutral culture are used; if the resources for the neutral culture are not available, the resources embedded in the main assembly are used. For more information on the resource fallback process, see Resource Fallback Process.

The list of cultures in the Windows API is slightly different from the list of cultures in the .NET Framework. For example, the neutral culture zh-CHT "Chinese (Traditional)" with culture identifier 0x7C04 is not available in the Windows API. If interoperability with Windows is required (for example, through the p/invoke mechanism), use a specific culture that is defined in the .NET Framework. This will ensure consistency with the equivalent Windows locale, which is identified with the same LCID.

A DateTimeFormatInfo or a NumberFormatInfo can be created only for the invariant culture or for specific cultures, not for neutral cultures.

The user might choose to override some of the values associated with the current culture of Windows through Regional and Language Options (or Regional Options or Regional Settings) in Control Panel. For example, the user might choose to display the date in a different format or to use a currency other than the default for the culture.

If UseUserOverride is true and the specified culture matches the current culture of Windows, the CultureInfo uses those overrides, including user settings for the properties of the DateTimeFormatInfo instance returned by the DateTimeFormat property, the properties of the NumberFormatInfo instance returned by the NumberFormat property, and the properties of the CompareInfo instance returned by the CompareInfo property. If the user settings are incompatible with the culture associated with the CultureInfo (for example, if the selected calendar is not one of the OptionalCalendars), the results of the methods and the values of the properties are undefined.

For cultures that use the euro, the .NET Framework and Windows XP set the default currency as euro; however, older versions of Windows do not. Therefore, if the user of an older version of Windows has not changed the currency setting through Regional Options or Regional Settings in Control Panel, the currency might be incorrect. To use the .NET Framework default setting for the currency, use a CultureInfo constructor overload that accepts a useUserOverride parameter and set it to false.

This class implements the ICloneable interface to enable duplication of CultureInfo objects. It also implements IFormatProvider to supply formatting information to applications.

Example

[Visual Basic, C#, C++] The following code example shows how to create a CultureInfo for "Spanish - Spain" with the international sort and another CultureInfo with the traditional sort.

[Visual Basic]

Page 8: Represents Information About a Specific Culture Including the Names of the Culture

Imports SystemImports System.CollectionsImports System.Globalization

Public Class SamplesCultureInfo

Public Shared Sub Main()

' Creates and initializes the CultureInfo which uses the international sort. Dim myCIintl As New CultureInfo("es-ES", False)

' Creates and initializes the CultureInfo which uses the traditional sort. Dim myCItrad As New CultureInfo(&H40A, False)

' Displays the properties of each culture. Console.WriteLine("{0,-33}{1,-25}{2,-25}", "PROPERTY", "INTERNATIONAL", "TRADITIONAL") Console.WriteLine("{0,-33}{1,-25}{2,-25}", "CompareInfo", myCIintl.CompareInfo, myCItrad.CompareInfo) Console.WriteLine("{0,-33}{1,-25}{2,-25}", "DisplayName", myCIintl.DisplayName, myCItrad.DisplayName) Console.WriteLine("{0,-33}{1,-25}{2,-25}", "EnglishName", myCIintl.EnglishName, myCItrad.EnglishName) Console.WriteLine("{0,-33}{1,-25}{2,-25}", "IsNeutralCulture", myCIintl.IsNeutralCulture, myCItrad.IsNeutralCulture) Console.WriteLine("{0,-33}{1,-25}{2,-25}", "IsReadOnly", myCIintl.IsReadOnly, myCItrad.IsReadOnly) Console.WriteLine("{0,-33}{1,-25}{2,-25}", "LCID", myCIintl.LCID, myCItrad.LCID) Console.WriteLine("{0,-33}{1,-25}{2,-25}", "Name", myCIintl.Name, myCItrad.Name) Console.WriteLine("{0,-33}{1,-25}{2,-25}", "NativeName", myCIintl.NativeName, myCItrad.NativeName) Console.WriteLine("{0,-33}{1,-25}{2,-25}", "Parent", myCIintl.Parent, myCItrad.Parent) Console.WriteLine("{0,-33}{1,-25}{2,-25}", "TextInfo", myCIintl.TextInfo, myCItrad.TextInfo) Console.WriteLine("{0,-33}{1,-25}{2,-25}", "ThreeLetterISOLanguageName", myCIintl.ThreeLetterISOLanguageName, myCItrad.ThreeLetterISOLanguageName) Console.WriteLine("{0,-33}{1,-25}{2,-25}", "ThreeLetterWindowsLanguageName", myCIintl.ThreeLetterWindowsLanguageName, myCItrad.ThreeLetterWindowsLanguageName) Console.WriteLine("{0,-33}{1,-25}{2,-25}", "TwoLetterISOLanguageName", myCIintl.TwoLetterISOLanguageName, myCItrad.TwoLetterISOLanguageName) Console.WriteLine()

' Compare two strings using myCIintl. Console.WriteLine("Comparing ""llegar"" and ""lugar""") Console.WriteLine(" With myCIintl.CompareInfo.Compare: {0}", myCIintl.CompareInfo.Compare("llegar", "lugar")) Console.WriteLine(" With myCItrad.CompareInfo.Compare: {0}", myCItrad.CompareInfo.Compare("llegar", "lugar"))

End Sub 'Main

End Class 'SamplesCultureInfo

Page 9: Represents Information About a Specific Culture Including the Names of the Culture

'This code produces the following output.''PROPERTY INTERNATIONAL TRADITIONAL'CompareInfo CompareInfo - 3082 CompareInfo - 1034'DisplayName Spanish (Spain) Spanish (Spain)'EnglishName Spanish (Spain) Spanish (Spain)'IsNeutralCulture False False'IsReadOnly False False'LCID 3082 1034'Name es-ES es-ES'NativeName espaol (Espaa) espaol (Espaa)'Parent es es'TextInfo TextInfo - 3082 TextInfo - 1034'ThreeLetterISOLanguageName spa spa'ThreeLetterWindowsLanguageName ESN ESN'TwoLetterISOLanguageName es es''Comparing "llegar" and "lugar"' With myCIintl.CompareInfo.Compare: -1' With myCItrad.CompareInfo.Compare: 1

[C#] using System;using System.Collections;using System.Globalization;

public class SamplesCultureInfo {

public static void Main() {

// Creates and initializes the CultureInfo which uses the international sort. CultureInfo myCIintl = new CultureInfo( "es-ES", false ); // Creates and initializes the CultureInfo which uses the traditional sort. CultureInfo myCItrad = new CultureInfo( 0x040A, false );

// Displays the properties of each culture. Console.WriteLine( "{0,-33}{1,-25}{2,-25}", "PROPERTY", "INTERNATIONAL", "TRADITIONAL" ); Console.WriteLine( "{0,-33}{1,-25}{2,-25}", "CompareInfo", myCIintl.CompareInfo, myCItrad.CompareInfo ); Console.WriteLine( "{0,-33}{1,-25}{2,-25}", "DisplayName", myCIintl.DisplayName, myCItrad.DisplayName ); Console.WriteLine( "{0,-33}{1,-25}{2,-25}", "EnglishName", myCIintl.EnglishName, myCItrad.EnglishName ); Console.WriteLine( "{0,-33}{1,-25}{2,-25}", "IsNeutralCulture", myCIintl.IsNeutralCulture, myCItrad.IsNeutralCulture ); Console.WriteLine( "{0,-33}{1,-25}{2,-25}", "IsReadOnly", myCIintl.IsReadOnly, myCItrad.IsReadOnly ); Console.WriteLine( "{0,-33}{1,-25}{2,-25}", "LCID", myCIintl.LCID, myCItrad.LCID ); Console.WriteLine( "{0,-33}{1,-25}{2,-25}", "Name", myCIintl.Name, myCItrad.Name ); Console.WriteLine( "{0,-33}{1,-25}{2,-25}", "NativeName", myCIintl.NativeName, myCItrad.NativeName );

Page 10: Represents Information About a Specific Culture Including the Names of the Culture

Console.WriteLine( "{0,-33}{1,-25}{2,-25}", "Parent", myCIintl.Parent, myCItrad.Parent ); Console.WriteLine( "{0,-33}{1,-25}{2,-25}", "TextInfo", myCIintl.TextInfo, myCItrad.TextInfo ); Console.WriteLine( "{0,-33}{1,-25}{2,-25}", "ThreeLetterISOLanguageName", myCIintl.ThreeLetterISOLanguageName, myCItrad.ThreeLetterISOLanguageName ); Console.WriteLine( "{0,-33}{1,-25}{2,-25}", "ThreeLetterWindowsLanguageName", myCIintl.ThreeLetterWindowsLanguageName, myCItrad.ThreeLetterWindowsLanguageName ); Console.WriteLine( "{0,-33}{1,-25}{2,-25}", "TwoLetterISOLanguageName", myCIintl.TwoLetterISOLanguageName, myCItrad.TwoLetterISOLanguageName ); Console.WriteLine();

// Compare two strings using myCIintl. Console.WriteLine( "Comparing \"llegar\" and \"lugar\"" ); Console.WriteLine( " With myCIintl.CompareInfo.Compare: {0}", myCIintl.CompareInfo.Compare( "llegar", "lugar" ) ); Console.WriteLine( " With myCItrad.CompareInfo.Compare: {0}", myCItrad.CompareInfo.Compare( "llegar", "lugar" ) );

}

}

/*This code produces the following output.

PROPERTY INTERNATIONAL TRADITIONALCompareInfo CompareInfo - 3082 CompareInfo - 1034DisplayName Spanish (Spain) Spanish (Spain)EnglishName Spanish (Spain) Spanish (Spain)IsNeutralCulture False FalseIsReadOnly False FalseLCID 3082 1034Name es-ES es-ESNativeName espaol (Espaa) espaol (Espaa)Parent es esTextInfo TextInfo - 3082 TextInfo - 1034ThreeLetterISOLanguageName spa spaThreeLetterWindowsLanguageName ESN ESNTwoLetterISOLanguageName es es

Comparing "llegar" and "lugar" With myCIintl.CompareInfo.Compare: -1 With myCItrad.CompareInfo.Compare: 1

*/

[C++] #using <mscorlib.dll>using namespace System;using namespace System::Collections;using namespace System::Globalization;

int main(){ // Creates and initializes the CultureInfo which uses the international sort.

Page 11: Represents Information About a Specific Culture Including the Names of the Culture

CultureInfo* myCIintl = new CultureInfo(S"es-ES", false);

// Creates and initializes the CultureInfo which uses the traditional sort. CultureInfo* myCItrad = new CultureInfo(0x040A, false);

// Displays the properties of each culture. Console::WriteLine(S"{0,-33}{1,-25}{2,-25}", S"PROPERTY", S"INTERNATIONAL", S"TRADITIONAL"); Console::WriteLine(S"{0,-33}{1,-25}{2,-25}", S"CompareInfo", myCIintl -> CompareInfo, myCItrad -> CompareInfo); Console::WriteLine(S"{0,-33}{1,-25}{2,-25}", S"DisplayName", myCIintl -> DisplayName, myCItrad -> DisplayName); Console::WriteLine(S"{0,-33}{1,-25}{2,-25}", S"EnglishName", myCIintl -> EnglishName, myCItrad -> EnglishName); Console::WriteLine(S"{0,-33}{1,-25}{2,-25}", S"IsNeutralCulture", __box(myCIintl -> IsNeutralCulture), __box(myCItrad -> IsNeutralCulture)); Console::WriteLine(S"{0,-33}{1,-25}{2,-25}", S"IsReadOnly", __box(myCIintl -> IsReadOnly), __box(myCItrad -> IsReadOnly)); Console::WriteLine(S"{0,-33}{1,-25}{2,-25}", S"LCID", __box(myCIintl -> LCID), __box(myCItrad -> LCID)); Console::WriteLine(S"{0,-33}{1,-25}{2,-25}", S"Name", myCIintl -> Name, myCItrad -> Name); Console::WriteLine(S"{0,-33}{1,-25}{2,-25}", S"NativeName", myCIintl -> NativeName, myCItrad -> NativeName); Console::WriteLine(S"{0,-33}{1,-25}{2,-25}", S"Parent", myCIintl -> Parent, myCItrad -> Parent); Console::WriteLine(S"{0,-33}{1,-25}{2,-25}", S"TextInfo", myCIintl -> TextInfo, myCItrad -> TextInfo); Console::WriteLine(S"{0,-33}{1,-25}{2,-25}", S"ThreeLetterISOLanguageName", myCIintl -> ThreeLetterISOLanguageName, myCItrad -> ThreeLetterISOLanguageName); Console::WriteLine(S"{0,-33}{1,-25}{2,-25}", S"ThreeLetterWindowsLanguageName", myCIintl -> ThreeLetterWindowsLanguageName, myCItrad -> ThreeLetterWindowsLanguageName); Console::WriteLine(S"{0,-33}{1,-25}{2,-25}", S"TwoLetterISOLanguageName", myCIintl -> TwoLetterISOLanguageName, myCItrad -> TwoLetterISOLanguageName); Console::WriteLine();

// Compare two strings using myCIintl -> Console::WriteLine(S"Comparing \"llegar\" and \"lugar\""); Console::WriteLine(S" With myCIintl -> CompareInfo -> Compare: {0}", __box(myCIintl -> CompareInfo -> Compare(S"llegar", S"lugar"))); Console::WriteLine(S" With myCItrad -> CompareInfo -> Compare: {0}", __box(myCItrad -> CompareInfo -> Compare(S"llegar", S"lugar")));}

/*This code produces the following output.

PROPERTY INTERNATIONAL TRADITIONAL CompareInfo CompareInfo - 3082 CompareInfo - 1034 DisplayName Spanish (Spain) Spanish (Spain) EnglishName Spanish (Spain) Spanish (Spain) IsNeutralCulture False False IsReadOnly False False LCID 3082 1034 Name es-ES es-ES

Page 12: Represents Information About a Specific Culture Including the Names of the Culture

NativeName espaol (Espaa) espaol (Espaa) Parent es es TextInfo TextInfo - 3082 TextInfo - 1034 ThreeLetterISOLanguageName spa spa ThreeLetterWindowsLanguageName ESN ESN TwoLetterISOLanguageName es es

Comparing "llegar" and "lugar" With myCIintl -> CompareInfo -> Compare: -1 With myCItrad -> CompareInfo -> Compare: 1

*/

[Visual Basic, C#, C++] The following code example determines the parent culture of each specific culture using the Chinese language.

[Visual Basic] Imports SystemImports System.Globalization

Public Class SamplesCultureInfo

Public Shared Sub Main()

' Prints the header. Console.WriteLine("SPECIFIC CULTURE PARENT CULTURE")

' Determines the specific cultures that use the Chinese language, and displays the parent culture. Dim ci As CultureInfo For Each ci In CultureInfo.GetCultures(CultureTypes.SpecificCultures) If ci.TwoLetterISOLanguageName = "zh" Then Console.Write("0x{0} {1} {2,-37}", ci.LCID.ToString("X4"), ci.Name, ci.EnglishName) Console.WriteLine("0x{0} {1} {2}", ci.Parent.LCID.ToString("X4"), ci.Parent.Name, ci.Parent.EnglishName) End If Next ci

End Sub 'Main

End Class 'SamplesCultureInfo

'This code produces the following output.''SPECIFIC CULTURE PARENT CULTURE'0x0404 zh-TW Chinese (Taiwan) 0x7C04 zh-CHT Chinese (Traditional)'0x0804 zh-CN Chinese (People's Republic of China) 0x0004 zh-CHS Chinese (Simplified)'0x0C04 zh-HK Chinese (Hong Kong S.A.R.) 0x7C04 zh-CHT Chinese (Traditional)'0x1004 zh-SG Chinese (Singapore) 0x0004 zh-CHS Chinese (Simplified)'0x1404 zh-MO Chinese (Macau S.A.R.) 0x0004 zh-CHS Chinese (Simplified)

Page 13: Represents Information About a Specific Culture Including the Names of the Culture

[C#] using System;using System.Globalization;

public class SamplesCultureInfo {

public static void Main() {

// Prints the header. Console.WriteLine( "SPECIFIC CULTURE PARENT CULTURE" );

// Determines the specific cultures that use the Chinese language, and displays the parent culture. foreach ( CultureInfo ci in CultureInfo.GetCultures( CultureTypes.SpecificCultures ) ) { if ( ci.TwoLetterISOLanguageName == "zh" ) { Console.Write( "0x{0} {1} {2,-37}", ci.LCID.ToString("X4"), ci.Name, ci.EnglishName ); Console.WriteLine( "0x{0} {1} {2}", ci.Parent.LCID.ToString("X4"), ci.Parent.Name, ci.Parent.EnglishName ); } }

}

}

/*This code produces the following output.

SPECIFIC CULTURE PARENT CULTURE0x0404 zh-TW Chinese (Taiwan) 0x7C04 zh-CHT Chinese (Traditional)0x0804 zh-CN Chinese (People's Republic of China) 0x0004 zh-CHS Chinese (Simplified)0x0C04 zh-HK Chinese (Hong Kong S.A.R.) 0x7C04 zh-CHT Chinese (Traditional)0x1004 zh-SG Chinese (Singapore) 0x0004 zh-CHS Chinese (Simplified)0x1404 zh-MO Chinese (Macau S.A.R.) 0x0004 zh-CHS Chinese (Simplified)

*/

[C++] #using <mscorlib.dll>

using namespace System;using namespace System::Globalization;

int main() { // Prints the header. Console::WriteLine(S"SPECIFIC CULTURE PARENT CULTURE" );

// Determines the specific cultures that use the Chinese language, // and displays the parent culture. System::Collections::IEnumerator* en = CultureInfo::GetCultures(CultureTypes::SpecificCultures)->GetEnumerator();

Page 14: Represents Information About a Specific Culture Including the Names of the Culture

while (en->MoveNext()) { CultureInfo* ci = __try_cast<CultureInfo*>(en->Current); if (ci->TwoLetterISOLanguageName->Equals(S"zh")) { Console::Write(S"0x{0} {1} {2,-37}", ci->LCID.ToString("X4"), ci->Name, ci->EnglishName); Console::WriteLine(S"0x{0} {1} {2}", ci->Parent->LCID.ToString(S"X4"), ci->Parent->Name, ci->Parent->EnglishName); } }}

/*This code produces the following output.

SPECIFIC CULTURE PARENT CULTURE0x0404 zh-TW Chinese (Taiwan) 0x7C04 zh-CHT Chinese (Traditional)0x0804 zh-CN Chinese (People's Republic of China) 0x0004 zh-CHS Chinese (Simplified)0x0C04 zh-HK Chinese (Hong Kong S.A.R.) 0x7C04 zh-CHT Chinese (Traditional)0x1004 zh-SG Chinese (Singapore) 0x0004 zh-CHS Chinese (Simplified)0x1404 zh-MO Chinese (Macau S.A.R.) 0x0004 zh-CHS Chinese (Simplified)

*/

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button in the upper-left corner of the page.

Requirements

 return Encoding.Unicode.GetString(                            Encoding.Convert(            Encoding.UTF8,            Encoding.Unicode,            Encoding.UTF8.GetBytes(utf8)));    }

T

class Example

02 {

03     public static void Main()

04     {

05         string text = "我喜欢跑步。";

06         string translated = Translator.Translate(text, Language.Chinese_Simplified, Language.English);

07         Console.WriteLine(translated);

Page 15: Represents Information About a Specific Culture Including the Names of the Culture

08         // I like running.

09     }

10

<asp:TextBox runat="server" ID="TXTReview" ></asp:TextBox>

2) Include the following javascript code to make the text box multilingual:This code will allow the user to type in Hindi and English using english keyboard.

Code:<script type="text/javascript" src="http://www.google.com/jsapi"></script><script type="text/javascript">      // Load the Google Transliteration API      google.load("elements", "1", {         packages: "transliteration"      });

      function onLoad() {         var options = {            sourceLanguage:                google.elements.transliteration.LanguageCode.ENGLISH,            destinationLanguage:                [google.elements.transliteration.LanguageCode.HINDI],            shortcutKey: 'ctrl+g',            [color=red]transliterationEnabled: false[/color]         };

         // Create an instance on TransliterationControl with the required         // options.         var control =            new google.elements.transliteration.TransliterationControl(options);

         // Enable transliteration in the textbox with id         // 'transliterateTextarea'.         control.makeTransliteratable(['[color=red]<%=TXTReview.ClientID%>[/color]']);      }      google.setOnLoadCallback(onLoad);    </script>

Multi-Language Add-In for Visual StudioSee also

OverviewMajor Features

Page 16: Represents Information About a Specific Culture Including the Names of the Culture

Quick Tour (ASP.NET 2.0)Quick Tour (Unmanaged C++/MFC)What's NewDownload

Quick Tour (Windows Forms)

Activating the Multi-Language Add-In

After you have installed the Add-In, there will be a new menu item in the Tools menu in Visual Studio.

This menu item activates the Add-In and shows it in a tool-window. You can dock this window at the side of the main Visual Studio window, or drag it into a tab group, like other tool windows in Visual Svtudio. It's probably best to place it at the bottom, in a wide format.

Page 17: Represents Information About a Specific Culture Including the Names of the Culture

Selecting a project

A Visual Studio solution may contain multiple projects. However, the Multi-Language Add-In always works with a single project. To get started, you must first select the project. There are two ways to do this.

from a dialog

When you select the Add-In from the tools menu, it will probably show a list of the projects in a dialog. Simply select the project and click on OK.

Page 18: Represents Information About a Specific Culture Including the Names of the Culture

This dialog can be disabled, so if somebody else has already worked with the Add-In, it might not appear.

from a drop down list

At the top of the Add-In's main window, just below the toolbar, there is a drop down project list

You can select a different project at any time from this list.

Initialising the project for localization

Page 19: Represents Information About a Specific Culture Including the Names of the Culture

When you select a project for the first time, you must specify what the original language of the project is. The Add-In will show a list of the languages supported by Windows.

Select the original language and click on OK.

The buttons below the list change the way the list is displayed. In particular, the button English simply shows the language names in English. It does not select English in the list.

Page 20: Represents Information About a Specific Culture Including the Names of the Culture

This dialog will probably be followed by second dialog, with options for scanning the project. Just click on OK to accept the default options.

The Add-In will now add two new files to your project.

<project name>_ml.xmlThis is the project database used by the Add-In. It is added to the project with BuildAction=None.

mlstring.vb or mlstring.cs or mlstring.h + .cpp

This module contains support functions, in particular the function ml_string(), which is used to load localized strings.

Scanning the project

The Add-In will now scan the project. This is performed in two phases:

scanning controls scanning source code

In the first phase, the controls in each Form and each UserControl are scanned for properties with the localizable attribute. In the second phase, the source code of the project is scanned for texts which may require translation.

Page 21: Represents Information About a Specific Culture Including the Names of the Culture

The results of the scan are displayed in two separate grids in the Add-In's window.

You can switch between these grids using the tabs at the bottom of the window.

Adding a second language

To add a new language to the project, click on the symbol on the Add-In's toolbar

This brings up a dialog very similar to one where we selected the original language of the project.

Page 22: Represents Information About a Specific Culture Including the Names of the Culture

Select a new language from the list.

If the Microsoft Translator supports both the original language and the selected language then the option Get translations from Microsoft Translator is enabled.

Select this option if you want the texts to be translated automatically.

Click on OK to add this language to the project.

Some languages, such as German or French, are considered to be neutral languages. The regional variations, such as German(Germany), German(Austria), French(France) or French(Canada) are referred to as specific languages. You should always add the neutral language before adding a related specific language. If you do choose to add a specific language, the Add-In will give you the option of adding both neutral and specific languages or only the neutral language.

After adding the second language, the Add-In will

add a new column to the grids for the new language search for translations of common texts such as OK and Cancel in the Global Translations

Database if you selected the Microsoft Translator option, then it will translate all other texts online

using the Microsoft Translator

Now we will take a closer look at the two grids.

The controls grid

To see the controls grid, make sure that the controls tab at the bottom of the window is selected. The grid should look something like the following screenshot.

Page 23: Represents Information About a Specific Culture Including the Names of the Culture

By default, the properties are shown in a hierarchical manner, showing the association of properties to controls. As an alternative, you can view the properties on each Form or UserControl in a flat list. To select this mode, click on the button on the toolbar and then select Flat list from the menu, as shown below:

The controls grid will then look something like the following screenshot.

Page 24: Represents Information About a Specific Culture Including the Names of the Culture

To enter a translation, simply click in cell and type in the new text. If you are able to translate the text yourself, this is the easiest way enter translations.

If a text is shown in light grey, then it is the text which would be retrieved at runtime via the resource fallback mechanism. In general, if a text is not defined for a specific language (e.g. Spanish(Mexico)) then the text for the neutral language (e.g. Spanish) would be used. If this has not been defined, then the original text in the project would be used.

The check boxes to the left of the property name indicates that the text has been selected for translation. By default, all properties which contain a non empty string are selected. In the screenshot above, you can see two menu separators with the text "-". It makes no sense to translate these, so we can deselect them by clicking on the check boxes.

In fact, we never really want to see these properties again, so we can go one step further and hide

Page 25: Represents Information About a Specific Culture Including the Names of the Culture

them completely. To do this, we first click on the sun symbol at the left hand margin. The sun symbol is replaced by a moon symbol .

To actually hide the lines, click on the mask symbol on the toolbar . If you want the hidden properties to be shown again, click on the button on the toolbar and select ''Show hidden properties" from the menu.

By default, properties containing empty strings are not shown in the grid. It very rarely makes sense to translate empty strings, so this if sensible setting. If you do want to see localizable properties containing empty strings, then you can modify this option in the settings dialog. To show this dialog click on the settings button on the toolbar. Details of this and other options are described in the online help file.

The source code grid

To see the source code grid, make sure that the source code tab at the bottom of the window is selected. The grid should look something like the following screenshot.

Page 26: Represents Information About a Specific Culture Including the Names of the Culture

As in the controls grid, you can select a string for translation by clicking in the checkbox to the left of the line number. In contrast to the controls grid however, none of the texts are selected automatically.

When you click on a line in the source code grid, the corresponding line in the source code will be shown in the source editor. Alternativly, if you select a line in the source editor, which contains a string, you can locate this line in the source code grid by clicking on the goto line button on the toolbar.

Page 27: Represents Information About a Specific Culture Including the Names of the Culture

When you select a string for translation by clicking on the checkbox, the Add-In will assign a string ID number to the text and insert a call to the function ml_string() into the source code.

As you can see, this function has two parameters:

Page 28: Represents Information About a Specific Culture Including the Names of the Culture

the String ID number and the original text

In fact only the string ID will actually be used, so you could consider the original text as a comment. Leaving the original text in the source code serves to make the code more readable.

The exact format of the function ml_string depends on the computer language used in the project.C# OpenFile.Title = ml.ml_string(27, "Open") ;

VB.NET OpenFile.Title = ml_string(27,"Open")

C++ OpenFile->Title = ML_STRING(28, "Open") ;

The function ml_string is implemented in the module mlstring which was added to the project from a template file (usually in the directory C:\Program Files\MultiLang2005\Templates).

Once a string has been selected for translation, you can enter a translation simply by typing a new text into the grid.

As with the controls grid, we also have the option of hiding texts which do not require translation. For example, none of the texts in the module AssemblyInfo.cs need to be translated.As before, we hide a string by clicking on the sun symbol at the left hand margin, which is then replaced by a moon symbol . At the same time, the comment //MLHIDE ('MLHIDE in VB.NET) is added to the end of the source code line, to mark it as hidden.

Page 29: Represents Information About a Specific Culture Including the Names of the Culture

To actually hide the lines, click on the mask symbol on the toolbar . This works a little differently to controls grid. The hidden items are collapsed behind a new node hidden and you can view them at any time simply be expanding this node.

It is good practice to either select or hide every string in the project. If new strings are added to the source code, it is then much easier to find the new strings in the grid. Of course, you can also add the MLHIDE comment to lines in the source code editor. When the Add-In scans the project, it will automatically hide these strings.

Page 30: Represents Information About a Specific Culture Including the Names of the Culture

Filtering texts with regular expressions

In many cases, you will be able to select, or alternativly hide, texts in the source code based on simple rules. For example you will probably not want to translate SQL strings, or the parameters to an event logging function. On the other hand, you will probably always want to translate the parameters to the MessageBox function.

You can handle operations like this easily with the feature "Filter with regular expressions". You can select this option from the tools menu as shown below, or from the context menu in the source code grid.

This command shows the filter dialog, in which you can enter a search string as a regular expression. For example in the screenshot shown below, the search string " ^ select " will search for any string starting with the word select, with the option to hide the string.

The dialog offers the option to match only the string, or the complete source code line. By matching the complete code line, it is easy to detect strings used in particular function calls.

Page 31: Represents Information About a Specific Culture Including the Names of the Culture

When the string is found, the Add-In asks whether the specific string should actually be hidden.

Using the translation memory

Aside from the project database used to store the translations for an individual project, the Multi-Language Add-In also stores all translations in global translations database. When it detects an exact match between a new text and a translation stored in the global database, it will insert the translation automatically. This is great for common terms like OK and Cancel.

If you are able to translate the texts yourself, then the translation memory provides an additional help, based on the translations stored in the global database. To use the translation memory, first click in the cell you want to edit, and then hit F3 or F12. The following screenshot shows the translation memory dialog with the text Add a new language to the project, which should be translated into German.

Page 32: Represents Information About a Specific Culture Including the Names of the Culture

In the lower part of the dialog, there is list of existing translations, containing one or more of the same words as the string to be translated. The list is sorted according to the number of matching words, so the most useful translations should be near the top. You can copy words out of the grid and edit the new translation in the edit box marked Translation.

Obviously, the common words "a", "to" and "the" will not be of much help. If you select the tab Ignored words, you can select the words which are to be ignored. The Add-In keeps a list of ignored words in the global database and automatically ignores these words in future.

The translation memory feature is particularly useful for technical terms where you might not be familiar with the correct translation and where you want to use terms consistently.

Using the Spreadsheet export

If you are not able to translate the texts yourself, you will have to give them to a translator. For this purpose you can use the Spreadsheet export/import feature. There are two versions of this feature:

the simple version with one worksheet and no macros (for Excel or OpenOffice)

Page 33: Represents Information About a Specific Culture Including the Names of the Culture

the three worksheet structured export with macro support (for Excel)

Both versions are accessed via the Excel symbol on the toolbar.

The screenshot below shows the format of the simple spreadsheet file. As you can see, the first column contains the string ID number, followed by a column for each language. The first two rows contain the language names and the locale ID numbers.

The translator should update texts in the appropriate language column, without changing the format of the file. When the translator is complete, you can import the translations back into the project.

The three worksheet format contains two additional worksheets, which closely resemble the controls grid and the source code grid in the Add-In. These worksheets provide more context information for the translator. Because all texts in the additional worksheets are also present in the third worksheet, Excel macros are used to maintain consistency within the file. The macros also provide some additional functionality, similar to some of the functions provided by the Add-In.

The three worksheet is to be recommended, unless your organization is adamantly opposed to using macros.

The Excel support requires that Excel be installed on the PC. The OpenOffice support uses the AODL Library and does not require that OpenOffice be installed.

Exporting the texts to resource files

In order for the translations to be used in your project you must:

Page 34: Represents Information About a Specific Culture Including the Names of the Culture

set the Localizable attribute in each Form and each UserControl export the texts to resource files in the ResX format

To do this, click on the runtime support symbol on the toolbar and select the command Native Runtime Support from the dropdown menu.

This command will bring up a dialog, from which you can select the languages to export and a couple of other options. Click on Export to start the operation.

Page 35: Represents Information About a Specific Culture Including the Names of the Culture

When it is completed, you will see in the solution explorer window, that a number of ResX files have been added to your project. All of these files have the BuildAction=EmbeddedResource.

When you compile your project, additional so called satellite dlls will be generated. These dlls are created in subdirectories of the bin\Debug or bin\Release directories, named according to the language abbreviation (ISO 639-1 and ISO 3166, formerly RFC 1766).

Page 36: Represents Information About a Specific Culture Including the Names of the Culture

The satellite dlls must be distributed with your application and installed in subdirectories exactly as they are generated by Visual Studio.

The compiled project is now localized. Windows will initialise the application to use the language of the Windows user interface. For example, if you have added support for German, and you install your application (with the satellite dlls) on computer running a German version of Windows, then German resources will automatically be used.

Selecting the language of the application

It is very practical to be able to select the language for your application, independently of the language used by Windows. This is almost essential for testing, but you may also want to make it a permanent feature of your application. We must consider two cases separately:

selecting the language when the program starts changing the language of the running program

Technically, it is very easy to set the language of a program when it starts up. It is only necessary to set the CurrentUICulture property of the main thread, before the main form of the program is called.

The Multi-Language can add a form to your project which allows the user to select the language when the program starts, as shown in the following screenshot.

With this dialog you can select the language, and specify whether the dialog should be shown next time the program is started.

Page 37: Represents Information About a Specific Culture Including the Names of the Culture

To add this feature, click on the runtime support symbol on the toolbar and select the command Add language selection form to your project from the dropdown menu.

This brings up a dialog showing which actions are necessary to add this dialog to your project.

Click on Add Now to perform start the operation.

This will add a form called SelectLanguage to your project, and some code to show the form when the program starts up.

Changing the language of a running program

A little more effort is required to change the language once the user interface of the program has been initialised. The problem breaks down into three operations:

Selecting a new language

To select a new language, it is simply necessary to show the SelectLanguage form, described above. This can easily be added to a menu command in your application.

Broadcasting events

Your application may use multiple Forms, each of which may contain UserControls. When the language is changed, it is necessary to update the user interface of each active component. The best way to handle this is with an event mechanism.

In general, you may use UserControls in multiple, separately compiled components. For this purpose, events must be generated via a public interface. The easiest way to

Page 38: Represents Information About a Specific Culture Including the Names of the Culture

handle this is to generate the events using a singleton object, compiled in a separate project.

Updating the user interface

Each Form and UserControl requires an event handler, which updates the user interface when the language is changed. The function InitializeComponent generated by Visual Studio is not designed to be called repeatedly. To update the user interface, the Add-In can generate a function called ml_UpdateControls to reinitialise the properties in the user interface.

The Multi-Language Add-In can generate the code for the second two points automatically, via the menu command Support for Runtime Language Switching.

A minor change is required to the SelectLanguage form, in order to generate a language changed event.

This is described in a tutorial in the Add-In's help file.