Setlocale:
Function prototype: char * setlocale (INT category, const char * locale );
Header file: <locale. h>
Supported Operating Systems: ANSI, Win 95, Win NT
You can use the following settings for simplified Chinese: setlocale (lc_all, "CHS ");
Why must I call setlocale?
In the C/C ++ language standard, the runtime Character Set environment is defined as "C", that is, a subset of the ASCII character set, when working, mbstowcs regards the string contained in CSTR as an ASCII character instead of a string containing CHS encoding, therefore, he splits each Chinese character into two ASCII codes for conversion. As a result, a string consisting of four wchar_t characters is formed. How can he make the mbstowcs work properly? You must explicitly tell mbstowcs that the current CSTR string contains a CHS encoded string by calling the mbstowcs command for conversion. You can use setlocale (lc_all,
"CHS") function calls are completed. Note that this function will change the character set encoding method of the entire application. You must call setlocale (lc_all, "C") again ") function to restore the string. This ensures that the string in the CSTR is considered as a Chinese string and converted into two wchar_t characters instead of four.
The localization settings must meet three requirements:
A. Language code B. Country Code)
C. Encoding (encoding)
Local names can be constructed using the following parts: language code _ country code. Code such as (zh_CN.UTF-8, en_us, etc)
For the alias table of locale, see/usr/lib/X11/locale. Alias (Debian GNU/Linux is used as an example)
Setlocale language string reference
Primary Language |
Sublanguage |
Language string |
Chinese |
Chinese |
"Chinese" |
Chinese |
Chinese (simplified) |
"Chinese-simplified" or "CHS" |
Chinese |
Chinese (traditional) |
"Chinese-traditional" or "CHT" |
Czech |
Czech |
"CSY" or "Czech" |
Danish |
Danish |
"Dan" or "Danish" |
Dutch |
Dutch (default) |
"Dutch" or "NLD" |
Dutch |
Dutch (Belgian) |
"Belgian", "Dutch-Belgian", or "NLB" |
English |
English (default) |
"English" |
English |
English (English) |
"Australian", "ENA", or "English-Aus" |
English |
English (Canadian) |
"Canadian", "ENC", or "English-can" |
English |
English (New Zealand) |
"English-NZ" or "enz" |
English |
English (United Kingdom) |
"Eng", "English-uk", or "UK" |
English |
English (United States) |
"American", "American English", "American-English", "English-American", "English-us", "English-USA", "enu ", "Us", or "USA" |
Finnish |
Finnish |
"Fin" or "Finnish" |
French |
French (default) |
"FRA" or "French" |
French |
French (Belgian) |
"FRB" or "French-Belgian" |
French |
French (Canadian) |
"FRC" or "French-Canadian" |
French |
French (Swiss) |
"French-Swiss" or "FR" |
German |
German (default) |
"DEU" or "German" |
German |
German (Austrian) |
"Dea" or "German-Austrian" |
German |
German (Swiss) |
"Des", "German-Swiss", or "Swiss" |
Greek |
Greek |
"Ell" or "Greek" |
Hungarian |
Hungarian |
"Hun" or "Hungarian" |
Icelandic |
Icelandic |
"Icelandic" or "isl" |
Italian |
Italian (default) |
"Ita" or "Italian" |
Italian |
Italian (Swiss) |
"Italian-Swiss" or "its" |
Japan |
Japan |
"Japan" or "JPN" |
Korean |
Korean |
"Kor" or "Korean" |
Norwegian |
Norwegian (default) |
"Norwegian" |
Norwegian |
Norwegian (bokmal) |
"Nor" or "Norwegian-bokmal" |
Norwegian |
Norwegian (nynorsk) |
"Non" or "Norwegian-nynorsk" |
Polish |
Polish |
"PLK" or "polish" |
Portuguese |
Portuguese (default) |
"Portuguese" or "PTG" |
Portuguese |
Portuguese (Brazilian) |
"Portuguese-Brazil" or "PTB" |
Russian |
Russian (default) |
"Rus" or "Russian" |
Slovak |
Slovak |
"Sky" or "Slovak" |
Spanish |
Spanish (default) |
"Esp" or "Spanish" |
Spanish |
Spanish (Mexican) |
"ESM" or "Spanish-Mexican" |
Spanish |
Spanish (modern) |
"ESN" or "Spanish-modern" |
Swedish |
Swedish |
"SVE" or "Swedish" |
Turkish |
Turkish |
"TRK" or "Turkish" |
Setlocale country string reference
Country/region |
Country/region string |
Australia |
"Aus" or "Australia" |
Austria |
"Aut" or "Austria" |
Belgium |
"BEL" or "Belgium" |
Brazil |
"Bra" or "Brazil" |
Canada |
"Can" or "Canada" |
China |
"China", "CHN", "PR China", or "PR-China" |
Czech Republic |
"CZE" or "Czech" |
Denmark |
"DNK" or "Denmark" |
Finland |
"Fin" or "Finland" |
France |
"FRA" or "France" |
Germany |
"DEU" or "Germany" |
Greece |
"GRC" or "Greece" |
Hong Kong SAR |
"HKG", "Hong Kong", or "Hong-Kong" |
Hungary |
"Hun" or "Hungary" |
Iceland |
"Iceland" or "isl" |
Ireland |
"IRL" or "Ireland" |
Italy |
"Ita" or "Italy" |
Japan |
"JPN" or "Japan" |
Korea |
"Kor" or "Korea" |
Mexico |
"Mex" or "Mexico ICO" |
The Netherlands |
"NLD", "Holland", or "Netherlands" |
New Zealand |
"NZL", "New Zealand", "New-Zealand", or "nz" |
Norway |
"Nor" or "Norway" |
Poland |
"Pol" or "Poland" |
Portugal |
"PRT" or "Portugal" |
Russia |
"Rus" or "Russia" |
Singapore |
"SGP" or "Singapore" |
Slovakia |
"SVK" or "Slovak" |
Spain |
"Esp" or "Spain" |
Sweden |
"SWE" or "Sweden" |
Switzerland |
"Che" or "Switzerland" |
Taiwan |
"TWN" or "Taiwan" |
Turkey |
"Tur" or "turkey" |
United Kingdom |
"GBR", "Britain", "England", "Great Britain", "UK", "United Kingdom", or "united-kingdom" |
United States |
"USA", "America", "United States", "United-States", or "us" |