localename.c 42 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507
  1. /* Determine name of the currently selected locale.
  2. Copyright (C) 1995-1999, 2000-2007 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. /* MacOS X code written by Bruno Haible <bruno@clisp.org>. */
  18. #include <config.h>
  19. /* Specification. */
  20. #ifdef IN_LIBINTL
  21. # include "gettextP.h"
  22. #else
  23. # include "localename.h"
  24. #endif
  25. #include <stdlib.h>
  26. #include <locale.h>
  27. #if HAVE_CFLOCALECOPYCURRENT || HAVE_CFPREFERENCESCOPYAPPVALUE
  28. # include <string.h>
  29. # include <CoreFoundation/CFString.h>
  30. # if HAVE_CFLOCALECOPYCURRENT
  31. # include <CoreFoundation/CFLocale.h>
  32. # elif HAVE_CFPREFERENCESCOPYAPPVALUE
  33. # include <CoreFoundation/CFPreferences.h>
  34. # endif
  35. #endif
  36. #if defined _WIN32 || defined __WIN32__
  37. # define WIN32_NATIVE
  38. #endif
  39. #ifdef WIN32_NATIVE
  40. # define WIN32_LEAN_AND_MEAN
  41. # include <windows.h>
  42. /* List of language codes, sorted by value:
  43. 0x01 LANG_ARABIC
  44. 0x02 LANG_BULGARIAN
  45. 0x03 LANG_CATALAN
  46. 0x04 LANG_CHINESE
  47. 0x05 LANG_CZECH
  48. 0x06 LANG_DANISH
  49. 0x07 LANG_GERMAN
  50. 0x08 LANG_GREEK
  51. 0x09 LANG_ENGLISH
  52. 0x0a LANG_SPANISH
  53. 0x0b LANG_FINNISH
  54. 0x0c LANG_FRENCH
  55. 0x0d LANG_HEBREW
  56. 0x0e LANG_HUNGARIAN
  57. 0x0f LANG_ICELANDIC
  58. 0x10 LANG_ITALIAN
  59. 0x11 LANG_JAPANESE
  60. 0x12 LANG_KOREAN
  61. 0x13 LANG_DUTCH
  62. 0x14 LANG_NORWEGIAN
  63. 0x15 LANG_POLISH
  64. 0x16 LANG_PORTUGUESE
  65. 0x17 LANG_RHAETO_ROMANCE
  66. 0x18 LANG_ROMANIAN
  67. 0x19 LANG_RUSSIAN
  68. 0x1a LANG_CROATIAN == LANG_SERBIAN
  69. 0x1b LANG_SLOVAK
  70. 0x1c LANG_ALBANIAN
  71. 0x1d LANG_SWEDISH
  72. 0x1e LANG_THAI
  73. 0x1f LANG_TURKISH
  74. 0x20 LANG_URDU
  75. 0x21 LANG_INDONESIAN
  76. 0x22 LANG_UKRAINIAN
  77. 0x23 LANG_BELARUSIAN
  78. 0x24 LANG_SLOVENIAN
  79. 0x25 LANG_ESTONIAN
  80. 0x26 LANG_LATVIAN
  81. 0x27 LANG_LITHUANIAN
  82. 0x28 LANG_TAJIK
  83. 0x29 LANG_FARSI
  84. 0x2a LANG_VIETNAMESE
  85. 0x2b LANG_ARMENIAN
  86. 0x2c LANG_AZERI
  87. 0x2d LANG_BASQUE
  88. 0x2e LANG_SORBIAN
  89. 0x2f LANG_MACEDONIAN
  90. 0x30 LANG_SUTU
  91. 0x31 LANG_TSONGA
  92. 0x32 LANG_TSWANA
  93. 0x33 LANG_VENDA
  94. 0x34 LANG_XHOSA
  95. 0x35 LANG_ZULU
  96. 0x36 LANG_AFRIKAANS
  97. 0x37 LANG_GEORGIAN
  98. 0x38 LANG_FAEROESE
  99. 0x39 LANG_HINDI
  100. 0x3a LANG_MALTESE
  101. 0x3b LANG_SAAMI
  102. 0x3c LANG_GAELIC
  103. 0x3d LANG_YIDDISH
  104. 0x3e LANG_MALAY
  105. 0x3f LANG_KAZAK
  106. 0x40 LANG_KYRGYZ
  107. 0x41 LANG_SWAHILI
  108. 0x42 LANG_TURKMEN
  109. 0x43 LANG_UZBEK
  110. 0x44 LANG_TATAR
  111. 0x45 LANG_BENGALI
  112. 0x46 LANG_PUNJABI
  113. 0x47 LANG_GUJARATI
  114. 0x48 LANG_ORIYA
  115. 0x49 LANG_TAMIL
  116. 0x4a LANG_TELUGU
  117. 0x4b LANG_KANNADA
  118. 0x4c LANG_MALAYALAM
  119. 0x4d LANG_ASSAMESE
  120. 0x4e LANG_MARATHI
  121. 0x4f LANG_SANSKRIT
  122. 0x50 LANG_MONGOLIAN
  123. 0x51 LANG_TIBETAN
  124. 0x52 LANG_WELSH
  125. 0x53 LANG_CAMBODIAN
  126. 0x54 LANG_LAO
  127. 0x55 LANG_BURMESE
  128. 0x56 LANG_GALICIAN
  129. 0x57 LANG_KONKANI
  130. 0x58 LANG_MANIPURI
  131. 0x59 LANG_SINDHI
  132. 0x5a LANG_SYRIAC
  133. 0x5b LANG_SINHALESE
  134. 0x5c LANG_CHEROKEE
  135. 0x5d LANG_INUKTITUT
  136. 0x5e LANG_AMHARIC
  137. 0x5f LANG_TAMAZIGHT
  138. 0x60 LANG_KASHMIRI
  139. 0x61 LANG_NEPALI
  140. 0x62 LANG_FRISIAN
  141. 0x63 LANG_PASHTO
  142. 0x64 LANG_TAGALOG
  143. 0x65 LANG_DIVEHI
  144. 0x66 LANG_EDO
  145. 0x67 LANG_FULFULDE
  146. 0x68 LANG_HAUSA
  147. 0x69 LANG_IBIBIO
  148. 0x6a LANG_YORUBA
  149. 0x70 LANG_IGBO
  150. 0x71 LANG_KANURI
  151. 0x72 LANG_OROMO
  152. 0x73 LANG_TIGRINYA
  153. 0x74 LANG_GUARANI
  154. 0x75 LANG_HAWAIIAN
  155. 0x76 LANG_LATIN
  156. 0x77 LANG_SOMALI
  157. 0x78 LANG_YI
  158. 0x79 LANG_PAPIAMENTU
  159. */
  160. /* Mingw headers don't have latest language and sublanguage codes. */
  161. # ifndef LANG_AFRIKAANS
  162. # define LANG_AFRIKAANS 0x36
  163. # endif
  164. # ifndef LANG_ALBANIAN
  165. # define LANG_ALBANIAN 0x1c
  166. # endif
  167. # ifndef LANG_AMHARIC
  168. # define LANG_AMHARIC 0x5e
  169. # endif
  170. # ifndef LANG_ARABIC
  171. # define LANG_ARABIC 0x01
  172. # endif
  173. # ifndef LANG_ARMENIAN
  174. # define LANG_ARMENIAN 0x2b
  175. # endif
  176. # ifndef LANG_ASSAMESE
  177. # define LANG_ASSAMESE 0x4d
  178. # endif
  179. # ifndef LANG_AZERI
  180. # define LANG_AZERI 0x2c
  181. # endif
  182. # ifndef LANG_BASQUE
  183. # define LANG_BASQUE 0x2d
  184. # endif
  185. # ifndef LANG_BELARUSIAN
  186. # define LANG_BELARUSIAN 0x23
  187. # endif
  188. # ifndef LANG_BENGALI
  189. # define LANG_BENGALI 0x45
  190. # endif
  191. # ifndef LANG_BURMESE
  192. # define LANG_BURMESE 0x55
  193. # endif
  194. # ifndef LANG_CAMBODIAN
  195. # define LANG_CAMBODIAN 0x53
  196. # endif
  197. # ifndef LANG_CATALAN
  198. # define LANG_CATALAN 0x03
  199. # endif
  200. # ifndef LANG_CHEROKEE
  201. # define LANG_CHEROKEE 0x5c
  202. # endif
  203. # ifndef LANG_DIVEHI
  204. # define LANG_DIVEHI 0x65
  205. # endif
  206. # ifndef LANG_EDO
  207. # define LANG_EDO 0x66
  208. # endif
  209. # ifndef LANG_ESTONIAN
  210. # define LANG_ESTONIAN 0x25
  211. # endif
  212. # ifndef LANG_FAEROESE
  213. # define LANG_FAEROESE 0x38
  214. # endif
  215. # ifndef LANG_FARSI
  216. # define LANG_FARSI 0x29
  217. # endif
  218. # ifndef LANG_FRISIAN
  219. # define LANG_FRISIAN 0x62
  220. # endif
  221. # ifndef LANG_FULFULDE
  222. # define LANG_FULFULDE 0x67
  223. # endif
  224. # ifndef LANG_GAELIC
  225. # define LANG_GAELIC 0x3c
  226. # endif
  227. # ifndef LANG_GALICIAN
  228. # define LANG_GALICIAN 0x56
  229. # endif
  230. # ifndef LANG_GEORGIAN
  231. # define LANG_GEORGIAN 0x37
  232. # endif
  233. # ifndef LANG_GUARANI
  234. # define LANG_GUARANI 0x74
  235. # endif
  236. # ifndef LANG_GUJARATI
  237. # define LANG_GUJARATI 0x47
  238. # endif
  239. # ifndef LANG_HAUSA
  240. # define LANG_HAUSA 0x68
  241. # endif
  242. # ifndef LANG_HAWAIIAN
  243. # define LANG_HAWAIIAN 0x75
  244. # endif
  245. # ifndef LANG_HEBREW
  246. # define LANG_HEBREW 0x0d
  247. # endif
  248. # ifndef LANG_HINDI
  249. # define LANG_HINDI 0x39
  250. # endif
  251. # ifndef LANG_IBIBIO
  252. # define LANG_IBIBIO 0x69
  253. # endif
  254. # ifndef LANG_IGBO
  255. # define LANG_IGBO 0x70
  256. # endif
  257. # ifndef LANG_INDONESIAN
  258. # define LANG_INDONESIAN 0x21
  259. # endif
  260. # ifndef LANG_INUKTITUT
  261. # define LANG_INUKTITUT 0x5d
  262. # endif
  263. # ifndef LANG_KANNADA
  264. # define LANG_KANNADA 0x4b
  265. # endif
  266. # ifndef LANG_KANURI
  267. # define LANG_KANURI 0x71
  268. # endif
  269. # ifndef LANG_KASHMIRI
  270. # define LANG_KASHMIRI 0x60
  271. # endif
  272. # ifndef LANG_KAZAK
  273. # define LANG_KAZAK 0x3f
  274. # endif
  275. # ifndef LANG_KONKANI
  276. # define LANG_KONKANI 0x57
  277. # endif
  278. # ifndef LANG_KYRGYZ
  279. # define LANG_KYRGYZ 0x40
  280. # endif
  281. # ifndef LANG_LAO
  282. # define LANG_LAO 0x54
  283. # endif
  284. # ifndef LANG_LATIN
  285. # define LANG_LATIN 0x76
  286. # endif
  287. # ifndef LANG_LATVIAN
  288. # define LANG_LATVIAN 0x26
  289. # endif
  290. # ifndef LANG_LITHUANIAN
  291. # define LANG_LITHUANIAN 0x27
  292. # endif
  293. # ifndef LANG_MACEDONIAN
  294. # define LANG_MACEDONIAN 0x2f
  295. # endif
  296. # ifndef LANG_MALAY
  297. # define LANG_MALAY 0x3e
  298. # endif
  299. # ifndef LANG_MALAYALAM
  300. # define LANG_MALAYALAM 0x4c
  301. # endif
  302. # ifndef LANG_MALTESE
  303. # define LANG_MALTESE 0x3a
  304. # endif
  305. # ifndef LANG_MANIPURI
  306. # define LANG_MANIPURI 0x58
  307. # endif
  308. # ifndef LANG_MARATHI
  309. # define LANG_MARATHI 0x4e
  310. # endif
  311. # ifndef LANG_MONGOLIAN
  312. # define LANG_MONGOLIAN 0x50
  313. # endif
  314. # ifndef LANG_NEPALI
  315. # define LANG_NEPALI 0x61
  316. # endif
  317. # ifndef LANG_ORIYA
  318. # define LANG_ORIYA 0x48
  319. # endif
  320. # ifndef LANG_OROMO
  321. # define LANG_OROMO 0x72
  322. # endif
  323. # ifndef LANG_PAPIAMENTU
  324. # define LANG_PAPIAMENTU 0x79
  325. # endif
  326. # ifndef LANG_PASHTO
  327. # define LANG_PASHTO 0x63
  328. # endif
  329. # ifndef LANG_PUNJABI
  330. # define LANG_PUNJABI 0x46
  331. # endif
  332. # ifndef LANG_RHAETO_ROMANCE
  333. # define LANG_RHAETO_ROMANCE 0x17
  334. # endif
  335. # ifndef LANG_SAAMI
  336. # define LANG_SAAMI 0x3b
  337. # endif
  338. # ifndef LANG_SANSKRIT
  339. # define LANG_SANSKRIT 0x4f
  340. # endif
  341. # ifndef LANG_SERBIAN
  342. # define LANG_SERBIAN 0x1a
  343. # endif
  344. # ifndef LANG_SINDHI
  345. # define LANG_SINDHI 0x59
  346. # endif
  347. # ifndef LANG_SINHALESE
  348. # define LANG_SINHALESE 0x5b
  349. # endif
  350. # ifndef LANG_SLOVAK
  351. # define LANG_SLOVAK 0x1b
  352. # endif
  353. # ifndef LANG_SOMALI
  354. # define LANG_SOMALI 0x77
  355. # endif
  356. # ifndef LANG_SORBIAN
  357. # define LANG_SORBIAN 0x2e
  358. # endif
  359. # ifndef LANG_SUTU
  360. # define LANG_SUTU 0x30
  361. # endif
  362. # ifndef LANG_SWAHILI
  363. # define LANG_SWAHILI 0x41
  364. # endif
  365. # ifndef LANG_SYRIAC
  366. # define LANG_SYRIAC 0x5a
  367. # endif
  368. # ifndef LANG_TAGALOG
  369. # define LANG_TAGALOG 0x64
  370. # endif
  371. # ifndef LANG_TAJIK
  372. # define LANG_TAJIK 0x28
  373. # endif
  374. # ifndef LANG_TAMAZIGHT
  375. # define LANG_TAMAZIGHT 0x5f
  376. # endif
  377. # ifndef LANG_TAMIL
  378. # define LANG_TAMIL 0x49
  379. # endif
  380. # ifndef LANG_TATAR
  381. # define LANG_TATAR 0x44
  382. # endif
  383. # ifndef LANG_TELUGU
  384. # define LANG_TELUGU 0x4a
  385. # endif
  386. # ifndef LANG_THAI
  387. # define LANG_THAI 0x1e
  388. # endif
  389. # ifndef LANG_TIBETAN
  390. # define LANG_TIBETAN 0x51
  391. # endif
  392. # ifndef LANG_TIGRINYA
  393. # define LANG_TIGRINYA 0x73
  394. # endif
  395. # ifndef LANG_TSONGA
  396. # define LANG_TSONGA 0x31
  397. # endif
  398. # ifndef LANG_TSWANA
  399. # define LANG_TSWANA 0x32
  400. # endif
  401. # ifndef LANG_TURKMEN
  402. # define LANG_TURKMEN 0x42
  403. # endif
  404. # ifndef LANG_UKRAINIAN
  405. # define LANG_UKRAINIAN 0x22
  406. # endif
  407. # ifndef LANG_URDU
  408. # define LANG_URDU 0x20
  409. # endif
  410. # ifndef LANG_UZBEK
  411. # define LANG_UZBEK 0x43
  412. # endif
  413. # ifndef LANG_VENDA
  414. # define LANG_VENDA 0x33
  415. # endif
  416. # ifndef LANG_VIETNAMESE
  417. # define LANG_VIETNAMESE 0x2a
  418. # endif
  419. # ifndef LANG_WELSH
  420. # define LANG_WELSH 0x52
  421. # endif
  422. # ifndef LANG_XHOSA
  423. # define LANG_XHOSA 0x34
  424. # endif
  425. # ifndef LANG_YI
  426. # define LANG_YI 0x78
  427. # endif
  428. # ifndef LANG_YIDDISH
  429. # define LANG_YIDDISH 0x3d
  430. # endif
  431. # ifndef LANG_YORUBA
  432. # define LANG_YORUBA 0x6a
  433. # endif
  434. # ifndef LANG_ZULU
  435. # define LANG_ZULU 0x35
  436. # endif
  437. # ifndef SUBLANG_ARABIC_SAUDI_ARABIA
  438. # define SUBLANG_ARABIC_SAUDI_ARABIA 0x01
  439. # endif
  440. # ifndef SUBLANG_ARABIC_IRAQ
  441. # define SUBLANG_ARABIC_IRAQ 0x02
  442. # endif
  443. # ifndef SUBLANG_ARABIC_EGYPT
  444. # define SUBLANG_ARABIC_EGYPT 0x03
  445. # endif
  446. # ifndef SUBLANG_ARABIC_LIBYA
  447. # define SUBLANG_ARABIC_LIBYA 0x04
  448. # endif
  449. # ifndef SUBLANG_ARABIC_ALGERIA
  450. # define SUBLANG_ARABIC_ALGERIA 0x05
  451. # endif
  452. # ifndef SUBLANG_ARABIC_MOROCCO
  453. # define SUBLANG_ARABIC_MOROCCO 0x06
  454. # endif
  455. # ifndef SUBLANG_ARABIC_TUNISIA
  456. # define SUBLANG_ARABIC_TUNISIA 0x07
  457. # endif
  458. # ifndef SUBLANG_ARABIC_OMAN
  459. # define SUBLANG_ARABIC_OMAN 0x08
  460. # endif
  461. # ifndef SUBLANG_ARABIC_YEMEN
  462. # define SUBLANG_ARABIC_YEMEN 0x09
  463. # endif
  464. # ifndef SUBLANG_ARABIC_SYRIA
  465. # define SUBLANG_ARABIC_SYRIA 0x0a
  466. # endif
  467. # ifndef SUBLANG_ARABIC_JORDAN
  468. # define SUBLANG_ARABIC_JORDAN 0x0b
  469. # endif
  470. # ifndef SUBLANG_ARABIC_LEBANON
  471. # define SUBLANG_ARABIC_LEBANON 0x0c
  472. # endif
  473. # ifndef SUBLANG_ARABIC_KUWAIT
  474. # define SUBLANG_ARABIC_KUWAIT 0x0d
  475. # endif
  476. # ifndef SUBLANG_ARABIC_UAE
  477. # define SUBLANG_ARABIC_UAE 0x0e
  478. # endif
  479. # ifndef SUBLANG_ARABIC_BAHRAIN
  480. # define SUBLANG_ARABIC_BAHRAIN 0x0f
  481. # endif
  482. # ifndef SUBLANG_ARABIC_QATAR
  483. # define SUBLANG_ARABIC_QATAR 0x10
  484. # endif
  485. # ifndef SUBLANG_AZERI_LATIN
  486. # define SUBLANG_AZERI_LATIN 0x01
  487. # endif
  488. # ifndef SUBLANG_AZERI_CYRILLIC
  489. # define SUBLANG_AZERI_CYRILLIC 0x02
  490. # endif
  491. # ifndef SUBLANG_BENGALI_INDIA
  492. # define SUBLANG_BENGALI_INDIA 0x01
  493. # endif
  494. # ifndef SUBLANG_BENGALI_BANGLADESH
  495. # define SUBLANG_BENGALI_BANGLADESH 0x02
  496. # endif
  497. # ifndef SUBLANG_CHINESE_MACAU
  498. # define SUBLANG_CHINESE_MACAU 0x05
  499. # endif
  500. # ifndef SUBLANG_ENGLISH_SOUTH_AFRICA
  501. # define SUBLANG_ENGLISH_SOUTH_AFRICA 0x07
  502. # endif
  503. # ifndef SUBLANG_ENGLISH_JAMAICA
  504. # define SUBLANG_ENGLISH_JAMAICA 0x08
  505. # endif
  506. # ifndef SUBLANG_ENGLISH_CARIBBEAN
  507. # define SUBLANG_ENGLISH_CARIBBEAN 0x09
  508. # endif
  509. # ifndef SUBLANG_ENGLISH_BELIZE
  510. # define SUBLANG_ENGLISH_BELIZE 0x0a
  511. # endif
  512. # ifndef SUBLANG_ENGLISH_TRINIDAD
  513. # define SUBLANG_ENGLISH_TRINIDAD 0x0b
  514. # endif
  515. # ifndef SUBLANG_ENGLISH_ZIMBABWE
  516. # define SUBLANG_ENGLISH_ZIMBABWE 0x0c
  517. # endif
  518. # ifndef SUBLANG_ENGLISH_PHILIPPINES
  519. # define SUBLANG_ENGLISH_PHILIPPINES 0x0d
  520. # endif
  521. # ifndef SUBLANG_ENGLISH_INDONESIA
  522. # define SUBLANG_ENGLISH_INDONESIA 0x0e
  523. # endif
  524. # ifndef SUBLANG_ENGLISH_HONGKONG
  525. # define SUBLANG_ENGLISH_HONGKONG 0x0f
  526. # endif
  527. # ifndef SUBLANG_ENGLISH_INDIA
  528. # define SUBLANG_ENGLISH_INDIA 0x10
  529. # endif
  530. # ifndef SUBLANG_ENGLISH_MALAYSIA
  531. # define SUBLANG_ENGLISH_MALAYSIA 0x11
  532. # endif
  533. # ifndef SUBLANG_ENGLISH_SINGAPORE
  534. # define SUBLANG_ENGLISH_SINGAPORE 0x12
  535. # endif
  536. # ifndef SUBLANG_FRENCH_LUXEMBOURG
  537. # define SUBLANG_FRENCH_LUXEMBOURG 0x05
  538. # endif
  539. # ifndef SUBLANG_FRENCH_MONACO
  540. # define SUBLANG_FRENCH_MONACO 0x06
  541. # endif
  542. # ifndef SUBLANG_FRENCH_WESTINDIES
  543. # define SUBLANG_FRENCH_WESTINDIES 0x07
  544. # endif
  545. # ifndef SUBLANG_FRENCH_REUNION
  546. # define SUBLANG_FRENCH_REUNION 0x08
  547. # endif
  548. # ifndef SUBLANG_FRENCH_CONGO
  549. # define SUBLANG_FRENCH_CONGO 0x09
  550. # endif
  551. # ifndef SUBLANG_FRENCH_SENEGAL
  552. # define SUBLANG_FRENCH_SENEGAL 0x0a
  553. # endif
  554. # ifndef SUBLANG_FRENCH_CAMEROON
  555. # define SUBLANG_FRENCH_CAMEROON 0x0b
  556. # endif
  557. # ifndef SUBLANG_FRENCH_COTEDIVOIRE
  558. # define SUBLANG_FRENCH_COTEDIVOIRE 0x0c
  559. # endif
  560. # ifndef SUBLANG_FRENCH_MALI
  561. # define SUBLANG_FRENCH_MALI 0x0d
  562. # endif
  563. # ifndef SUBLANG_FRENCH_MOROCCO
  564. # define SUBLANG_FRENCH_MOROCCO 0x0e
  565. # endif
  566. # ifndef SUBLANG_FRENCH_HAITI
  567. # define SUBLANG_FRENCH_HAITI 0x0f
  568. # endif
  569. # ifndef SUBLANG_GERMAN_LUXEMBOURG
  570. # define SUBLANG_GERMAN_LUXEMBOURG 0x04
  571. # endif
  572. # ifndef SUBLANG_GERMAN_LIECHTENSTEIN
  573. # define SUBLANG_GERMAN_LIECHTENSTEIN 0x05
  574. # endif
  575. # ifndef SUBLANG_KASHMIRI_INDIA
  576. # define SUBLANG_KASHMIRI_INDIA 0x02
  577. # endif
  578. # ifndef SUBLANG_MALAY_MALAYSIA
  579. # define SUBLANG_MALAY_MALAYSIA 0x01
  580. # endif
  581. # ifndef SUBLANG_MALAY_BRUNEI_DARUSSALAM
  582. # define SUBLANG_MALAY_BRUNEI_DARUSSALAM 0x02
  583. # endif
  584. # ifndef SUBLANG_NEPALI_INDIA
  585. # define SUBLANG_NEPALI_INDIA 0x02
  586. # endif
  587. # ifndef SUBLANG_PUNJABI_INDIA
  588. # define SUBLANG_PUNJABI_INDIA 0x01
  589. # endif
  590. # ifndef SUBLANG_PUNJABI_PAKISTAN
  591. # define SUBLANG_PUNJABI_PAKISTAN 0x02
  592. # endif
  593. # ifndef SUBLANG_ROMANIAN_ROMANIA
  594. # define SUBLANG_ROMANIAN_ROMANIA 0x01
  595. # endif
  596. # ifndef SUBLANG_ROMANIAN_MOLDOVA
  597. # define SUBLANG_ROMANIAN_MOLDOVA 0x02
  598. # endif
  599. # ifndef SUBLANG_SERBIAN_LATIN
  600. # define SUBLANG_SERBIAN_LATIN 0x02
  601. # endif
  602. # ifndef SUBLANG_SERBIAN_CYRILLIC
  603. # define SUBLANG_SERBIAN_CYRILLIC 0x03
  604. # endif
  605. # ifndef SUBLANG_SINDHI_PAKISTAN
  606. # define SUBLANG_SINDHI_PAKISTAN 0x01
  607. # endif
  608. # ifndef SUBLANG_SINDHI_AFGHANISTAN
  609. # define SUBLANG_SINDHI_AFGHANISTAN 0x02
  610. # endif
  611. # ifndef SUBLANG_SPANISH_GUATEMALA
  612. # define SUBLANG_SPANISH_GUATEMALA 0x04
  613. # endif
  614. # ifndef SUBLANG_SPANISH_COSTA_RICA
  615. # define SUBLANG_SPANISH_COSTA_RICA 0x05
  616. # endif
  617. # ifndef SUBLANG_SPANISH_PANAMA
  618. # define SUBLANG_SPANISH_PANAMA 0x06
  619. # endif
  620. # ifndef SUBLANG_SPANISH_DOMINICAN_REPUBLIC
  621. # define SUBLANG_SPANISH_DOMINICAN_REPUBLIC 0x07
  622. # endif
  623. # ifndef SUBLANG_SPANISH_VENEZUELA
  624. # define SUBLANG_SPANISH_VENEZUELA 0x08
  625. # endif
  626. # ifndef SUBLANG_SPANISH_COLOMBIA
  627. # define SUBLANG_SPANISH_COLOMBIA 0x09
  628. # endif
  629. # ifndef SUBLANG_SPANISH_PERU
  630. # define SUBLANG_SPANISH_PERU 0x0a
  631. # endif
  632. # ifndef SUBLANG_SPANISH_ARGENTINA
  633. # define SUBLANG_SPANISH_ARGENTINA 0x0b
  634. # endif
  635. # ifndef SUBLANG_SPANISH_ECUADOR
  636. # define SUBLANG_SPANISH_ECUADOR 0x0c
  637. # endif
  638. # ifndef SUBLANG_SPANISH_CHILE
  639. # define SUBLANG_SPANISH_CHILE 0x0d
  640. # endif
  641. # ifndef SUBLANG_SPANISH_URUGUAY
  642. # define SUBLANG_SPANISH_URUGUAY 0x0e
  643. # endif
  644. # ifndef SUBLANG_SPANISH_PARAGUAY
  645. # define SUBLANG_SPANISH_PARAGUAY 0x0f
  646. # endif
  647. # ifndef SUBLANG_SPANISH_BOLIVIA
  648. # define SUBLANG_SPANISH_BOLIVIA 0x10
  649. # endif
  650. # ifndef SUBLANG_SPANISH_EL_SALVADOR
  651. # define SUBLANG_SPANISH_EL_SALVADOR 0x11
  652. # endif
  653. # ifndef SUBLANG_SPANISH_HONDURAS
  654. # define SUBLANG_SPANISH_HONDURAS 0x12
  655. # endif
  656. # ifndef SUBLANG_SPANISH_NICARAGUA
  657. # define SUBLANG_SPANISH_NICARAGUA 0x13
  658. # endif
  659. # ifndef SUBLANG_SPANISH_PUERTO_RICO
  660. # define SUBLANG_SPANISH_PUERTO_RICO 0x14
  661. # endif
  662. # ifndef SUBLANG_SWEDISH_FINLAND
  663. # define SUBLANG_SWEDISH_FINLAND 0x02
  664. # endif
  665. # ifndef SUBLANG_TAMAZIGHT_ARABIC
  666. # define SUBLANG_TAMAZIGHT_ARABIC 0x01
  667. # endif
  668. # ifndef SUBLANG_TAMAZIGHT_ALGERIA_LATIN
  669. # define SUBLANG_TAMAZIGHT_ALGERIA_LATIN 0x02
  670. # endif
  671. # ifndef SUBLANG_TIGRINYA_ETHIOPIA
  672. # define SUBLANG_TIGRINYA_ETHIOPIA 0x01
  673. # endif
  674. # ifndef SUBLANG_TIGRINYA_ERITREA
  675. # define SUBLANG_TIGRINYA_ERITREA 0x02
  676. # endif
  677. # ifndef SUBLANG_URDU_PAKISTAN
  678. # define SUBLANG_URDU_PAKISTAN 0x01
  679. # endif
  680. # ifndef SUBLANG_URDU_INDIA
  681. # define SUBLANG_URDU_INDIA 0x02
  682. # endif
  683. # ifndef SUBLANG_UZBEK_LATIN
  684. # define SUBLANG_UZBEK_LATIN 0x01
  685. # endif
  686. # ifndef SUBLANG_UZBEK_CYRILLIC
  687. # define SUBLANG_UZBEK_CYRILLIC 0x02
  688. # endif
  689. #endif
  690. # if HAVE_CFLOCALECOPYCURRENT || HAVE_CFPREFERENCESCOPYAPPVALUE
  691. /* MacOS X 10.2 or newer */
  692. /* Canonicalize a MacOS X locale name to a Unix locale name.
  693. NAME is a sufficiently large buffer.
  694. On input, it contains the MacOS X locale name.
  695. On output, it contains the Unix locale name. */
  696. # if !defined IN_LIBINTL
  697. static
  698. # endif
  699. void
  700. gl_locale_name_canonicalize (char *name)
  701. {
  702. /* This conversion is based on a posting by
  703. Deborah GoldSmith <goldsmit@apple.com> on 2005-03-08,
  704. http://lists.apple.com/archives/carbon-dev/2005/Mar/msg00293.html */
  705. /* Convert legacy (NeXTstep inherited) English names to Unix (ISO 639 and
  706. ISO 3166) names. Prior to MacOS X 10.3, there is no API for doing this.
  707. Therefore we do it ourselves, using a table based on the results of the
  708. MacOS X 10.3.8 function
  709. CFLocaleCreateCanonicalLocaleIdentifierFromString(). */
  710. typedef struct { const char legacy[21+1]; const char unixy[5+1]; }
  711. legacy_entry;
  712. static const legacy_entry legacy_table[] = {
  713. { "Afrikaans", "af" },
  714. { "Albanian", "sq" },
  715. { "Amharic", "am" },
  716. { "Arabic", "ar" },
  717. { "Armenian", "hy" },
  718. { "Assamese", "as" },
  719. { "Aymara", "ay" },
  720. { "Azerbaijani", "az" },
  721. { "Basque", "eu" },
  722. { "Belarusian", "be" },
  723. { "Belorussian", "be" },
  724. { "Bengali", "bn" },
  725. { "Brazilian Portugese", "pt_BR" },
  726. { "Brazilian Portuguese", "pt_BR" },
  727. { "Breton", "br" },
  728. { "Bulgarian", "bg" },
  729. { "Burmese", "my" },
  730. { "Byelorussian", "be" },
  731. { "Catalan", "ca" },
  732. { "Chewa", "ny" },
  733. { "Chichewa", "ny" },
  734. { "Chinese", "zh" },
  735. { "Chinese, Simplified", "zh_CN" },
  736. { "Chinese, Traditional", "zh_TW" },
  737. { "Chinese, Tradtional", "zh_TW" },
  738. { "Croatian", "hr" },
  739. { "Czech", "cs" },
  740. { "Danish", "da" },
  741. { "Dutch", "nl" },
  742. { "Dzongkha", "dz" },
  743. { "English", "en" },
  744. { "Esperanto", "eo" },
  745. { "Estonian", "et" },
  746. { "Faroese", "fo" },
  747. { "Farsi", "fa" },
  748. { "Finnish", "fi" },
  749. { "Flemish", "nl_BE" },
  750. { "French", "fr" },
  751. { "Galician", "gl" },
  752. { "Gallegan", "gl" },
  753. { "Georgian", "ka" },
  754. { "German", "de" },
  755. { "Greek", "el" },
  756. { "Greenlandic", "kl" },
  757. { "Guarani", "gn" },
  758. { "Gujarati", "gu" },
  759. { "Hawaiian", "haw" }, /* Yes, "haw", not "cpe". */
  760. { "Hebrew", "he" },
  761. { "Hindi", "hi" },
  762. { "Hungarian", "hu" },
  763. { "Icelandic", "is" },
  764. { "Indonesian", "id" },
  765. { "Inuktitut", "iu" },
  766. { "Irish", "ga" },
  767. { "Italian", "it" },
  768. { "Japanese", "ja" },
  769. { "Javanese", "jv" },
  770. { "Kalaallisut", "kl" },
  771. { "Kannada", "kn" },
  772. { "Kashmiri", "ks" },
  773. { "Kazakh", "kk" },
  774. { "Khmer", "km" },
  775. { "Kinyarwanda", "rw" },
  776. { "Kirghiz", "ky" },
  777. { "Korean", "ko" },
  778. { "Kurdish", "ku" },
  779. { "Latin", "la" },
  780. { "Latvian", "lv" },
  781. { "Lithuanian", "lt" },
  782. { "Macedonian", "mk" },
  783. { "Malagasy", "mg" },
  784. { "Malay", "ms" },
  785. { "Malayalam", "ml" },
  786. { "Maltese", "mt" },
  787. { "Manx", "gv" },
  788. { "Marathi", "mr" },
  789. { "Moldavian", "mo" },
  790. { "Mongolian", "mn" },
  791. { "Nepali", "ne" },
  792. { "Norwegian", "nb" }, /* Yes, "nb", not the obsolete "no". */
  793. { "Nyanja", "ny" },
  794. { "Nynorsk", "nn" },
  795. { "Oriya", "or" },
  796. { "Oromo", "om" },
  797. { "Panjabi", "pa" },
  798. { "Pashto", "ps" },
  799. { "Persian", "fa" },
  800. { "Polish", "pl" },
  801. { "Portuguese", "pt" },
  802. { "Portuguese, Brazilian", "pt_BR" },
  803. { "Punjabi", "pa" },
  804. { "Pushto", "ps" },
  805. { "Quechua", "qu" },
  806. { "Romanian", "ro" },
  807. { "Ruanda", "rw" },
  808. { "Rundi", "rn" },
  809. { "Russian", "ru" },
  810. { "Sami", "se_NO" }, /* Not just "se". */
  811. { "Sanskrit", "sa" },
  812. { "Scottish", "gd" },
  813. { "Serbian", "sr" },
  814. { "Simplified Chinese", "zh_CN" },
  815. { "Sindhi", "sd" },
  816. { "Sinhalese", "si" },
  817. { "Slovak", "sk" },
  818. { "Slovenian", "sl" },
  819. { "Somali", "so" },
  820. { "Spanish", "es" },
  821. { "Sundanese", "su" },
  822. { "Swahili", "sw" },
  823. { "Swedish", "sv" },
  824. { "Tagalog", "tl" },
  825. { "Tajik", "tg" },
  826. { "Tajiki", "tg" },
  827. { "Tamil", "ta" },
  828. { "Tatar", "tt" },
  829. { "Telugu", "te" },
  830. { "Thai", "th" },
  831. { "Tibetan", "bo" },
  832. { "Tigrinya", "ti" },
  833. { "Tongan", "to" },
  834. { "Traditional Chinese", "zh_TW" },
  835. { "Turkish", "tr" },
  836. { "Turkmen", "tk" },
  837. { "Uighur", "ug" },
  838. { "Ukrainian", "uk" },
  839. { "Urdu", "ur" },
  840. { "Uzbek", "uz" },
  841. { "Vietnamese", "vi" },
  842. { "Welsh", "cy" },
  843. { "Yiddish", "yi" }
  844. };
  845. /* Convert new-style locale names with language tags (ISO 639 and ISO 15924)
  846. to Unix (ISO 639 and ISO 3166) names. */
  847. typedef struct { const char langtag[7+1]; const char unixy[12+1]; }
  848. langtag_entry;
  849. static const langtag_entry langtag_table[] = {
  850. /* MacOS X has "az-Arab", "az-Cyrl", "az-Latn".
  851. The default script for az on Unix is Latin. */
  852. { "az-Latn", "az" },
  853. /* MacOS X has "ga-dots". Does not yet exist on Unix. */
  854. { "ga-dots", "ga" },
  855. /* MacOS X has "kk-Cyrl". Does not yet exist on Unix. */
  856. /* MacOS X has "mn-Cyrl", "mn-Mong".
  857. The default script for mn on Unix is Cyrillic. */
  858. { "mn-Cyrl", "mn" },
  859. /* MacOS X has "ms-Arab", "ms-Latn".
  860. The default script for ms on Unix is Latin. */
  861. { "ms-Latn", "ms" },
  862. /* MacOS X has "tg-Cyrl".
  863. The default script for tg on Unix is Cyrillic. */
  864. { "tg-Cyrl", "tg" },
  865. /* MacOS X has "tk-Cyrl". Does not yet exist on Unix. */
  866. /* MacOS X has "tt-Cyrl".
  867. The default script for tt on Unix is Cyrillic. */
  868. { "tt-Cyrl", "tt" },
  869. /* MacOS X has "zh-Hans", "zh-Hant".
  870. Country codes are used to distinguish these on Unix. */
  871. { "zh-Hans", "zh_CN" },
  872. { "zh-Hant", "zh_TW" }
  873. };
  874. /* Convert script names (ISO 15924) to Unix conventions.
  875. See http://www.unicode.org/iso15924/iso15924-codes.html */
  876. typedef struct { const char script[4+1]; const char unixy[9+1]; }
  877. script_entry;
  878. static const script_entry script_table[] = {
  879. { "Arab", "arabic" },
  880. { "Cyrl", "cyrillic" },
  881. { "Mong", "mongolian" }
  882. };
  883. /* Step 1: Convert using legacy_table. */
  884. if (name[0] >= 'A' && name[0] <= 'Z')
  885. {
  886. unsigned int i1, i2;
  887. i1 = 0;
  888. i2 = sizeof (legacy_table) / sizeof (legacy_entry);
  889. while (i2 - i1 > 1)
  890. {
  891. /* At this point we know that if name occurs in legacy_table,
  892. its index must be >= i1 and < i2. */
  893. unsigned int i = (i1 + i2) >> 1;
  894. const legacy_entry *p = &legacy_table[i];
  895. if (strcmp (name, p->legacy) < 0)
  896. i2 = i;
  897. else
  898. i1 = i;
  899. }
  900. if (strcmp (name, legacy_table[i1].legacy) == 0)
  901. {
  902. strcpy (name, legacy_table[i1].unixy);
  903. return;
  904. }
  905. }
  906. /* Step 2: Convert using langtag_table and script_table. */
  907. if (strlen (name) == 7 && name[2] == '-')
  908. {
  909. unsigned int i1, i2;
  910. i1 = 0;
  911. i2 = sizeof (langtag_table) / sizeof (langtag_entry);
  912. while (i2 - i1 > 1)
  913. {
  914. /* At this point we know that if name occurs in langtag_table,
  915. its index must be >= i1 and < i2. */
  916. unsigned int i = (i1 + i2) >> 1;
  917. const langtag_entry *p = &langtag_table[i];
  918. if (strcmp (name, p->langtag) < 0)
  919. i2 = i;
  920. else
  921. i1 = i;
  922. }
  923. if (strcmp (name, langtag_table[i1].langtag) == 0)
  924. {
  925. strcpy (name, langtag_table[i1].unixy);
  926. return;
  927. }
  928. i1 = 0;
  929. i2 = sizeof (script_table) / sizeof (script_entry);
  930. while (i2 - i1 > 1)
  931. {
  932. /* At this point we know that if (name + 3) occurs in script_table,
  933. its index must be >= i1 and < i2. */
  934. unsigned int i = (i1 + i2) >> 1;
  935. const script_entry *p = &script_table[i];
  936. if (strcmp (name + 3, p->script) < 0)
  937. i2 = i;
  938. else
  939. i1 = i;
  940. }
  941. if (strcmp (name + 3, script_table[i1].script) == 0)
  942. {
  943. name[2] = '@';
  944. strcpy (name + 3, script_table[i1].unixy);
  945. return;
  946. }
  947. }
  948. /* Step 3: Convert new-style dash to Unix underscore. */
  949. {
  950. char *p;
  951. for (p = name; *p != '\0'; p++)
  952. if (*p == '-')
  953. *p = '_';
  954. }
  955. }
  956. #endif
  957. /* XPG3 defines the result of 'setlocale (category, NULL)' as:
  958. "Directs 'setlocale()' to query 'category' and return the current
  959. setting of 'local'."
  960. However it does not specify the exact format. Neither do SUSV2 and
  961. ISO C 99. So we can use this feature only on selected systems (e.g.
  962. those using GNU C Library). */
  963. #if defined _LIBC || (defined __GLIBC__ && __GLIBC__ >= 2)
  964. # define HAVE_LOCALE_NULL
  965. #endif
  966. /* Determine the current locale's name, and canonicalize it into XPG syntax
  967. language[_territory][.codeset][@modifier]
  968. The codeset part in the result is not reliable; the locale_charset()
  969. should be used for codeset information instead.
  970. The result must not be freed; it is statically allocated. */
  971. const char *
  972. gl_locale_name_posix (int category, const char *categoryname)
  973. {
  974. /* Use the POSIX methods of looking to 'LC_ALL', 'LC_xxx', and 'LANG'.
  975. On some systems this can be done by the 'setlocale' function itself. */
  976. #if defined HAVE_SETLOCALE && defined HAVE_LC_MESSAGES && defined HAVE_LOCALE_NULL
  977. return setlocale (category, NULL);
  978. #else
  979. const char *retval;
  980. /* Setting of LC_ALL overrides all other. */
  981. retval = getenv ("LC_ALL");
  982. if (retval != NULL && retval[0] != '\0')
  983. return retval;
  984. /* Next comes the name of the desired category. */
  985. retval = getenv (categoryname);
  986. if (retval != NULL && retval[0] != '\0')
  987. return retval;
  988. /* Last possibility is the LANG environment variable. */
  989. retval = getenv ("LANG");
  990. if (retval != NULL && retval[0] != '\0')
  991. return retval;
  992. return NULL;
  993. #endif
  994. }
  995. const char *
  996. gl_locale_name_default (void)
  997. {
  998. /* POSIX:2001 says:
  999. "All implementations shall define a locale as the default locale, to be
  1000. invoked when no environment variables are set, or set to the empty
  1001. string. This default locale can be the POSIX locale or any other
  1002. implementation-defined locale. Some implementations may provide
  1003. facilities for local installation administrators to set the default
  1004. locale, customizing it for each location. POSIX:2001 does not require
  1005. such a facility. */
  1006. #if !(HAVE_CFLOCALECOPYCURRENT || HAVE_CFPREFERENCESCOPYAPPVALUE || defined(WIN32_NATIVE))
  1007. /* The system does not have a way of setting the locale, other than the
  1008. POSIX specified environment variables. We use C as default locale. */
  1009. return "C";
  1010. #else
  1011. /* Return an XPG style locale name language[_territory][@modifier].
  1012. Don't even bother determining the codeset; it's not useful in this
  1013. context, because message catalogs are not specific to a single
  1014. codeset. */
  1015. # if HAVE_CFLOCALECOPYCURRENT || HAVE_CFPREFERENCESCOPYAPPVALUE
  1016. /* MacOS X 10.2 or newer */
  1017. {
  1018. /* Cache the locale name, since CoreFoundation calls are expensive. */
  1019. static const char *cached_localename;
  1020. if (cached_localename == NULL)
  1021. {
  1022. char namebuf[256];
  1023. # if HAVE_CFLOCALECOPYCURRENT /* MacOS X 10.3 or newer */
  1024. CFLocaleRef locale = CFLocaleCopyCurrent ();
  1025. CFStringRef name = CFLocaleGetIdentifier (locale);
  1026. if (CFStringGetCString (name, namebuf, sizeof(namebuf),
  1027. kCFStringEncodingASCII))
  1028. {
  1029. gl_locale_name_canonicalize (namebuf);
  1030. cached_localename = strdup (namebuf);
  1031. }
  1032. CFRelease (locale);
  1033. # elif HAVE_CFPREFERENCESCOPYAPPVALUE /* MacOS X 10.2 or newer */
  1034. CFTypeRef value =
  1035. CFPreferencesCopyAppValue (CFSTR ("AppleLocale"),
  1036. kCFPreferencesCurrentApplication);
  1037. if (value != NULL
  1038. && CFGetTypeID (value) == CFStringGetTypeID ()
  1039. && CFStringGetCString ((CFStringRef)value, namebuf, sizeof(namebuf),
  1040. kCFStringEncodingASCII))
  1041. {
  1042. gl_locale_name_canonicalize (namebuf);
  1043. cached_localename = strdup (namebuf);
  1044. }
  1045. # endif
  1046. if (cached_localename == NULL)
  1047. cached_localename = "C";
  1048. }
  1049. return cached_localename;
  1050. }
  1051. # endif
  1052. # if defined(WIN32_NATIVE) /* WIN32, not Cygwin */
  1053. {
  1054. LCID lcid;
  1055. LANGID langid;
  1056. int primary, sub;
  1057. /* Use native Win32 API locale ID. */
  1058. lcid = GetThreadLocale ();
  1059. /* Strip off the sorting rules, keep only the language part. */
  1060. langid = LANGIDFROMLCID (lcid);
  1061. /* Split into language and territory part. */
  1062. primary = PRIMARYLANGID (langid);
  1063. sub = SUBLANGID (langid);
  1064. /* Dispatch on language.
  1065. See also http://www.unicode.org/unicode/onlinedat/languages.html .
  1066. For details about languages, see http://www.ethnologue.com/ . */
  1067. switch (primary)
  1068. {
  1069. case LANG_AFRIKAANS: return "af_ZA";
  1070. case LANG_ALBANIAN: return "sq_AL";
  1071. case LANG_AMHARIC: return "am_ET";
  1072. case LANG_ARABIC:
  1073. switch (sub)
  1074. {
  1075. case SUBLANG_ARABIC_SAUDI_ARABIA: return "ar_SA";
  1076. case SUBLANG_ARABIC_IRAQ: return "ar_IQ";
  1077. case SUBLANG_ARABIC_EGYPT: return "ar_EG";
  1078. case SUBLANG_ARABIC_LIBYA: return "ar_LY";
  1079. case SUBLANG_ARABIC_ALGERIA: return "ar_DZ";
  1080. case SUBLANG_ARABIC_MOROCCO: return "ar_MA";
  1081. case SUBLANG_ARABIC_TUNISIA: return "ar_TN";
  1082. case SUBLANG_ARABIC_OMAN: return "ar_OM";
  1083. case SUBLANG_ARABIC_YEMEN: return "ar_YE";
  1084. case SUBLANG_ARABIC_SYRIA: return "ar_SY";
  1085. case SUBLANG_ARABIC_JORDAN: return "ar_JO";
  1086. case SUBLANG_ARABIC_LEBANON: return "ar_LB";
  1087. case SUBLANG_ARABIC_KUWAIT: return "ar_KW";
  1088. case SUBLANG_ARABIC_UAE: return "ar_AE";
  1089. case SUBLANG_ARABIC_BAHRAIN: return "ar_BH";
  1090. case SUBLANG_ARABIC_QATAR: return "ar_QA";
  1091. }
  1092. return "ar";
  1093. case LANG_ARMENIAN: return "hy_AM";
  1094. case LANG_ASSAMESE: return "as_IN";
  1095. case LANG_AZERI:
  1096. switch (sub)
  1097. {
  1098. /* FIXME: Adjust this when Azerbaijani locales appear on Unix. */
  1099. case SUBLANG_AZERI_LATIN: return "az_AZ@latin";
  1100. case SUBLANG_AZERI_CYRILLIC: return "az_AZ@cyrillic";
  1101. }
  1102. return "az";
  1103. case LANG_BASQUE:
  1104. switch (sub)
  1105. {
  1106. case SUBLANG_DEFAULT: return "eu_ES";
  1107. }
  1108. return "eu"; /* Ambiguous: could be "eu_ES" or "eu_FR". */
  1109. case LANG_BELARUSIAN: return "be_BY";
  1110. case LANG_BENGALI:
  1111. switch (sub)
  1112. {
  1113. case SUBLANG_BENGALI_INDIA: return "bn_IN";
  1114. case SUBLANG_BENGALI_BANGLADESH: return "bn_BD";
  1115. }
  1116. return "bn";
  1117. case LANG_BULGARIAN: return "bg_BG";
  1118. case LANG_BURMESE: return "my_MM";
  1119. case LANG_CAMBODIAN: return "km_KH";
  1120. case LANG_CATALAN: return "ca_ES";
  1121. case LANG_CHEROKEE: return "chr_US";
  1122. case LANG_CHINESE:
  1123. switch (sub)
  1124. {
  1125. case SUBLANG_CHINESE_TRADITIONAL: return "zh_TW";
  1126. case SUBLANG_CHINESE_SIMPLIFIED: return "zh_CN";
  1127. case SUBLANG_CHINESE_HONGKONG: return "zh_HK";
  1128. case SUBLANG_CHINESE_SINGAPORE: return "zh_SG";
  1129. case SUBLANG_CHINESE_MACAU: return "zh_MO";
  1130. }
  1131. return "zh";
  1132. case LANG_CROATIAN: /* LANG_CROATIAN == LANG_SERBIAN
  1133. * What used to be called Serbo-Croatian
  1134. * should really now be two separate
  1135. * languages because of political reasons.
  1136. * (Says tml, who knows nothing about Serbian
  1137. * or Croatian.)
  1138. * (I can feel those flames coming already.)
  1139. */
  1140. switch (sub)
  1141. {
  1142. case SUBLANG_DEFAULT: return "hr_HR";
  1143. case SUBLANG_SERBIAN_LATIN: return "sr_CS";
  1144. case SUBLANG_SERBIAN_CYRILLIC: return "sr_CS@cyrillic";
  1145. }
  1146. return "hr";
  1147. case LANG_CZECH: return "cs_CZ";
  1148. case LANG_DANISH: return "da_DK";
  1149. case LANG_DIVEHI: return "dv_MV";
  1150. case LANG_DUTCH:
  1151. switch (sub)
  1152. {
  1153. case SUBLANG_DUTCH: return "nl_NL";
  1154. case SUBLANG_DUTCH_BELGIAN: /* FLEMISH, VLAAMS */ return "nl_BE";
  1155. }
  1156. return "nl";
  1157. case LANG_EDO: return "bin_NG";
  1158. case LANG_ENGLISH:
  1159. switch (sub)
  1160. {
  1161. /* SUBLANG_ENGLISH_US == SUBLANG_DEFAULT. Heh. I thought
  1162. * English was the language spoken in England.
  1163. * Oh well.
  1164. */
  1165. case SUBLANG_ENGLISH_US: return "en_US";
  1166. case SUBLANG_ENGLISH_UK: return "en_GB";
  1167. case SUBLANG_ENGLISH_AUS: return "en_AU";
  1168. case SUBLANG_ENGLISH_CAN: return "en_CA";
  1169. case SUBLANG_ENGLISH_NZ: return "en_NZ";
  1170. case SUBLANG_ENGLISH_EIRE: return "en_IE";
  1171. case SUBLANG_ENGLISH_SOUTH_AFRICA: return "en_ZA";
  1172. case SUBLANG_ENGLISH_JAMAICA: return "en_JM";
  1173. case SUBLANG_ENGLISH_CARIBBEAN: return "en_GD"; /* Grenada? */
  1174. case SUBLANG_ENGLISH_BELIZE: return "en_BZ";
  1175. case SUBLANG_ENGLISH_TRINIDAD: return "en_TT";
  1176. case SUBLANG_ENGLISH_ZIMBABWE: return "en_ZW";
  1177. case SUBLANG_ENGLISH_PHILIPPINES: return "en_PH";
  1178. case SUBLANG_ENGLISH_INDONESIA: return "en_ID";
  1179. case SUBLANG_ENGLISH_HONGKONG: return "en_HK";
  1180. case SUBLANG_ENGLISH_INDIA: return "en_IN";
  1181. case SUBLANG_ENGLISH_MALAYSIA: return "en_MY";
  1182. case SUBLANG_ENGLISH_SINGAPORE: return "en_SG";
  1183. }
  1184. return "en";
  1185. case LANG_ESTONIAN: return "et_EE";
  1186. case LANG_FAEROESE: return "fo_FO";
  1187. case LANG_FARSI: return "fa_IR";
  1188. case LANG_FINNISH: return "fi_FI";
  1189. case LANG_FRENCH:
  1190. switch (sub)
  1191. {
  1192. case SUBLANG_FRENCH: return "fr_FR";
  1193. case SUBLANG_FRENCH_BELGIAN: /* WALLOON */ return "fr_BE";
  1194. case SUBLANG_FRENCH_CANADIAN: return "fr_CA";
  1195. case SUBLANG_FRENCH_SWISS: return "fr_CH";
  1196. case SUBLANG_FRENCH_LUXEMBOURG: return "fr_LU";
  1197. case SUBLANG_FRENCH_MONACO: return "fr_MC";
  1198. case SUBLANG_FRENCH_WESTINDIES: return "fr"; /* Caribbean? */
  1199. case SUBLANG_FRENCH_REUNION: return "fr_RE";
  1200. case SUBLANG_FRENCH_CONGO: return "fr_CG";
  1201. case SUBLANG_FRENCH_SENEGAL: return "fr_SN";
  1202. case SUBLANG_FRENCH_CAMEROON: return "fr_CM";
  1203. case SUBLANG_FRENCH_COTEDIVOIRE: return "fr_CI";
  1204. case SUBLANG_FRENCH_MALI: return "fr_ML";
  1205. case SUBLANG_FRENCH_MOROCCO: return "fr_MA";
  1206. case SUBLANG_FRENCH_HAITI: return "fr_HT";
  1207. }
  1208. return "fr";
  1209. case LANG_FRISIAN: return "fy_NL";
  1210. case LANG_FULFULDE:
  1211. /* Spoken in Nigeria, Guinea, Senegal, Mali, Niger, Cameroon, Benin. */
  1212. return "ff_NG";
  1213. case LANG_GAELIC:
  1214. switch (sub)
  1215. {
  1216. case 0x01: /* SCOTTISH */ return "gd_GB";
  1217. case 0x02: /* IRISH */ return "ga_IE";
  1218. }
  1219. return "C";
  1220. case LANG_GALICIAN: return "gl_ES";
  1221. case LANG_GEORGIAN: return "ka_GE";
  1222. case LANG_GERMAN:
  1223. switch (sub)
  1224. {
  1225. case SUBLANG_GERMAN: return "de_DE";
  1226. case SUBLANG_GERMAN_SWISS: return "de_CH";
  1227. case SUBLANG_GERMAN_AUSTRIAN: return "de_AT";
  1228. case SUBLANG_GERMAN_LUXEMBOURG: return "de_LU";
  1229. case SUBLANG_GERMAN_LIECHTENSTEIN: return "de_LI";
  1230. }
  1231. return "de";
  1232. case LANG_GREEK: return "el_GR";
  1233. case LANG_GUARANI: return "gn_PY";
  1234. case LANG_GUJARATI: return "gu_IN";
  1235. case LANG_HAUSA: return "ha_NG";
  1236. case LANG_HAWAIIAN:
  1237. /* FIXME: Do they mean Hawaiian ("haw_US", 1000 speakers)
  1238. or Hawaii Creole English ("cpe_US", 600000 speakers)? */
  1239. return "cpe_US";
  1240. case LANG_HEBREW: return "he_IL";
  1241. case LANG_HINDI: return "hi_IN";
  1242. case LANG_HUNGARIAN: return "hu_HU";
  1243. case LANG_IBIBIO: return "nic_NG";
  1244. case LANG_ICELANDIC: return "is_IS";
  1245. case LANG_IGBO: return "ig_NG";
  1246. case LANG_INDONESIAN: return "id_ID";
  1247. case LANG_INUKTITUT: return "iu_CA";
  1248. case LANG_ITALIAN:
  1249. switch (sub)
  1250. {
  1251. case SUBLANG_ITALIAN: return "it_IT";
  1252. case SUBLANG_ITALIAN_SWISS: return "it_CH";
  1253. }
  1254. return "it";
  1255. case LANG_JAPANESE: return "ja_JP";
  1256. case LANG_KANNADA: return "kn_IN";
  1257. case LANG_KANURI: return "kr_NG";
  1258. case LANG_KASHMIRI:
  1259. switch (sub)
  1260. {
  1261. case SUBLANG_DEFAULT: return "ks_PK";
  1262. case SUBLANG_KASHMIRI_INDIA: return "ks_IN";
  1263. }
  1264. return "ks";
  1265. case LANG_KAZAK: return "kk_KZ";
  1266. case LANG_KONKANI:
  1267. /* FIXME: Adjust this when such locales appear on Unix. */
  1268. return "kok_IN";
  1269. case LANG_KOREAN: return "ko_KR";
  1270. case LANG_KYRGYZ: return "ky_KG";
  1271. case LANG_LAO: return "lo_LA";
  1272. case LANG_LATIN: return "la_VA";
  1273. case LANG_LATVIAN: return "lv_LV";
  1274. case LANG_LITHUANIAN: return "lt_LT";
  1275. case LANG_MACEDONIAN: return "mk_MK";
  1276. case LANG_MALAY:
  1277. switch (sub)
  1278. {
  1279. case SUBLANG_MALAY_MALAYSIA: return "ms_MY";
  1280. case SUBLANG_MALAY_BRUNEI_DARUSSALAM: return "ms_BN";
  1281. }
  1282. return "ms";
  1283. case LANG_MALAYALAM: return "ml_IN";
  1284. case LANG_MALTESE: return "mt_MT";
  1285. case LANG_MANIPURI:
  1286. /* FIXME: Adjust this when such locales appear on Unix. */
  1287. return "mni_IN";
  1288. case LANG_MARATHI: return "mr_IN";
  1289. case LANG_MONGOLIAN:
  1290. switch (sub)
  1291. {
  1292. case SUBLANG_DEFAULT: return "mn_MN";
  1293. }
  1294. return "mn"; /* Ambiguous: could be "mn_CN" or "mn_MN". */
  1295. case LANG_NEPALI:
  1296. switch (sub)
  1297. {
  1298. case SUBLANG_DEFAULT: return "ne_NP";
  1299. case SUBLANG_NEPALI_INDIA: return "ne_IN";
  1300. }
  1301. return "ne";
  1302. case LANG_NORWEGIAN:
  1303. switch (sub)
  1304. {
  1305. case SUBLANG_NORWEGIAN_BOKMAL: return "nb_NO";
  1306. case SUBLANG_NORWEGIAN_NYNORSK: return "nn_NO";
  1307. }
  1308. return "no";
  1309. case LANG_ORIYA: return "or_IN";
  1310. case LANG_OROMO: return "om_ET";
  1311. case LANG_PAPIAMENTU: return "pap_AN";
  1312. case LANG_PASHTO:
  1313. return "ps"; /* Ambiguous: could be "ps_PK" or "ps_AF". */
  1314. case LANG_POLISH: return "pl_PL";
  1315. case LANG_PORTUGUESE:
  1316. switch (sub)
  1317. {
  1318. case SUBLANG_PORTUGUESE: return "pt_PT";
  1319. /* Hmm. SUBLANG_PORTUGUESE_BRAZILIAN == SUBLANG_DEFAULT.
  1320. Same phenomenon as SUBLANG_ENGLISH_US == SUBLANG_DEFAULT. */
  1321. case SUBLANG_PORTUGUESE_BRAZILIAN: return "pt_BR";
  1322. }
  1323. return "pt";
  1324. case LANG_PUNJABI:
  1325. switch (sub)
  1326. {
  1327. case SUBLANG_PUNJABI_INDIA: return "pa_IN"; /* Gurmukhi script */
  1328. case SUBLANG_PUNJABI_PAKISTAN: return "pa_PK"; /* Arabic script */
  1329. }
  1330. return "pa";
  1331. case LANG_RHAETO_ROMANCE: return "rm_CH";
  1332. case LANG_ROMANIAN:
  1333. switch (sub)
  1334. {
  1335. case SUBLANG_ROMANIAN_ROMANIA: return "ro_RO";
  1336. case SUBLANG_ROMANIAN_MOLDOVA: return "ro_MD";
  1337. }
  1338. return "ro";
  1339. case LANG_RUSSIAN:
  1340. switch (sub)
  1341. {
  1342. case SUBLANG_DEFAULT: return "ru_RU";
  1343. }
  1344. return "ru"; /* Ambiguous: could be "ru_RU" or "ru_UA" or "ru_MD". */
  1345. case LANG_SAAMI: /* actually Northern Sami */ return "se_NO";
  1346. case LANG_SANSKRIT: return "sa_IN";
  1347. case LANG_SINDHI:
  1348. switch (sub)
  1349. {
  1350. case SUBLANG_SINDHI_PAKISTAN: return "sd_PK";
  1351. case SUBLANG_SINDHI_AFGHANISTAN: return "sd_AF";
  1352. }
  1353. return "sd";
  1354. case LANG_SINHALESE: return "si_LK";
  1355. case LANG_SLOVAK: return "sk_SK";
  1356. case LANG_SLOVENIAN: return "sl_SI";
  1357. case LANG_SOMALI: return "so_SO";
  1358. case LANG_SORBIAN:
  1359. /* FIXME: Adjust this when such locales appear on Unix. */
  1360. return "wen_DE";
  1361. case LANG_SPANISH:
  1362. switch (sub)
  1363. {
  1364. case SUBLANG_SPANISH: return "es_ES";
  1365. case SUBLANG_SPANISH_MEXICAN: return "es_MX";
  1366. case SUBLANG_SPANISH_MODERN:
  1367. return "es_ES@modern"; /* not seen on Unix */
  1368. case SUBLANG_SPANISH_GUATEMALA: return "es_GT";
  1369. case SUBLANG_SPANISH_COSTA_RICA: return "es_CR";
  1370. case SUBLANG_SPANISH_PANAMA: return "es_PA";
  1371. case SUBLANG_SPANISH_DOMINICAN_REPUBLIC: return "es_DO";
  1372. case SUBLANG_SPANISH_VENEZUELA: return "es_VE";
  1373. case SUBLANG_SPANISH_COLOMBIA: return "es_CO";
  1374. case SUBLANG_SPANISH_PERU: return "es_PE";
  1375. case SUBLANG_SPANISH_ARGENTINA: return "es_AR";
  1376. case SUBLANG_SPANISH_ECUADOR: return "es_EC";
  1377. case SUBLANG_SPANISH_CHILE: return "es_CL";
  1378. case SUBLANG_SPANISH_URUGUAY: return "es_UY";
  1379. case SUBLANG_SPANISH_PARAGUAY: return "es_PY";
  1380. case SUBLANG_SPANISH_BOLIVIA: return "es_BO";
  1381. case SUBLANG_SPANISH_EL_SALVADOR: return "es_SV";
  1382. case SUBLANG_SPANISH_HONDURAS: return "es_HN";
  1383. case SUBLANG_SPANISH_NICARAGUA: return "es_NI";
  1384. case SUBLANG_SPANISH_PUERTO_RICO: return "es_PR";
  1385. }
  1386. return "es";
  1387. case LANG_SUTU: return "bnt_TZ"; /* or "st_LS" or "nso_ZA"? */
  1388. case LANG_SWAHILI: return "sw_KE";
  1389. case LANG_SWEDISH:
  1390. switch (sub)
  1391. {
  1392. case SUBLANG_DEFAULT: return "sv_SE";
  1393. case SUBLANG_SWEDISH_FINLAND: return "sv_FI";
  1394. }
  1395. return "sv";
  1396. case LANG_SYRIAC: return "syr_TR"; /* An extinct language. */
  1397. case LANG_TAGALOG: return "tl_PH";
  1398. case LANG_TAJIK: return "tg_TJ";
  1399. case LANG_TAMAZIGHT:
  1400. switch (sub)
  1401. {
  1402. /* FIXME: Adjust this when Tamazight locales appear on Unix. */
  1403. case SUBLANG_TAMAZIGHT_ARABIC: return "ber_MA@arabic";
  1404. case SUBLANG_TAMAZIGHT_ALGERIA_LATIN: return "ber_DZ@latin";
  1405. }
  1406. return "ber_MA";
  1407. case LANG_TAMIL:
  1408. switch (sub)
  1409. {
  1410. case SUBLANG_DEFAULT: return "ta_IN";
  1411. }
  1412. return "ta"; /* Ambiguous: could be "ta_IN" or "ta_LK" or "ta_SG". */
  1413. case LANG_TATAR: return "tt_RU";
  1414. case LANG_TELUGU: return "te_IN";
  1415. case LANG_THAI: return "th_TH";
  1416. case LANG_TIBETAN: return "bo_CN";
  1417. case LANG_TIGRINYA:
  1418. switch (sub)
  1419. {
  1420. case SUBLANG_TIGRINYA_ETHIOPIA: return "ti_ET";
  1421. case SUBLANG_TIGRINYA_ERITREA: return "ti_ER";
  1422. }
  1423. return "ti";
  1424. case LANG_TSONGA: return "ts_ZA";
  1425. case LANG_TSWANA: return "tn_BW";
  1426. case LANG_TURKISH: return "tr_TR";
  1427. case LANG_TURKMEN: return "tk_TM";
  1428. case LANG_UKRAINIAN: return "uk_UA";
  1429. case LANG_URDU:
  1430. switch (sub)
  1431. {
  1432. case SUBLANG_URDU_PAKISTAN: return "ur_PK";
  1433. case SUBLANG_URDU_INDIA: return "ur_IN";
  1434. }
  1435. return "ur";
  1436. case LANG_UZBEK:
  1437. switch (sub)
  1438. {
  1439. case SUBLANG_UZBEK_LATIN: return "uz_UZ";
  1440. case SUBLANG_UZBEK_CYRILLIC: return "uz_UZ@cyrillic";
  1441. }
  1442. return "uz";
  1443. case LANG_VENDA: return "ve_ZA";
  1444. case LANG_VIETNAMESE: return "vi_VN";
  1445. case LANG_WELSH: return "cy_GB";
  1446. case LANG_XHOSA: return "xh_ZA";
  1447. case LANG_YI: return "sit_CN";
  1448. case LANG_YIDDISH: return "yi_IL";
  1449. case LANG_YORUBA: return "yo_NG";
  1450. case LANG_ZULU: return "zu_ZA";
  1451. default: return "C";
  1452. }
  1453. }
  1454. # endif
  1455. #endif
  1456. }
  1457. const char *
  1458. gl_locale_name (int category, const char *categoryname)
  1459. {
  1460. const char *retval;
  1461. retval = gl_locale_name_posix (category, categoryname);
  1462. if (retval != NULL)
  1463. return retval;
  1464. return gl_locale_name_default ();
  1465. }