Csharp/CSharp Tutorial/I18N Internationalization/CultureInfo — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
|
(нет различий)
|
Версия 15:31, 26 мая 2010
Содержание
- 1 Change the current cultures to Mexican Spanish
- 2 Create a CultureInfo object for the nl-BE culture
- 3 Create CultureInfo: de-DE
- 4 Create CultureInfo: en-US
- 5 Enumerates all available cultures
- 6 Germany culture
- 7 Get CultureInfo from data type
- 8 Get current Culture
- 9 Get the current and current-ui cultures
- 10 Russian culture
- 11 turkish-i problem
Change the current cultures to Mexican Spanish
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using System.Resources;
using System.Text;
using System.Threading;
using System.Globalization;
public class MainClass
{
public static void Main()
{
CultureInfo current = CultureInfo.CurrentCulture;
CultureInfo currentUi = CultureInfo.CurrentUICulture;
try
{
CultureInfo mexicanSpanishCi = CultureInfo.GetCultureInfo("es-MX");
Thread.CurrentThread.CurrentCulture = mexicanSpanishCi;
Thread.CurrentThread.CurrentUICulture = mexicanSpanishCi;
Console.WriteLine("{0}/{1}", Thread.CurrentThread.CurrentCulture, Thread.CurrentThread.CurrentUICulture);
Console.WriteLine("{0:C}, {1}", 1250.50m, DateTime.Now.ToLongDateString());
}
finally
{
Thread.CurrentThread.CurrentCulture = current;
Thread.CurrentThread.CurrentUICulture = currentUi;
}
}
}
es-MX/es-MX $1,250.50, domingo, 25 de marzo de 2007
Create a CultureInfo object for the nl-BE culture
using System;
using System.Globalization;
class MainClass
{
public static void Main()
{
CultureInfo ci = new CultureInfo("nl-BE");
// show some basic information
Console.WriteLine("Native Name: " + ci.NativeName);
Console.WriteLine("English Name: " + ci.EnglishName);
}
}
Native Name: Nederlands (Belgi?) English Name: Dutch (Belgium)
Create CultureInfo: de-DE
using System;
using System.Globalization;
using System.Threading;
class MainClass
{
public static void Main()
{
Thread.CurrentThread.CurrentCulture=new CultureInfo("de-DE");
}
}
Create CultureInfo: en-US
using System;
using System.Globalization;
using System.Threading;
class MainClass
{
public static void Main()
{
CultureInfo ci = new CultureInfo("en-US");
}
}
Enumerates all available cultures
using System;
using System.Globalization;
class MainClass
{
public static void Main()
{
foreach (CultureInfo ci in CultureInfo.GetCultures(CultureTypes.AllCultures))
{
Console.WriteLine("{0} | {1}", ci.EnglishName, ci.Name);
}
}
}
Arabic | ar Bulgarian | bg Catalan | ca Chinese (Simplified) | zh-CHS Czech | cs Danish | da German | de Greek | el English | en Spanish | es Finnish | fi French | fr Hebrew | he Hungarian | hu Icelandic | is Italian | it Japanese | ja Korean | ko Dutch | nl Norwegian | no Polish | pl Portuguese | pt Romanian | ro Russian | ru Croatian | hr Slovak | sk Albanian | sq Swedish | sv Thai | th Turkish | tr Urdu | ur Indonesian | id Ukrainian | uk Belarusian | be Slovenian | sl Estonian | et Latvian | lv Lithuanian | lt Persian | fa Vietnamese | vi Armenian | hy Azeri | az Basque | eu Macedonian | mk Afrikaans | af Georgian | ka Faroese | fo Hindi | hi Malay | ms Kazakh | kk Kyrgyz | ky Kiswahili | sw Uzbek | uz Tatar | tt Punjabi | pa Gujarati | gu Tamil | ta Telugu | te Kannada | kn Marathi | mr Sanskrit | sa Mongolian | mn Galician | gl Konkani | kok Syriac | syr Divehi | div Invariant Language (Invariant Country) | Arabic (Saudi Arabia) | ar-SA Bulgarian (Bulgaria) | bg-BG Catalan (Catalan) | ca-ES Chinese (Taiwan) | zh-TW Czech (Czech Republic) | cs-CZ Danish (Denmark) | da-DK German (Germany) | de-DE Greek (Greece) | el-GR English (United States) | en-US Finnish (Finland) | fi-FI French (France) | fr-FR Hebrew (Israel) | he-IL Hungarian (Hungary) | hu-HU Icelandic (Iceland) | is-IS Italian (Italy) | it-IT Japanese (Japan) | ja-JP Korean (Korea) | ko-KR Dutch (Netherlands) | nl-NL Norwegian, Bokm?l (Norway) | nb-NO Polish (Poland) | pl-PL Portuguese (Brazil) | pt-BR Romanian (Romania) | ro-RO Russian (Russia) | ru-RU Croatian (Croatia) | hr-HR Slovak (Slovakia) | sk-SK Albanian (Albania) | sq-AL Swedish (Sweden) | sv-SE Thai (Thailand) | th-TH Turkish (Turkey) | tr-TR Urdu (Islamic Republic of Pakistan) | ur-PK Indonesian (Indonesia) | id-ID Ukrainian (Ukraine) | uk-UA Belarusian (Belarus) | be-BY Slovenian (Slovenia) | sl-SI Estonian (Estonia) | et-EE Latvian (Latvia) | lv-LV Lithuanian (Lithuania) | lt-LT Persian (Iran) | fa-IR Vietnamese (Vietnam) | vi-VN Armenian (Armenia) | hy-AM Azeri (Latin, Azerbaijan) | az-AZ-Latn Basque (Basque) | eu-ES Macedonian (Former Yugoslav Republic of Macedonia) | mk-MK Afrikaans (South Africa) | af-ZA Georgian (Georgia) | ka-GE Faroese (Faroe Islands) | fo-FO Hindi (India) | hi-IN Malay (Malaysia) | ms-MY Kazakh (Kazakhstan) | kk-KZ Kyrgyz (Kyrgyzstan) | ky-KG Kiswahili (Kenya) | sw-KE Uzbek (Latin, Uzbekistan) | uz-UZ-Latn Tatar (Russia) | tt-RU Punjabi (India) | pa-IN Gujarati (India) | gu-IN Tamil (India) | ta-IN Telugu (India) | te-IN Kannada (India) | kn-IN Marathi (India) | mr-IN Sanskrit (India) | sa-IN Mongolian (Cyrillic, Mongolia) | mn-MN Galician (Galician) | gl-ES Konkani (India) | kok-IN Syriac (Syria) | syr-SY Divehi (Maldives) | div-MV Arabic (Iraq) | ar-IQ Chinese (People"s Republic of China) | zh-CN German (Switzerland) | de-CH English (United Kingdom) | en-GB Spanish (Mexico) | es-MX French (Belgium) | fr-BE Italian (Switzerland) | it-CH Dutch (Belgium) | nl-BE Norwegian, Nynorsk (Norway) | nn-NO Portuguese (Portugal) | pt-PT Serbian (Latin, Serbia and Montenegro) | sr-SP-Latn Swedish (Finland) | sv-FI Azeri (Cyrillic, Azerbaijan) | az-AZ-Cyrl Malay (Brunei Darussalam) | ms-BN Uzbek (Cyrillic, Uzbekistan) | uz-UZ-Cyrl Arabic (Egypt) | ar-EG Chinese (Hong Kong S.A.R.) | zh-HK German (Austria) | de-AT English (Australia) | en-AU Spanish (Spain) | es-ES French (Canada) | fr-CA Serbian (Cyrillic, Serbia and Montenegro) | sr-SP-Cyrl Arabic (Libya) | ar-LY Chinese (Singapore) | zh-SG German (Luxembourg) | de-LU English (Canada) | en-CA Spanish (Guatemala) | es-GT French (Switzerland) | fr-CH Arabic (Algeria) | ar-DZ Chinese (Macao S.A.R.) | zh-MO German (Liechtenstein) | de-LI English (New Zealand) | en-NZ Spanish (Costa Rica) | es-CR French (Luxembourg) | fr-LU Arabic (Morocco) | ar-MA English (Ireland) | en-IE Spanish (Panama) | es-PA French (Principality of Monaco) | fr-MC Arabic (Tunisia) | ar-TN English (South Africa) | en-ZA Spanish (Dominican Republic) | es-DO Arabic (Oman) | ar-OM English (Jamaica) | en-JM Spanish (Venezuela) | es-VE Arabic (Yemen) | ar-YE English (Caribbean) | en-CB Spanish (Colombia) | es-CO Arabic (Syria) | ar-SY English (Belize) | en-BZ Spanish (Peru) | es-PE Arabic (Jordan) | ar-JO English (Trinidad and Tobago) | en-TT Spanish (Argentina) | es-AR Arabic (Lebanon) | ar-LB English (Zimbabwe) | en-ZW Spanish (Ecuador) | es-EC Arabic (Kuwait) | ar-KW English (Republic of the Philippines) | en-PH Spanish (Chile) | es-CL Arabic (U.A.E.) | ar-AE Spanish (Uruguay) | es-UY Arabic (Bahrain) | ar-BH Spanish (Paraguay) | es-PY Arabic (Qatar) | ar-QA Spanish (Bolivia) | es-BO Spanish (El Salvador) | es-SV Spanish (Honduras) | es-HN Spanish (Nicaragua) | es-NI Spanish (Puerto Rico) | es-PR Chinese (Traditional) | zh-CHT Serbian | sr Sami (Southern) (Norway) | sma-NO Serbian (Cyrillic) (Bosnia and Herzegovina) | sr-BA-Cyrl Zulu (South Africa) | zu-ZA Xhosa (South Africa) | xh-ZA Tswana (South Africa) | tn-ZA Sami (Northern) (Sweden) | se-SE Sami (Southern) (Sweden) | sma-SE Croatian (Bosnia and Herzegovina) | hr-BA Sami (Inari) (Finland) | smn-FI Quechua (Peru) | quz-PE Sami (Northern) (Finland) | se-FI Sami (Skolt) (Finland) | sms-FI Welsh (United Kingdom) | cy-GB Bosnian (Bosnia and Herzegovina) | bs-BA-Latn Sami (Lule) (Norway) | smj-NO Maori (New Zealand) | mi-NZ Quechua (Ecuador) | quz-EC Serbian (Latin) (Bosnia and Herzegovina) | sr-BA-Latn Bengali (India) | bn-IN Sami (Lule) (Sweden) | smj-SE Malayalam (India) | ml-IN Northern Sotho (South Africa) | ns-ZA Quechua (Bolivia) | quz-BO Sami (Northern) (Norway) | se-NO Maltese (Malta) | mt-MT
Germany culture
using System;
using System.Globalization;
using System.Windows.Forms;
public class MainClass
{
static void Main() {
CultureInfo germany = new CultureInfo( "de-DE" );
double money = 123.45;
string localMoney = money.ToString( "C", germany );
Console.WriteLine( localMoney );
}
}
123,45
Get CultureInfo from data type
using System;
using System.Globalization;
class MainClass
{
static void Main(string[] args)
{
int theInt = 0;
Console.WriteLine("IConvertible-ing System.Int32 to System.Byte");
IConvertible itfConvert = (IConvertible)theInt;
byte theByte = itfConvert.ToByte(CultureInfo.CurrentCulture);
Console.WriteLine("Type code int converted to byte is: {0}", theByte.GetTypeCode());
Console.WriteLine("Value of converted int: {0}", theByte);
}
}
IConvertible-ing System.Int32 to System.Byte Type code int converted to byte is: Byte Value of converted int: 0
Get current Culture
using System;
using System.Globalization;
using System.Threading;
class MainClass
{
public static void Main()
{
Console.WriteLine(Thread.CurrentThread.CurrentCulture.Name);
}
}
en-CA
Get the current and current-ui cultures
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using System.Resources;
using System.Text;
using System.Threading;
using System.Globalization;
public class MainClass
{
public static void Main()
{
CultureInfo current = CultureInfo.CurrentCulture;
CultureInfo currentUI = CultureInfo.CurrentUICulture;
Console.WriteLine("CurrentCulture = {0}", current);
Console.WriteLine("CurrentUICulture = {0}", currentUI);
}
}
Russian culture
using System;
using System.Globalization;
using System.Windows.Forms;
public class MainClass
{
static void Main() {
CultureInfo russian = new CultureInfo( "ru-RU" );
double money = 123.45;
string localMoney = money.ToString( "C", russian );
Console.WriteLine( localMoney );
}
}
123,45?.
turkish-i problem
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using System.Resources;
using System.Text;
using System.Threading;
using System.Globalization;
public class MainClass
{
public static void Main()
{
CultureInfo[] cultures = new CultureInfo[] {
CultureInfo.GetCultureInfo("en-US"),
CultureInfo.GetCultureInfo("tr-TR")
};
char lower = "i";
char upper = "I";
foreach (CultureInfo culture in cultures)
{
Thread.CurrentThread.CurrentCulture = culture;
Console.WriteLine("{0}", culture.DisplayName);
char toUpper = Char.ToUpper(lower);
Console.WriteLine(" Lower->Upper: {0} ({1:X}) -> {2} ({3:X})",lower, (int)lower, toUpper, (int)toUpper);
char toLower = Char.ToLower(upper);
Console.WriteLine(" Upper->Lower: {0} ({1:X}) -> {2} ({3:X})",upper, (int)upper, toLower, (int)toLower);
}
}
}
English (United States) Lower->Upper: i (69) -> I (49) Upper->Lower: I (49) -> i (69) Turkish (Turkey) Lower->Upper: i (69) -> ? (130) Upper->Lower: I (49) -> ? (131)