+#include "wx/intl.h"
+#include "wx/utils.h" // for wxSetEnv
+
+static wxLocale gs_localeDefault;
+ // NOTE: don't init it here as it needs a wxAppTraits object
+ // and thus must be init-ed after creation of the wxInitializer
+ // class in the main()
+
+// find the name of the language from its value
+static const wxChar *GetLangName(int lang)
+{
+ static const wxChar *languageNames[] =
+ {
+ wxT("DEFAULT"),
+ wxT("UNKNOWN"),
+ wxT("ABKHAZIAN"),
+ wxT("AFAR"),
+ wxT("AFRIKAANS"),
+ wxT("ALBANIAN"),
+ wxT("AMHARIC"),
+ wxT("ARABIC"),
+ wxT("ARABIC_ALGERIA"),
+ wxT("ARABIC_BAHRAIN"),
+ wxT("ARABIC_EGYPT"),
+ wxT("ARABIC_IRAQ"),
+ wxT("ARABIC_JORDAN"),
+ wxT("ARABIC_KUWAIT"),
+ wxT("ARABIC_LEBANON"),
+ wxT("ARABIC_LIBYA"),
+ wxT("ARABIC_MOROCCO"),
+ wxT("ARABIC_OMAN"),
+ wxT("ARABIC_QATAR"),
+ wxT("ARABIC_SAUDI_ARABIA"),
+ wxT("ARABIC_SUDAN"),
+ wxT("ARABIC_SYRIA"),
+ wxT("ARABIC_TUNISIA"),
+ wxT("ARABIC_UAE"),
+ wxT("ARABIC_YEMEN"),
+ wxT("ARMENIAN"),
+ wxT("ASSAMESE"),
+ wxT("AYMARA"),
+ wxT("AZERI"),
+ wxT("AZERI_CYRILLIC"),
+ wxT("AZERI_LATIN"),
+ wxT("BASHKIR"),
+ wxT("BASQUE"),
+ wxT("BELARUSIAN"),
+ wxT("BENGALI"),
+ wxT("BHUTANI"),
+ wxT("BIHARI"),
+ wxT("BISLAMA"),
+ wxT("BRETON"),
+ wxT("BULGARIAN"),
+ wxT("BURMESE"),
+ wxT("CAMBODIAN"),
+ wxT("CATALAN"),
+ wxT("CHINESE"),
+ wxT("CHINESE_SIMPLIFIED"),
+ wxT("CHINESE_TRADITIONAL"),
+ wxT("CHINESE_HONGKONG"),
+ wxT("CHINESE_MACAU"),
+ wxT("CHINESE_SINGAPORE"),
+ wxT("CHINESE_TAIWAN"),
+ wxT("CORSICAN"),
+ wxT("CROATIAN"),
+ wxT("CZECH"),
+ wxT("DANISH"),
+ wxT("DUTCH"),
+ wxT("DUTCH_BELGIAN"),
+ wxT("ENGLISH"),
+ wxT("ENGLISH_UK"),
+ wxT("ENGLISH_US"),
+ wxT("ENGLISH_AUSTRALIA"),
+ wxT("ENGLISH_BELIZE"),
+ wxT("ENGLISH_BOTSWANA"),
+ wxT("ENGLISH_CANADA"),
+ wxT("ENGLISH_CARIBBEAN"),
+ wxT("ENGLISH_DENMARK"),
+ wxT("ENGLISH_EIRE"),
+ wxT("ENGLISH_JAMAICA"),
+ wxT("ENGLISH_NEW_ZEALAND"),
+ wxT("ENGLISH_PHILIPPINES"),
+ wxT("ENGLISH_SOUTH_AFRICA"),
+ wxT("ENGLISH_TRINIDAD"),
+ wxT("ENGLISH_ZIMBABWE"),
+ wxT("ESPERANTO"),
+ wxT("ESTONIAN"),
+ wxT("FAEROESE"),
+ wxT("FARSI"),
+ wxT("FIJI"),
+ wxT("FINNISH"),
+ wxT("FRENCH"),
+ wxT("FRENCH_BELGIAN"),
+ wxT("FRENCH_CANADIAN"),
+ wxT("FRENCH_LUXEMBOURG"),
+ wxT("FRENCH_MONACO"),
+ wxT("FRENCH_SWISS"),
+ wxT("FRISIAN"),
+ wxT("GALICIAN"),
+ wxT("GEORGIAN"),
+ wxT("GERMAN"),
+ wxT("GERMAN_AUSTRIAN"),
+ wxT("GERMAN_BELGIUM"),
+ wxT("GERMAN_LIECHTENSTEIN"),
+ wxT("GERMAN_LUXEMBOURG"),
+ wxT("GERMAN_SWISS"),
+ wxT("GREEK"),
+ wxT("GREENLANDIC"),
+ wxT("GUARANI"),
+ wxT("GUJARATI"),
+ wxT("HAUSA"),
+ wxT("HEBREW"),
+ wxT("HINDI"),
+ wxT("HUNGARIAN"),
+ wxT("ICELANDIC"),
+ wxT("INDONESIAN"),
+ wxT("INTERLINGUA"),
+ wxT("INTERLINGUE"),
+ wxT("INUKTITUT"),
+ wxT("INUPIAK"),
+ wxT("IRISH"),
+ wxT("ITALIAN"),
+ wxT("ITALIAN_SWISS"),
+ wxT("JAPANESE"),
+ wxT("JAVANESE"),
+ wxT("KANNADA"),
+ wxT("KASHMIRI"),
+ wxT("KASHMIRI_INDIA"),
+ wxT("KAZAKH"),
+ wxT("KERNEWEK"),
+ wxT("KINYARWANDA"),
+ wxT("KIRGHIZ"),
+ wxT("KIRUNDI"),
+ wxT("KONKANI"),
+ wxT("KOREAN"),
+ wxT("KURDISH"),
+ wxT("LAOTHIAN"),
+ wxT("LATIN"),
+ wxT("LATVIAN"),
+ wxT("LINGALA"),
+ wxT("LITHUANIAN"),
+ wxT("MACEDONIAN"),
+ wxT("MALAGASY"),
+ wxT("MALAY"),
+ wxT("MALAYALAM"),
+ wxT("MALAY_BRUNEI_DARUSSALAM"),
+ wxT("MALAY_MALAYSIA"),
+ wxT("MALTESE"),
+ wxT("MANIPURI"),
+ wxT("MAORI"),
+ wxT("MARATHI"),
+ wxT("MOLDAVIAN"),
+ wxT("MONGOLIAN"),
+ wxT("NAURU"),
+ wxT("NEPALI"),
+ wxT("NEPALI_INDIA"),
+ wxT("NORWEGIAN_BOKMAL"),
+ wxT("NORWEGIAN_NYNORSK"),
+ wxT("OCCITAN"),
+ wxT("ORIYA"),
+ wxT("OROMO"),
+ wxT("PASHTO"),
+ wxT("POLISH"),
+ wxT("PORTUGUESE"),
+ wxT("PORTUGUESE_BRAZILIAN"),
+ wxT("PUNJABI"),
+ wxT("QUECHUA"),
+ wxT("RHAETO_ROMANCE"),
+ wxT("ROMANIAN"),
+ wxT("RUSSIAN"),
+ wxT("RUSSIAN_UKRAINE"),
+ wxT("SAMOAN"),
+ wxT("SANGHO"),
+ wxT("SANSKRIT"),
+ wxT("SCOTS_GAELIC"),
+ wxT("SERBIAN"),
+ wxT("SERBIAN_CYRILLIC"),
+ wxT("SERBIAN_LATIN"),
+ wxT("SERBO_CROATIAN"),
+ wxT("SESOTHO"),
+ wxT("SETSWANA"),
+ wxT("SHONA"),
+ wxT("SINDHI"),
+ wxT("SINHALESE"),
+ wxT("SISWATI"),
+ wxT("SLOVAK"),
+ wxT("SLOVENIAN"),
+ wxT("SOMALI"),
+ wxT("SPANISH"),
+ wxT("SPANISH_ARGENTINA"),
+ wxT("SPANISH_BOLIVIA"),
+ wxT("SPANISH_CHILE"),
+ wxT("SPANISH_COLOMBIA"),
+ wxT("SPANISH_COSTA_RICA"),
+ wxT("SPANISH_DOMINICAN_REPUBLIC"),
+ wxT("SPANISH_ECUADOR"),
+ wxT("SPANISH_EL_SALVADOR"),
+ wxT("SPANISH_GUATEMALA"),
+ wxT("SPANISH_HONDURAS"),
+ wxT("SPANISH_MEXICAN"),
+ wxT("SPANISH_MODERN"),
+ wxT("SPANISH_NICARAGUA"),
+ wxT("SPANISH_PANAMA"),
+ wxT("SPANISH_PARAGUAY"),
+ wxT("SPANISH_PERU"),
+ wxT("SPANISH_PUERTO_RICO"),
+ wxT("SPANISH_URUGUAY"),
+ wxT("SPANISH_US"),
+ wxT("SPANISH_VENEZUELA"),
+ wxT("SUNDANESE"),
+ wxT("SWAHILI"),
+ wxT("SWEDISH"),
+ wxT("SWEDISH_FINLAND"),
+ wxT("TAGALOG"),
+ wxT("TAJIK"),
+ wxT("TAMIL"),
+ wxT("TATAR"),
+ wxT("TELUGU"),
+ wxT("THAI"),
+ wxT("TIBETAN"),
+ wxT("TIGRINYA"),
+ wxT("TONGA"),
+ wxT("TSONGA"),
+ wxT("TURKISH"),
+ wxT("TURKMEN"),
+ wxT("TWI"),
+ wxT("UIGHUR"),
+ wxT("UKRAINIAN"),
+ wxT("URDU"),
+ wxT("URDU_INDIA"),
+ wxT("URDU_PAKISTAN"),
+ wxT("UZBEK"),
+ wxT("UZBEK_CYRILLIC"),
+ wxT("UZBEK_LATIN"),
+ wxT("VIETNAMESE"),
+ wxT("VOLAPUK"),
+ wxT("WELSH"),
+ wxT("WOLOF"),
+ wxT("XHOSA"),
+ wxT("YIDDISH"),
+ wxT("YORUBA"),
+ wxT("ZHUANG"),
+ wxT("ZULU"),
+ };
+
+ if ( (size_t)lang < WXSIZEOF(languageNames) )
+ return languageNames[lang];
+ else
+ return wxT("INVALID");
+}
+
+static void TestDefaultLang()
+{
+ wxPuts(wxT("*** Testing wxLocale::GetSystemLanguage ***"));
+
+ gs_localeDefault.Init(wxLANGUAGE_ENGLISH);
+
+ static const wxChar *langStrings[] =
+ {
+ NULL, // system default
+ wxT("C"),
+ wxT("fr"),
+ wxT("fr_FR"),
+ wxT("en"),
+ wxT("en_GB"),
+ wxT("en_US"),
+ wxT("de_DE.iso88591"),
+ wxT("german"),
+ wxT("?"), // invalid lang spec
+ wxT("klingonese"), // I bet on some systems it does exist...
+ };
+
+ wxPrintf(wxT("The default system encoding is %s (%d)\n"),
+ wxLocale::GetSystemEncodingName().c_str(),
+ wxLocale::GetSystemEncoding());
+
+ for ( size_t n = 0; n < WXSIZEOF(langStrings); n++ )
+ {
+ const wxChar *langStr = langStrings[n];
+ if ( langStr )
+ {
+ // FIXME: this doesn't do anything at all under Windows, we need
+ // to create a new wxLocale!
+ wxSetEnv(wxT("LC_ALL"), langStr);
+ }