localename.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772
  1. /* Determine the current selected locale.
  2. Copyright (C) 1995-1999, 2000-2002 Free Software Foundation, Inc.
  3. This program is free software; you can redistribute it and/or modify it
  4. under the terms of the GNU Library General Public License as published
  5. by the Free Software Foundation; either version 2, or (at your option)
  6. any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10. Library General Public License for more details.
  11. You should have received a copy of the GNU Library General Public
  12. License along with this program; if not, write to the Free Software
  13. Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301,
  14. USA. */
  15. /* Written by Ulrich Drepper <drepper@gnu.org>, 1995. */
  16. /* Win32 code written by Tor Lillqvist <tml@iki.fi>. */
  17. #ifdef HAVE_CONFIG_H
  18. # include <config.h>
  19. #endif
  20. #include <stdlib.h>
  21. #include <locale.h>
  22. #if defined _WIN32 || defined __WIN32__
  23. # undef WIN32 /* avoid warning on mingw32 */
  24. # define WIN32
  25. #endif
  26. #ifdef WIN32
  27. # define WIN32_LEAN_AND_MEAN
  28. # include <windows.h>
  29. /* Mingw headers don't have latest language and sublanguage codes. */
  30. # ifndef LANG_AFRIKAANS
  31. # define LANG_AFRIKAANS 0x36
  32. # endif
  33. # ifndef LANG_ALBANIAN
  34. # define LANG_ALBANIAN 0x1c
  35. # endif
  36. # ifndef LANG_ARABIC
  37. # define LANG_ARABIC 0x01
  38. # endif
  39. # ifndef LANG_ARMENIAN
  40. # define LANG_ARMENIAN 0x2b
  41. # endif
  42. # ifndef LANG_ASSAMESE
  43. # define LANG_ASSAMESE 0x4d
  44. # endif
  45. # ifndef LANG_AZERI
  46. # define LANG_AZERI 0x2c
  47. # endif
  48. # ifndef LANG_BASQUE
  49. # define LANG_BASQUE 0x2d
  50. # endif
  51. # ifndef LANG_BELARUSIAN
  52. # define LANG_BELARUSIAN 0x23
  53. # endif
  54. # ifndef LANG_BENGALI
  55. # define LANG_BENGALI 0x45
  56. # endif
  57. # ifndef LANG_CATALAN
  58. # define LANG_CATALAN 0x03
  59. # endif
  60. # ifndef LANG_DIVEHI
  61. # define LANG_DIVEHI 0x65
  62. # endif
  63. # ifndef LANG_ESTONIAN
  64. # define LANG_ESTONIAN 0x25
  65. # endif
  66. # ifndef LANG_FAEROESE
  67. # define LANG_FAEROESE 0x38
  68. # endif
  69. # ifndef LANG_FARSI
  70. # define LANG_FARSI 0x29
  71. # endif
  72. # ifndef LANG_GALICIAN
  73. # define LANG_GALICIAN 0x56
  74. # endif
  75. # ifndef LANG_GEORGIAN
  76. # define LANG_GEORGIAN 0x37
  77. # endif
  78. # ifndef LANG_GUJARATI
  79. # define LANG_GUJARATI 0x47
  80. # endif
  81. # ifndef LANG_HEBREW
  82. # define LANG_HEBREW 0x0d
  83. # endif
  84. # ifndef LANG_HINDI
  85. # define LANG_HINDI 0x39
  86. # endif
  87. # ifndef LANG_INDONESIAN
  88. # define LANG_INDONESIAN 0x21
  89. # endif
  90. # ifndef LANG_KANNADA
  91. # define LANG_KANNADA 0x4b
  92. # endif
  93. # ifndef LANG_KASHMIRI
  94. # define LANG_KASHMIRI 0x60
  95. # endif
  96. # ifndef LANG_KAZAK
  97. # define LANG_KAZAK 0x3f
  98. # endif
  99. # ifndef LANG_KONKANI
  100. # define LANG_KONKANI 0x57
  101. # endif
  102. # ifndef LANG_KYRGYZ
  103. # define LANG_KYRGYZ 0x40
  104. # endif
  105. # ifndef LANG_LATVIAN
  106. # define LANG_LATVIAN 0x26
  107. # endif
  108. # ifndef LANG_LITHUANIAN
  109. # define LANG_LITHUANIAN 0x27
  110. # endif
  111. # ifndef LANG_MACEDONIAN
  112. # define LANG_MACEDONIAN 0x2f
  113. # endif
  114. # ifndef LANG_MALAY
  115. # define LANG_MALAY 0x3e
  116. # endif
  117. # ifndef LANG_MALAYALAM
  118. # define LANG_MALAYALAM 0x4c
  119. # endif
  120. # ifndef LANG_MANIPURI
  121. # define LANG_MANIPURI 0x58
  122. # endif
  123. # ifndef LANG_MARATHI
  124. # define LANG_MARATHI 0x4e
  125. # endif
  126. # ifndef LANG_MONGOLIAN
  127. # define LANG_MONGOLIAN 0x50
  128. # endif
  129. # ifndef LANG_NEPALI
  130. # define LANG_NEPALI 0x61
  131. # endif
  132. # ifndef LANG_ORIYA
  133. # define LANG_ORIYA 0x48
  134. # endif
  135. # ifndef LANG_PUNJABI
  136. # define LANG_PUNJABI 0x46
  137. # endif
  138. # ifndef LANG_SANSKRIT
  139. # define LANG_SANSKRIT 0x4f
  140. # endif
  141. # ifndef LANG_SERBIAN
  142. # define LANG_SERBIAN 0x1a
  143. # endif
  144. # ifndef LANG_SINDHI
  145. # define LANG_SINDHI 0x59
  146. # endif
  147. # ifndef LANG_SLOVAK
  148. # define LANG_SLOVAK 0x1b
  149. # endif
  150. # ifndef LANG_SORBIAN
  151. # define LANG_SORBIAN 0x2e
  152. # endif
  153. # ifndef LANG_SWAHILI
  154. # define LANG_SWAHILI 0x41
  155. # endif
  156. # ifndef LANG_SYRIAC
  157. # define LANG_SYRIAC 0x5a
  158. # endif
  159. # ifndef LANG_TAMIL
  160. # define LANG_TAMIL 0x49
  161. # endif
  162. # ifndef LANG_TATAR
  163. # define LANG_TATAR 0x44
  164. # endif
  165. # ifndef LANG_TELUGU
  166. # define LANG_TELUGU 0x4a
  167. # endif
  168. # ifndef LANG_THAI
  169. # define LANG_THAI 0x1e
  170. # endif
  171. # ifndef LANG_UKRAINIAN
  172. # define LANG_UKRAINIAN 0x22
  173. # endif
  174. # ifndef LANG_URDU
  175. # define LANG_URDU 0x20
  176. # endif
  177. # ifndef LANG_UZBEK
  178. # define LANG_UZBEK 0x43
  179. # endif
  180. # ifndef LANG_VIETNAMESE
  181. # define LANG_VIETNAMESE 0x2a
  182. # endif
  183. # ifndef SUBLANG_ARABIC_SAUDI_ARABIA
  184. # define SUBLANG_ARABIC_SAUDI_ARABIA 0x01
  185. # endif
  186. # ifndef SUBLANG_ARABIC_IRAQ
  187. # define SUBLANG_ARABIC_IRAQ 0x02
  188. # endif
  189. # ifndef SUBLANG_ARABIC_EGYPT
  190. # define SUBLANG_ARABIC_EGYPT 0x03
  191. # endif
  192. # ifndef SUBLANG_ARABIC_LIBYA
  193. # define SUBLANG_ARABIC_LIBYA 0x04
  194. # endif
  195. # ifndef SUBLANG_ARABIC_ALGERIA
  196. # define SUBLANG_ARABIC_ALGERIA 0x05
  197. # endif
  198. # ifndef SUBLANG_ARABIC_MOROCCO
  199. # define SUBLANG_ARABIC_MOROCCO 0x06
  200. # endif
  201. # ifndef SUBLANG_ARABIC_TUNISIA
  202. # define SUBLANG_ARABIC_TUNISIA 0x07
  203. # endif
  204. # ifndef SUBLANG_ARABIC_OMAN
  205. # define SUBLANG_ARABIC_OMAN 0x08
  206. # endif
  207. # ifndef SUBLANG_ARABIC_YEMEN
  208. # define SUBLANG_ARABIC_YEMEN 0x09
  209. # endif
  210. # ifndef SUBLANG_ARABIC_SYRIA
  211. # define SUBLANG_ARABIC_SYRIA 0x0a
  212. # endif
  213. # ifndef SUBLANG_ARABIC_JORDAN
  214. # define SUBLANG_ARABIC_JORDAN 0x0b
  215. # endif
  216. # ifndef SUBLANG_ARABIC_LEBANON
  217. # define SUBLANG_ARABIC_LEBANON 0x0c
  218. # endif
  219. # ifndef SUBLANG_ARABIC_KUWAIT
  220. # define SUBLANG_ARABIC_KUWAIT 0x0d
  221. # endif
  222. # ifndef SUBLANG_ARABIC_UAE
  223. # define SUBLANG_ARABIC_UAE 0x0e
  224. # endif
  225. # ifndef SUBLANG_ARABIC_BAHRAIN
  226. # define SUBLANG_ARABIC_BAHRAIN 0x0f
  227. # endif
  228. # ifndef SUBLANG_ARABIC_QATAR
  229. # define SUBLANG_ARABIC_QATAR 0x10
  230. # endif
  231. # ifndef SUBLANG_AZERI_LATIN
  232. # define SUBLANG_AZERI_LATIN 0x01
  233. # endif
  234. # ifndef SUBLANG_AZERI_CYRILLIC
  235. # define SUBLANG_AZERI_CYRILLIC 0x02
  236. # endif
  237. # ifndef SUBLANG_CHINESE_MACAU
  238. # define SUBLANG_CHINESE_MACAU 0x05
  239. # endif
  240. # ifndef SUBLANG_ENGLISH_SOUTH_AFRICA
  241. # define SUBLANG_ENGLISH_SOUTH_AFRICA 0x07
  242. # endif
  243. # ifndef SUBLANG_ENGLISH_JAMAICA
  244. # define SUBLANG_ENGLISH_JAMAICA 0x08
  245. # endif
  246. # ifndef SUBLANG_ENGLISH_CARIBBEAN
  247. # define SUBLANG_ENGLISH_CARIBBEAN 0x09
  248. # endif
  249. # ifndef SUBLANG_ENGLISH_BELIZE
  250. # define SUBLANG_ENGLISH_BELIZE 0x0a
  251. # endif
  252. # ifndef SUBLANG_ENGLISH_TRINIDAD
  253. # define SUBLANG_ENGLISH_TRINIDAD 0x0b
  254. # endif
  255. # ifndef SUBLANG_ENGLISH_ZIMBABWE
  256. # define SUBLANG_ENGLISH_ZIMBABWE 0x0c
  257. # endif
  258. # ifndef SUBLANG_ENGLISH_PHILIPPINES
  259. # define SUBLANG_ENGLISH_PHILIPPINES 0x0d
  260. # endif
  261. # ifndef SUBLANG_FRENCH_LUXEMBOURG
  262. # define SUBLANG_FRENCH_LUXEMBOURG 0x05
  263. # endif
  264. # ifndef SUBLANG_FRENCH_MONACO
  265. # define SUBLANG_FRENCH_MONACO 0x06
  266. # endif
  267. # ifndef SUBLANG_GERMAN_LUXEMBOURG
  268. # define SUBLANG_GERMAN_LUXEMBOURG 0x04
  269. # endif
  270. # ifndef SUBLANG_GERMAN_LIECHTENSTEIN
  271. # define SUBLANG_GERMAN_LIECHTENSTEIN 0x05
  272. # endif
  273. # ifndef SUBLANG_KASHMIRI_INDIA
  274. # define SUBLANG_KASHMIRI_INDIA 0x02
  275. # endif
  276. # ifndef SUBLANG_MALAY_MALAYSIA
  277. # define SUBLANG_MALAY_MALAYSIA 0x01
  278. # endif
  279. # ifndef SUBLANG_MALAY_BRUNEI_DARUSSALAM
  280. # define SUBLANG_MALAY_BRUNEI_DARUSSALAM 0x02
  281. # endif
  282. # ifndef SUBLANG_NEPALI_INDIA
  283. # define SUBLANG_NEPALI_INDIA 0x02
  284. # endif
  285. # ifndef SUBLANG_SERBIAN_LATIN
  286. # define SUBLANG_SERBIAN_LATIN 0x02
  287. # endif
  288. # ifndef SUBLANG_SERBIAN_CYRILLIC
  289. # define SUBLANG_SERBIAN_CYRILLIC 0x03
  290. # endif
  291. # ifndef SUBLANG_SPANISH_GUATEMALA
  292. # define SUBLANG_SPANISH_GUATEMALA 0x04
  293. # endif
  294. # ifndef SUBLANG_SPANISH_COSTA_RICA
  295. # define SUBLANG_SPANISH_COSTA_RICA 0x05
  296. # endif
  297. # ifndef SUBLANG_SPANISH_PANAMA
  298. # define SUBLANG_SPANISH_PANAMA 0x06
  299. # endif
  300. # ifndef SUBLANG_SPANISH_DOMINICAN_REPUBLIC
  301. # define SUBLANG_SPANISH_DOMINICAN_REPUBLIC 0x07
  302. # endif
  303. # ifndef SUBLANG_SPANISH_VENEZUELA
  304. # define SUBLANG_SPANISH_VENEZUELA 0x08
  305. # endif
  306. # ifndef SUBLANG_SPANISH_COLOMBIA
  307. # define SUBLANG_SPANISH_COLOMBIA 0x09
  308. # endif
  309. # ifndef SUBLANG_SPANISH_PERU
  310. # define SUBLANG_SPANISH_PERU 0x0a
  311. # endif
  312. # ifndef SUBLANG_SPANISH_ARGENTINA
  313. # define SUBLANG_SPANISH_ARGENTINA 0x0b
  314. # endif
  315. # ifndef SUBLANG_SPANISH_ECUADOR
  316. # define SUBLANG_SPANISH_ECUADOR 0x0c
  317. # endif
  318. # ifndef SUBLANG_SPANISH_CHILE
  319. # define SUBLANG_SPANISH_CHILE 0x0d
  320. # endif
  321. # ifndef SUBLANG_SPANISH_URUGUAY
  322. # define SUBLANG_SPANISH_URUGUAY 0x0e
  323. # endif
  324. # ifndef SUBLANG_SPANISH_PARAGUAY
  325. # define SUBLANG_SPANISH_PARAGUAY 0x0f
  326. # endif
  327. # ifndef SUBLANG_SPANISH_BOLIVIA
  328. # define SUBLANG_SPANISH_BOLIVIA 0x10
  329. # endif
  330. # ifndef SUBLANG_SPANISH_EL_SALVADOR
  331. # define SUBLANG_SPANISH_EL_SALVADOR 0x11
  332. # endif
  333. # ifndef SUBLANG_SPANISH_HONDURAS
  334. # define SUBLANG_SPANISH_HONDURAS 0x12
  335. # endif
  336. # ifndef SUBLANG_SPANISH_NICARAGUA
  337. # define SUBLANG_SPANISH_NICARAGUA 0x13
  338. # endif
  339. # ifndef SUBLANG_SPANISH_PUERTO_RICO
  340. # define SUBLANG_SPANISH_PUERTO_RICO 0x14
  341. # endif
  342. # ifndef SUBLANG_SWEDISH_FINLAND
  343. # define SUBLANG_SWEDISH_FINLAND 0x02
  344. # endif
  345. # ifndef SUBLANG_URDU_PAKISTAN
  346. # define SUBLANG_URDU_PAKISTAN 0x01
  347. # endif
  348. # ifndef SUBLANG_URDU_INDIA
  349. # define SUBLANG_URDU_INDIA 0x02
  350. # endif
  351. # ifndef SUBLANG_UZBEK_LATIN
  352. # define SUBLANG_UZBEK_LATIN 0x01
  353. # endif
  354. # ifndef SUBLANG_UZBEK_CYRILLIC
  355. # define SUBLANG_UZBEK_CYRILLIC 0x02
  356. # endif
  357. #endif
  358. /* XPG3 defines the result of 'setlocale (category, NULL)' as:
  359. "Directs 'setlocale()' to query 'category' and return the current
  360. setting of 'local'."
  361. However it does not specify the exact format. Neither do SUSV2 and
  362. ISO C 99. So we can use this feature only on selected systems (e.g.
  363. those using GNU C Library). */
  364. #if defined _LIBC || (defined __GNU_LIBRARY__ && __GNU_LIBRARY__ >= 2)
  365. # define HAVE_LOCALE_NULL
  366. #endif
  367. /* Determine the current locale's name, and canonicalize it into XPG syntax
  368. language[_territory[.codeset]][@modifier]
  369. The codeset part in the result is not reliable; the locale_charset()
  370. should be used for codeset information instead.
  371. The result must not be freed; it is statically allocated. */
  372. const char *
  373. _nl_locale_name (category, categoryname)
  374. int category;
  375. const char *categoryname;
  376. {
  377. const char *retval;
  378. #ifndef WIN32
  379. /* Use the POSIX methods of looking to 'LC_ALL', 'LC_xxx', and 'LANG'.
  380. On some systems this can be done by the 'setlocale' function itself. */
  381. # if defined HAVE_SETLOCALE && defined HAVE_LC_MESSAGES && defined HAVE_LOCALE_NULL
  382. retval = setlocale (category, NULL);
  383. # else
  384. /* Setting of LC_ALL overwrites all other. */
  385. retval = getenv ("LC_ALL");
  386. if (retval == NULL || retval[0] == '\0')
  387. {
  388. /* Next comes the name of the desired category. */
  389. retval = getenv (categoryname);
  390. if (retval == NULL || retval[0] == '\0')
  391. {
  392. /* Last possibility is the LANG environment variable. */
  393. retval = getenv ("LANG");
  394. if (retval == NULL || retval[0] == '\0')
  395. /* We use C as the default domain. POSIX says this is
  396. implementation defined. */
  397. retval = "C";
  398. }
  399. }
  400. # endif
  401. return retval;
  402. #else /* WIN32 */
  403. /* Return an XPG style locale name language[_territory][@modifier].
  404. Don't even bother determining the codeset; it's not useful in this
  405. context, because message catalogs are not specific to a single
  406. codeset. */
  407. LCID lcid;
  408. LANGID langid;
  409. int primary, sub;
  410. /* Let the user override the system settings through environment
  411. variables, as on POSIX systems. */
  412. retval = getenv ("LC_ALL");
  413. if (retval != NULL && retval[0] != '\0')
  414. return retval;
  415. retval = getenv (categoryname);
  416. if (retval != NULL && retval[0] != '\0')
  417. return retval;
  418. retval = getenv ("LANG");
  419. if (retval != NULL && retval[0] != '\0')
  420. return retval;
  421. /* Use native Win32 API locale ID. */
  422. lcid = GetThreadLocale ();
  423. /* Strip off the sorting rules, keep only the language part. */
  424. langid = LANGIDFROMLCID (lcid);
  425. /* Split into language and territory part. */
  426. primary = PRIMARYLANGID (langid);
  427. sub = SUBLANGID (langid);
  428. /* Dispatch on language.
  429. See also http://www.unicode.org/unicode/onlinedat/languages.html .
  430. For details about languages, see http://www.ethnologue.com/ . */
  431. switch (primary)
  432. {
  433. case LANG_AFRIKAANS: return "af_ZA";
  434. case LANG_ALBANIAN: return "sq_AL";
  435. case 0x5e: /* AMHARIC */ return "am_ET";
  436. case LANG_ARABIC:
  437. switch (sub)
  438. {
  439. case SUBLANG_ARABIC_SAUDI_ARABIA: return "ar_SA";
  440. case SUBLANG_ARABIC_IRAQ: return "ar_IQ";
  441. case SUBLANG_ARABIC_EGYPT: return "ar_EG";
  442. case SUBLANG_ARABIC_LIBYA: return "ar_LY";
  443. case SUBLANG_ARABIC_ALGERIA: return "ar_DZ";
  444. case SUBLANG_ARABIC_MOROCCO: return "ar_MA";
  445. case SUBLANG_ARABIC_TUNISIA: return "ar_TN";
  446. case SUBLANG_ARABIC_OMAN: return "ar_OM";
  447. case SUBLANG_ARABIC_YEMEN: return "ar_YE";
  448. case SUBLANG_ARABIC_SYRIA: return "ar_SY";
  449. case SUBLANG_ARABIC_JORDAN: return "ar_JO";
  450. case SUBLANG_ARABIC_LEBANON: return "ar_LB";
  451. case SUBLANG_ARABIC_KUWAIT: return "ar_KW";
  452. case SUBLANG_ARABIC_UAE: return "ar_AE";
  453. case SUBLANG_ARABIC_BAHRAIN: return "ar_BH";
  454. case SUBLANG_ARABIC_QATAR: return "ar_QA";
  455. }
  456. return "ar";
  457. case LANG_ARMENIAN: return "hy_AM";
  458. case LANG_ASSAMESE: return "as_IN";
  459. case LANG_AZERI:
  460. switch (sub)
  461. {
  462. /* FIXME: Adjust this when Azerbaijani locales appear on Unix. */
  463. case SUBLANG_AZERI_LATIN: return "az_AZ@latin";
  464. case SUBLANG_AZERI_CYRILLIC: return "az_AZ@cyrillic";
  465. }
  466. return "az";
  467. case LANG_BASQUE:
  468. return "eu"; /* Ambiguous: could be "eu_ES" or "eu_FR". */
  469. case LANG_BELARUSIAN: return "be_BY";
  470. case LANG_BENGALI: return "bn_IN";
  471. case LANG_BULGARIAN: return "bg_BG";
  472. case 0x55: /* BURMESE */ return "my_MM";
  473. case 0x53: /* CAMBODIAN */ return "km_KH";
  474. case LANG_CATALAN: return "ca_ES";
  475. case 0x5c: /* CHEROKEE */ return "chr_US";
  476. case LANG_CHINESE:
  477. switch (sub)
  478. {
  479. case SUBLANG_CHINESE_TRADITIONAL: return "zh_TW";
  480. case SUBLANG_CHINESE_SIMPLIFIED: return "zh_CN";
  481. case SUBLANG_CHINESE_HONGKONG: return "zh_HK";
  482. case SUBLANG_CHINESE_SINGAPORE: return "zh_SG";
  483. case SUBLANG_CHINESE_MACAU: return "zh_MO";
  484. }
  485. return "zh";
  486. case LANG_CROATIAN: /* LANG_CROATIAN == LANG_SERBIAN
  487. * What used to be called Serbo-Croatian
  488. * should really now be two separate
  489. * languages because of political reasons.
  490. * (Says tml, who knows nothing about Serbian
  491. * or Croatian.)
  492. * (I can feel those flames coming already.)
  493. */
  494. switch (sub)
  495. {
  496. case SUBLANG_DEFAULT: return "hr_HR";
  497. case SUBLANG_SERBIAN_LATIN: return "sr_YU";
  498. case SUBLANG_SERBIAN_CYRILLIC: return "sr_YU@cyrillic";
  499. }
  500. return "hr";
  501. case LANG_CZECH: return "cs_CZ";
  502. case LANG_DANISH: return "da_DK";
  503. case LANG_DIVEHI: return "div_MV";
  504. case LANG_DUTCH:
  505. switch (sub)
  506. {
  507. case SUBLANG_DUTCH: return "nl_NL";
  508. case SUBLANG_DUTCH_BELGIAN: /* FLEMISH, VLAAMS */ return "nl_BE";
  509. }
  510. return "nl";
  511. case 0x66: /* EDO */ return "bin_NG";
  512. case LANG_ENGLISH:
  513. switch (sub)
  514. {
  515. /* SUBLANG_ENGLISH_US == SUBLANG_DEFAULT. Heh. I thought
  516. * English was the language spoken in England.
  517. * Oh well.
  518. */
  519. case SUBLANG_ENGLISH_US: return "en_US";
  520. case SUBLANG_ENGLISH_UK: return "en_GB";
  521. case SUBLANG_ENGLISH_AUS: return "en_AU";
  522. case SUBLANG_ENGLISH_CAN: return "en_CA";
  523. case SUBLANG_ENGLISH_NZ: return "en_NZ";
  524. case SUBLANG_ENGLISH_EIRE: return "en_IE";
  525. case SUBLANG_ENGLISH_SOUTH_AFRICA: return "en_ZA";
  526. case SUBLANG_ENGLISH_JAMAICA: return "en_JM";
  527. case SUBLANG_ENGLISH_CARIBBEAN: return "en_GD"; /* Grenada? */
  528. case SUBLANG_ENGLISH_BELIZE: return "en_BZ";
  529. case SUBLANG_ENGLISH_TRINIDAD: return "en_TT";
  530. case SUBLANG_ENGLISH_ZIMBABWE: return "en_ZW";
  531. case SUBLANG_ENGLISH_PHILIPPINES: return "en_PH";
  532. }
  533. return "en";
  534. case LANG_ESTONIAN: return "et_EE";
  535. case LANG_FAEROESE: return "fo_FO";
  536. case LANG_FARSI: return "fa_IR";
  537. case LANG_FINNISH: return "fi_FI";
  538. case LANG_FRENCH:
  539. switch (sub)
  540. {
  541. case SUBLANG_FRENCH: return "fr_FR";
  542. case SUBLANG_FRENCH_BELGIAN: /* WALLOON */ return "fr_BE";
  543. case SUBLANG_FRENCH_CANADIAN: return "fr_CA";
  544. case SUBLANG_FRENCH_SWISS: return "fr_CH";
  545. case SUBLANG_FRENCH_LUXEMBOURG: return "fr_LU";
  546. case SUBLANG_FRENCH_MONACO: return "fr_MC";
  547. }
  548. return "fr";
  549. case 0x62: /* FRISIAN */ return "fy_NL";
  550. case 0x67: /* FULFULDE */ return "ful_NG";
  551. case 0x3c: /* GAELIC */
  552. switch (sub)
  553. {
  554. case 0x01: /* SCOTTISH */ return "gd_GB";
  555. case 0x02: /* IRISH */ return "ga_IE";
  556. }
  557. return "C";
  558. case LANG_GALICIAN: return "gl_ES";
  559. case LANG_GEORGIAN: return "ka_GE";
  560. case LANG_GERMAN:
  561. switch (sub)
  562. {
  563. case SUBLANG_GERMAN: return "de_DE";
  564. case SUBLANG_GERMAN_SWISS: return "de_CH";
  565. case SUBLANG_GERMAN_AUSTRIAN: return "de_AT";
  566. case SUBLANG_GERMAN_LUXEMBOURG: return "de_LU";
  567. case SUBLANG_GERMAN_LIECHTENSTEIN: return "de_LI";
  568. }
  569. return "de";
  570. case LANG_GREEK: return "el_GR";
  571. case 0x74: /* GUARANI */ return "gn_PY";
  572. case LANG_GUJARATI: return "gu_IN";
  573. case 0x68: /* HAUSA */ return "ha_NG";
  574. case 0x75: /* HAWAIIAN */
  575. /* FIXME: Do they mean Hawaiian ("haw_US", 1000 speakers)
  576. or Hawaii Creole English ("cpe_US", 600000 speakers)? */
  577. return "cpe_US";
  578. case LANG_HEBREW: return "he_IL";
  579. case LANG_HINDI: return "hi_IN";
  580. case LANG_HUNGARIAN: return "hu_HU";
  581. case 0x69: /* IBIBIO */ return "nic_NG";
  582. case LANG_ICELANDIC: return "is_IS";
  583. case 0x70: /* IGBO */ return "ibo_NG";
  584. case LANG_INDONESIAN: return "id_ID";
  585. case 0x5d: /* INUKTITUT */ return "iu_CA";
  586. case LANG_ITALIAN:
  587. switch (sub)
  588. {
  589. case SUBLANG_ITALIAN: return "it_IT";
  590. case SUBLANG_ITALIAN_SWISS: return "it_CH";
  591. }
  592. return "it";
  593. case LANG_JAPANESE: return "ja_JP";
  594. case LANG_KANNADA: return "kn_IN";
  595. case 0x71: /* KANURI */ return "kau_NG";
  596. case LANG_KASHMIRI:
  597. switch (sub)
  598. {
  599. case SUBLANG_DEFAULT: return "ks_PK";
  600. case SUBLANG_KASHMIRI_INDIA: return "ks_IN";
  601. }
  602. return "ks";
  603. case LANG_KAZAK: return "kk_KZ";
  604. case LANG_KONKANI:
  605. /* FIXME: Adjust this when such locales appear on Unix. */
  606. return "kok_IN";
  607. case LANG_KOREAN: return "ko_KR";
  608. case LANG_KYRGYZ: return "ky_KG";
  609. case 0x54: /* LAO */ return "lo_LA";
  610. case 0x76: /* LATIN */ return "la_VA";
  611. case LANG_LATVIAN: return "lv_LV";
  612. case LANG_LITHUANIAN: return "lt_LT";
  613. case LANG_MACEDONIAN: return "mk_MK";
  614. case LANG_MALAY:
  615. switch (sub)
  616. {
  617. case SUBLANG_MALAY_MALAYSIA: return "ms_MY";
  618. case SUBLANG_MALAY_BRUNEI_DARUSSALAM: return "ms_BN";
  619. }
  620. return "ms";
  621. case LANG_MALAYALAM: return "ml_IN";
  622. case 0x3a: /* MALTESE */ return "mt_MT";
  623. case LANG_MANIPURI:
  624. /* FIXME: Adjust this when such locales appear on Unix. */
  625. return "mni_IN";
  626. case LANG_MARATHI: return "mr_IN";
  627. case LANG_MONGOLIAN:
  628. return "mn"; /* Ambiguous: could be "mn_CN" or "mn_MN". */
  629. case LANG_NEPALI:
  630. switch (sub)
  631. {
  632. case SUBLANG_DEFAULT: return "ne_NP";
  633. case SUBLANG_NEPALI_INDIA: return "ne_IN";
  634. }
  635. return "ne";
  636. case LANG_NORWEGIAN:
  637. switch (sub)
  638. {
  639. case SUBLANG_NORWEGIAN_BOKMAL: return "no_NO";
  640. case SUBLANG_NORWEGIAN_NYNORSK: return "nn_NO";
  641. }
  642. return "no";
  643. case LANG_ORIYA: return "or_IN";
  644. case 0x72: /* OROMO */ return "om_ET";
  645. case 0x79: /* PAPIAMENTU */ return "pap_AN";
  646. case 0x63: /* PASHTO */
  647. return "ps"; /* Ambiguous: could be "ps_PK" or "ps_AF". */
  648. case LANG_POLISH: return "pl_PL";
  649. case LANG_PORTUGUESE:
  650. switch (sub)
  651. {
  652. case SUBLANG_PORTUGUESE: return "pt_PT";
  653. /* Hmm. SUBLANG_PORTUGUESE_BRAZILIAN == SUBLANG_DEFAULT.
  654. Same phenomenon as SUBLANG_ENGLISH_US == SUBLANG_DEFAULT. */
  655. case SUBLANG_PORTUGUESE_BRAZILIAN: return "pt_BR";
  656. }
  657. return "pt";
  658. case LANG_PUNJABI: return "pa_IN";
  659. case 0x17: /* RHAETO-ROMANCE */ return "rm_CH";
  660. case LANG_ROMANIAN: return "ro_RO";
  661. case LANG_RUSSIAN:
  662. return "ru"; /* Ambiguous: could be "ru_RU" or "ru_UA". */
  663. case 0x3b: /* SAMI */ return "se_NO";
  664. case LANG_SANSKRIT: return "sa_IN";
  665. case LANG_SINDHI: return "sd";
  666. case 0x5b: /* SINHALESE */ return "si_LK";
  667. case LANG_SLOVAK: return "sk_SK";
  668. case LANG_SLOVENIAN: return "sl_SI";
  669. case 0x77: /* SOMALI */ return "so_SO";
  670. case LANG_SORBIAN:
  671. /* FIXME: Adjust this when such locales appear on Unix. */
  672. return "wen_DE";
  673. case LANG_SPANISH:
  674. switch (sub)
  675. {
  676. case SUBLANG_SPANISH: return "es_ES";
  677. case SUBLANG_SPANISH_MEXICAN: return "es_MX";
  678. case SUBLANG_SPANISH_MODERN:
  679. return "es_ES@modern"; /* not seen on Unix */
  680. case SUBLANG_SPANISH_GUATEMALA: return "es_GT";
  681. case SUBLANG_SPANISH_COSTA_RICA: return "es_CR";
  682. case SUBLANG_SPANISH_PANAMA: return "es_PA";
  683. case SUBLANG_SPANISH_DOMINICAN_REPUBLIC: return "es_DO";
  684. case SUBLANG_SPANISH_VENEZUELA: return "es_VE";
  685. case SUBLANG_SPANISH_COLOMBIA: return "es_CO";
  686. case SUBLANG_SPANISH_PERU: return "es_PE";
  687. case SUBLANG_SPANISH_ARGENTINA: return "es_AR";
  688. case SUBLANG_SPANISH_ECUADOR: return "es_EC";
  689. case SUBLANG_SPANISH_CHILE: return "es_CL";
  690. case SUBLANG_SPANISH_URUGUAY: return "es_UY";
  691. case SUBLANG_SPANISH_PARAGUAY: return "es_PY";
  692. case SUBLANG_SPANISH_BOLIVIA: return "es_BO";
  693. case SUBLANG_SPANISH_EL_SALVADOR: return "es_SV";
  694. case SUBLANG_SPANISH_HONDURAS: return "es_HN";
  695. case SUBLANG_SPANISH_NICARAGUA: return "es_NI";
  696. case SUBLANG_SPANISH_PUERTO_RICO: return "es_PR";
  697. }
  698. return "es";
  699. case 0x30: /* SUTU */ return "bnt_TZ";
  700. case LANG_SWAHILI: return "sw_KE";
  701. case LANG_SWEDISH:
  702. switch (sub)
  703. {
  704. case SUBLANG_DEFAULT: return "sv_SE";
  705. case SUBLANG_SWEDISH_FINLAND: return "sv_FI";
  706. }
  707. return "sv";
  708. case LANG_SYRIAC: return "syr_TR"; /* An extinct language. */
  709. case 0x64: /* TAGALOG */ return "tl_PH";
  710. case 0x28: /* TAJIK */ return "tg_TJ";
  711. case 0x5f: /* TAMAZIGHT */ return "ber_MA";
  712. case LANG_TAMIL:
  713. return "ta"; /* Ambiguous: could be "ta_IN" or "ta_LK" or "ta_SG". */
  714. case LANG_TATAR: return "tt_RU";
  715. case LANG_TELUGU: return "te_IN";
  716. case LANG_THAI: return "th_TH";
  717. case 0x51: /* TIBETAN */ return "bo_CN";
  718. case 0x73: /* TIGRINYA */ return "ti_ET";
  719. case 0x31: /* TSONGA */ return "ts_ZA";
  720. case LANG_TURKISH: return "tr_TR";
  721. case 0x42: /* TURKMEN */ return "tk_TM";
  722. case LANG_UKRAINIAN: return "uk_UA";
  723. case LANG_URDU:
  724. switch (sub)
  725. {
  726. case SUBLANG_URDU_PAKISTAN: return "ur_PK";
  727. case SUBLANG_URDU_INDIA: return "ur_IN";
  728. }
  729. return "ur";
  730. case LANG_UZBEK:
  731. switch (sub)
  732. {
  733. /* FIXME: Adjust this when Uzbek locales appear on Unix. */
  734. case SUBLANG_UZBEK_LATIN: return "uz_UZ@latin";
  735. case SUBLANG_UZBEK_CYRILLIC: return "uz_UZ@cyrillic";
  736. }
  737. return "uz";
  738. case 0x33: /* VENDA */ return "ven_ZA";
  739. case LANG_VIETNAMESE: return "vi_VN";
  740. case 0x52: /* WELSH */ return "cy_GB";
  741. case 0x34: /* XHOSA */ return "xh_ZA";
  742. case 0x78: /* YI */ return "sit_CN";
  743. case 0x3d: /* YIDDISH */ return "yi_IL";
  744. case 0x6a: /* YORUBA */ return "yo_NG";
  745. case 0x35: /* ZULU */ return "zu_ZA";
  746. default: return "C";
  747. }
  748. #endif
  749. }