Win32 API之Setlocale函式配置地域化資訊函式
setlocale:
函式原形為:char *setlocale( int category, const char *locale );
標頭檔案:<locale.h>
所支援的作業系統為:ANSI, Win 95, Win NT
對於簡體中文可以使用如下設定:setlocale( LC_ALL, "chs" );
函式原形為:char *setlocale( int category, const char *locale );
標頭檔案:<locale.h>
所支援的作業系統為:ANSI, Win 95, Win NT
對於簡體中文可以使用如下設定:setlocale( LC_ALL, "chs" );
為什麼一定要呼叫setlocale呢?
因為在C/C++語言標準中定義了其執行時的字符集環境為"C",也就是ASCII字符集的一個子集,那麼mbstowcs在工作時會將cstr中所包含的字串看作是ASCII編碼的字元,而不認為是一個包含有chs編碼的字串,所以他會將每一箇中文拆成2個ASCII編碼進行轉換,這樣得到的結果就是會形成4個wchar_t的字元組成的串,那麼如何才能夠讓mbstowcs正常工作呢?在呼叫mbstowcs進行轉換之間必須明確的告訴mbstowcs目前cstr串中包含的是chs編碼的字串,通過setlocale( LC_ALL,
"chs" )函式呼叫來完成,需要注意的是這個函式會改變整個應用程式的字符集編碼方式,必須要通過重新呼叫setlocale( LC_ALL, "C" )函式來還原,這樣就可以保證mbstowcs在轉換時將cstr中的串看作是中文串,並且轉換成為2個wchar_t字元,而不是4個。
本地化設定需要具備三個條件:
a.語言程式碼(Language Code)
b.國家程式碼(Country Code)
c.編碼(Encoding)
本地名字可以用下面這些部分來構造:
語言程式碼_國家程式碼.編碼 比如(zh_CN.UTF-8, en_US等)
locale的別名表見/usr/lib/X11/locale/locale.alias(以Debian GNU/Linux為例)
setlocale語言字串參考
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 (Australian) | "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 "frs" |
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" |
Japanese | Japanese | "japanese" 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/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" |
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" |
相關文章
- 常用Win32 API函式簡介Win32API函式
- 函式式API簡介函式API
- 字串函式之Strtok()函式字串函式
- Python 擴充之特殊函式(lambda 函式,map 函式,filter 函式,reduce 函式)Python函式Filter
- Win32 API CreateCompatibleDC 函式的相關應用Win32API函式
- 利用Win32 API 函式 ShowWindowAsync / ShowWindow 改變視窗大小Win32API函式
- Lesson14——NumPy 字串函式之 Par3:字串資訊函式字串函式
- 函式式JavaScript(4):函式柯里化函式JavaScript
- Kotlin 集合函式式ApiKotlin函式API
- 柯里化函式之Javascript函式JavaScript
- ORACLE單行函式與多行函式之七:多行函式之分組函式示例Oracle函式
- 常見函式之單行函式函式
- 【Analytic】分析函式之MIN函式函式
- 【Analytic】分析函式之MAX函式函式
- 【Analytic】分析函式之AVG函式函式
- 【Analytic】分析函式之RANK函式函式
- 【Analytic】分析函式之COUNT函式函式
- ORACLE單行函式與多行函式之四:日期函式示例Oracle函式
- ORACLE單行函式與多行函式之六:通用函式示例Oracle函式
- JS高階函式-函式柯里化JS函式
- Kotlin之“with”函式和“apply”函式Kotlin函式APP
- 常用JS函式-陣列扁平化,快取函式,柯里化函式,防抖和節流函式JS函式陣列快取
- ORACLE單行函式與多行函式之五:轉換函式示例Oracle函式
- ORACLE函式介紹第三篇 著名函式之聚合函式Oracle函式
- MySQL函式大全(字串函式,數學函式,日期函式,系統級函式,聚合函式)MySql函式字串
- Windows API GetUserNameEx 函式使用WindowsAPI函式
- MySQL C API函式大全MySqlAPI函式
- 轉化函式函式
- 【機器學習】【base】 之 目標函式 損失函式 優化演算法機器學習函式優化演算法
- Oracle 函式大全(字串函式,數學函式,日期函式,邏輯運算函式,其他函式)Oracle函式字串
- 【函式式 Swift】函式式思想函式Swift
- 函式柯里化和偏函式應用函式
- ORACLE函式介紹第四篇 非著名函式之聚合函式Oracle函式
- PHP函式漏洞審計之addslashes函式-PHP函式
- 函式的祕密之 函式返回值函式
- 【Spark篇】---SparkSql之UDF函式和UDAF函式SparkSQL函式
- 【Analytic】分析函式之ROW_NUMBER函式函式
- 【Analytic】分析函式之DENSE_RANK函式函式