Debian Codegraph @

lib/localename-unsafe.c

raw
1 /* Determine name of the currently selected locale.
2 Copyright (C) 1995-2025 Free Software Foundation, Inc.
3
4 This file is free software: you can redistribute it and/or modify
5 it under the terms of the GNU Lesser General Public License as
6 published by the Free Software Foundation; either version 2.1 of the
7 License, or (at your option) any later version.
8
9 This file is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public License
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
16
17 /* Written by Ulrich Drepper <[email protected]>, 1995. */
18 /* Native Windows code written by Tor Lillqvist <[email protected]>. */
19 /* Mac OS X code written by Bruno Haible <[email protected]>. */
20
21 /* Don't use __attribute__ __nonnull__ in this compilation unit. Otherwise gcc
22 optimizes away the locale == NULL tests below in duplocale() and freelocale(),
23 or xlclang reports -Wtautological-pointer-compare warnings for these tests.
24 */
25 #define _GL_ARG_NONNULL(params)
26
27 #include <config.h>
28
29 /* Specification. */
30 #include "localename.h"
31
32 #include <stddef.h>
33 #include <stdlib.h>
34 #include <locale.h>
35 #include <string.h>
36
37 #include "getlocalename_l-unsafe.h"
38 #include "setlocale_null.h"
39
40 #if HAVE_GOOD_USELOCALE
41 /* Mac OS X 10.5 defines the locale_t type in <xlocale.h>. */
42 # if defined __APPLE__ && defined __MACH__
43 # include <xlocale.h>
44 # endif
45 #endif
46
47 #if HAVE_CFPREFERENCESCOPYAPPVALUE
48 # include <CoreFoundation/CFString.h>
49 # include <CoreFoundation/CFPreferences.h>
50 #endif
51
52 #if defined _WIN32 && !defined __CYGWIN__
53 # define WINDOWS_NATIVE
54 # include "glthread/lock.h"
55 #endif
56
57 #if defined WINDOWS_NATIVE || defined __CYGWIN__ /* Native Windows or Cygwin */
58 # define WIN32_LEAN_AND_MEAN
59 # include <windows.h>
60 # include <winnls.h>
61 /* List of language codes, sorted by value:
62 0x01 LANG_ARABIC
63 0x02 LANG_BULGARIAN
64 0x03 LANG_CATALAN
65 0x04 LANG_CHINESE
66 0x05 LANG_CZECH
67 0x06 LANG_DANISH
68 0x07 LANG_GERMAN
69 0x08 LANG_GREEK
70 0x09 LANG_ENGLISH
71 0x0a LANG_SPANISH
72 0x0b LANG_FINNISH
73 0x0c LANG_FRENCH
74 0x0d LANG_HEBREW
75 0x0e LANG_HUNGARIAN
76 0x0f LANG_ICELANDIC
77 0x10 LANG_ITALIAN
78 0x11 LANG_JAPANESE
79 0x12 LANG_KOREAN
80 0x13 LANG_DUTCH
81 0x14 LANG_NORWEGIAN
82 0x15 LANG_POLISH
83 0x16 LANG_PORTUGUESE
84 0x17 LANG_ROMANSH
85 0x18 LANG_ROMANIAN
86 0x19 LANG_RUSSIAN
87 0x1a LANG_CROATIAN == LANG_SERBIAN
88 0x1b LANG_SLOVAK
89 0x1c LANG_ALBANIAN
90 0x1d LANG_SWEDISH
91 0x1e LANG_THAI
92 0x1f LANG_TURKISH
93 0x20 LANG_URDU
94 0x21 LANG_INDONESIAN
95 0x22 LANG_UKRAINIAN
96 0x23 LANG_BELARUSIAN
97 0x24 LANG_SLOVENIAN
98 0x25 LANG_ESTONIAN
99 0x26 LANG_LATVIAN
100 0x27 LANG_LITHUANIAN
101 0x28 LANG_TAJIK
102 0x29 LANG_FARSI
103 0x2a LANG_VIETNAMESE
104 0x2b LANG_ARMENIAN
105 0x2c LANG_AZERI
106 0x2d LANG_BASQUE
107 0x2e LANG_SORBIAN
108 0x2f LANG_MACEDONIAN
109 0x30 LANG_SUTU
110 0x31 LANG_TSONGA
111 0x32 LANG_TSWANA
112 0x33 LANG_VENDA
113 0x34 LANG_XHOSA
114 0x35 LANG_ZULU
115 0x36 LANG_AFRIKAANS
116 0x37 LANG_GEORGIAN
117 0x38 LANG_FAEROESE
118 0x39 LANG_HINDI
119 0x3a LANG_MALTESE
120 0x3b LANG_SAMI
121 0x3c LANG_GAELIC
122 0x3d LANG_YIDDISH
123 0x3e LANG_MALAY
124 0x3f LANG_KAZAK
125 0x40 LANG_KYRGYZ
126 0x41 LANG_SWAHILI
127 0x42 LANG_TURKMEN
128 0x43 LANG_UZBEK
129 0x44 LANG_TATAR
130 0x45 LANG_BENGALI
131 0x46 LANG_PUNJABI
132 0x47 LANG_GUJARATI
133 0x48 LANG_ORIYA
134 0x49 LANG_TAMIL
135 0x4a LANG_TELUGU
136 0x4b LANG_KANNADA
137 0x4c LANG_MALAYALAM
138 0x4d LANG_ASSAMESE
139 0x4e LANG_MARATHI
140 0x4f LANG_SANSKRIT
141 0x50 LANG_MONGOLIAN
142 0x51 LANG_TIBETAN
143 0x52 LANG_WELSH
144 0x53 LANG_CAMBODIAN
145 0x54 LANG_LAO
146 0x55 LANG_BURMESE
147 0x56 LANG_GALICIAN
148 0x57 LANG_KONKANI
149 0x58 LANG_MANIPURI
150 0x59 LANG_SINDHI
151 0x5a LANG_SYRIAC
152 0x5b LANG_SINHALESE
153 0x5c LANG_CHEROKEE
154 0x5d LANG_INUKTITUT
155 0x5e LANG_AMHARIC
156 0x5f LANG_TAMAZIGHT
157 0x60 LANG_KASHMIRI
158 0x61 LANG_NEPALI
159 0x62 LANG_FRISIAN
160 0x63 LANG_PASHTO
161 0x64 LANG_TAGALOG
162 0x65 LANG_DIVEHI
163 0x66 LANG_EDO
164 0x67 LANG_FULFULDE
165 0x68 LANG_HAUSA
166 0x69 LANG_IBIBIO
167 0x6a LANG_YORUBA
168 0x6d LANG_BASHKIR
169 0x6e LANG_LUXEMBOURGISH
170 0x6f LANG_GREENLANDIC
171 0x70 LANG_IGBO
172 0x71 LANG_KANURI
173 0x72 LANG_OROMO
174 0x73 LANG_TIGRINYA
175 0x74 LANG_GUARANI
176 0x75 LANG_HAWAIIAN
177 0x76 LANG_LATIN
178 0x77 LANG_SOMALI
179 0x78 LANG_YI
180 0x79 LANG_PAPIAMENTU
181 0x7a LANG_MAPUDUNGUN
182 0x7c LANG_MOHAWK
183 0x7e LANG_BRETON
184 0x82 LANG_OCCITAN
185 0x83 LANG_CORSICAN
186 0x84 LANG_ALSATIAN
187 0x85 LANG_YAKUT
188 0x86 LANG_KICHE
189 0x87 LANG_KINYARWANDA
190 0x88 LANG_WOLOF
191 0x8c LANG_DARI
192 0x91 LANG_SCOTTISH_GAELIC
193 */
194 /* Mingw headers don't have latest language and sublanguage codes. */
195 # ifndef LANG_AFRIKAANS
196 # define LANG_AFRIKAANS 0x36
197 # endif
198 # ifndef LANG_ALBANIAN
199 # define LANG_ALBANIAN 0x1c
200 # endif
201 # ifndef LANG_ALSATIAN
202 # define LANG_ALSATIAN 0x84
203 # endif
204 # ifndef LANG_AMHARIC
205 # define LANG_AMHARIC 0x5e
206 # endif
207 # ifndef LANG_ARABIC
208 # define LANG_ARABIC 0x01
209 # endif
210 # ifndef LANG_ARMENIAN
211 # define LANG_ARMENIAN 0x2b
212 # endif
213 # ifndef LANG_ASSAMESE
214 # define LANG_ASSAMESE 0x4d
215 # endif
216 # ifndef LANG_AZERI
217 # define LANG_AZERI 0x2c
218 # endif
219 # ifndef LANG_BASHKIR
220 # define LANG_BASHKIR 0x6d
221 # endif
222 # ifndef LANG_BASQUE
223 # define LANG_BASQUE 0x2d
224 # endif
225 # ifndef LANG_BELARUSIAN
226 # define LANG_BELARUSIAN 0x23
227 # endif
228 # ifndef LANG_BENGALI
229 # define LANG_BENGALI 0x45
230 # endif
231 # ifndef LANG_BRETON
232 # define LANG_BRETON 0x7e
233 # endif
234 # ifndef LANG_BURMESE
235 # define LANG_BURMESE 0x55
236 # endif
237 # ifndef LANG_CAMBODIAN
238 # define LANG_CAMBODIAN 0x53
239 # endif
240 # ifndef LANG_CATALAN
241 # define LANG_CATALAN 0x03
242 # endif
243 # ifndef LANG_CHEROKEE
244 # define LANG_CHEROKEE 0x5c
245 # endif
246 # ifndef LANG_CORSICAN
247 # define LANG_CORSICAN 0x83
248 # endif
249 # ifndef LANG_DARI
250 # define LANG_DARI 0x8c
251 # endif
252 # ifndef LANG_DIVEHI
253 # define LANG_DIVEHI 0x65
254 # endif
255 # ifndef LANG_EDO
256 # define LANG_EDO 0x66
257 # endif
258 # ifndef LANG_ESTONIAN
259 # define LANG_ESTONIAN 0x25
260 # endif
261 # ifndef LANG_FAEROESE
262 # define LANG_FAEROESE 0x38
263 # endif
264 # ifndef LANG_FARSI
265 # define LANG_FARSI 0x29
266 # endif
267 # ifndef LANG_FRISIAN
268 # define LANG_FRISIAN 0x62
269 # endif
270 # ifndef LANG_FULFULDE
271 # define LANG_FULFULDE 0x67
272 # endif
273 # ifndef LANG_GAELIC
274 # define LANG_GAELIC 0x3c
275 # endif
276 # ifndef LANG_GALICIAN
277 # define LANG_GALICIAN 0x56
278 # endif
279 # ifndef LANG_GEORGIAN
280 # define LANG_GEORGIAN 0x37
281 # endif
282 # ifndef LANG_GREENLANDIC
283 # define LANG_GREENLANDIC 0x6f
284 # endif
285 # ifndef LANG_GUARANI
286 # define LANG_GUARANI 0x74
287 # endif
288 # ifndef LANG_GUJARATI
289 # define LANG_GUJARATI 0x47
290 # endif
291 # ifndef LANG_HAUSA
292 # define LANG_HAUSA 0x68
293 # endif
294 # ifndef LANG_HAWAIIAN
295 # define LANG_HAWAIIAN 0x75
296 # endif
297 # ifndef LANG_HEBREW
298 # define LANG_HEBREW 0x0d
299 # endif
300 # ifndef LANG_HINDI
301 # define LANG_HINDI 0x39
302 # endif
303 # ifndef LANG_IBIBIO
304 # define LANG_IBIBIO 0x69
305 # endif
306 # ifndef LANG_IGBO
307 # define LANG_IGBO 0x70
308 # endif
309 # ifndef LANG_INDONESIAN
310 # define LANG_INDONESIAN 0x21
311 # endif
312 # ifndef LANG_INUKTITUT
313 # define LANG_INUKTITUT 0x5d
314 # endif
315 # ifndef LANG_KANNADA
316 # define LANG_KANNADA 0x4b
317 # endif
318 # ifndef LANG_KANURI
319 # define LANG_KANURI 0x71
320 # endif
321 # ifndef LANG_KASHMIRI
322 # define LANG_KASHMIRI 0x60
323 # endif
324 # ifndef LANG_KAZAK
325 # define LANG_KAZAK 0x3f
326 # endif
327 # ifndef LANG_KICHE
328 # define LANG_KICHE 0x86
329 # endif
330 # ifndef LANG_KINYARWANDA
331 # define LANG_KINYARWANDA 0x87
332 # endif
333 # ifndef LANG_KONKANI
334 # define LANG_KONKANI 0x57
335 # endif
336 # ifndef LANG_KYRGYZ
337 # define LANG_KYRGYZ 0x40
338 # endif
339 # ifndef LANG_LAO
340 # define LANG_LAO 0x54
341 # endif
342 # ifndef LANG_LATIN
343 # define LANG_LATIN 0x76
344 # endif
345 # ifndef LANG_LATVIAN
346 # define LANG_LATVIAN 0x26
347 # endif
348 # ifndef LANG_LITHUANIAN
349 # define LANG_LITHUANIAN 0x27
350 # endif
351 # ifndef LANG_LUXEMBOURGISH
352 # define LANG_LUXEMBOURGISH 0x6e
353 # endif
354 # ifndef LANG_MACEDONIAN
355 # define LANG_MACEDONIAN 0x2f
356 # endif
357 # ifndef LANG_MALAY
358 # define LANG_MALAY 0x3e
359 # endif
360 # ifndef LANG_MALAYALAM
361 # define LANG_MALAYALAM 0x4c
362 # endif
363 # ifndef LANG_MALTESE
364 # define LANG_MALTESE 0x3a
365 # endif
366 # ifndef LANG_MANIPURI
367 # define LANG_MANIPURI 0x58
368 # endif
369 # ifndef LANG_MAORI
370 # define LANG_MAORI 0x81
371 # endif
372 # ifndef LANG_MAPUDUNGUN
373 # define LANG_MAPUDUNGUN 0x7a
374 # endif
375 # ifndef LANG_MARATHI
376 # define LANG_MARATHI 0x4e
377 # endif
378 # ifndef LANG_MOHAWK
379 # define LANG_MOHAWK 0x7c
380 # endif
381 # ifndef LANG_MONGOLIAN
382 # define LANG_MONGOLIAN 0x50
383 # endif
384 # ifndef LANG_NEPALI
385 # define LANG_NEPALI 0x61
386 # endif
387 # ifndef LANG_OCCITAN
388 # define LANG_OCCITAN 0x82
389 # endif
390 # ifndef LANG_ORIYA
391 # define LANG_ORIYA 0x48
392 # endif
393 # ifndef LANG_OROMO
394 # define LANG_OROMO 0x72
395 # endif
396 # ifndef LANG_PAPIAMENTU
397 # define LANG_PAPIAMENTU 0x79
398 # endif
399 # ifndef LANG_PASHTO
400 # define LANG_PASHTO 0x63
401 # endif
402 # ifndef LANG_PUNJABI
403 # define LANG_PUNJABI 0x46
404 # endif
405 # ifndef LANG_QUECHUA
406 # define LANG_QUECHUA 0x6b
407 # endif
408 # ifndef LANG_ROMANSH
409 # define LANG_ROMANSH 0x17
410 # endif
411 # ifndef LANG_SAMI
412 # define LANG_SAMI 0x3b
413 # endif
414 # ifndef LANG_SANSKRIT
415 # define LANG_SANSKRIT 0x4f
416 # endif
417 # ifndef LANG_SCOTTISH_GAELIC
418 # define LANG_SCOTTISH_GAELIC 0x91
419 # endif
420 # ifndef LANG_SERBIAN
421 # define LANG_SERBIAN 0x1a
422 # endif
423 # ifndef LANG_SINDHI
424 # define LANG_SINDHI 0x59
425 # endif
426 # ifndef LANG_SINHALESE
427 # define LANG_SINHALESE 0x5b
428 # endif
429 # ifndef LANG_SLOVAK
430 # define LANG_SLOVAK 0x1b
431 # endif
432 # ifndef LANG_SOMALI
433 # define LANG_SOMALI 0x77
434 # endif
435 # ifndef LANG_SORBIAN
436 # define LANG_SORBIAN 0x2e
437 # endif
438 # ifndef LANG_SOTHO
439 # define LANG_SOTHO 0x6c
440 # endif
441 # ifndef LANG_SUTU
442 # define LANG_SUTU 0x30
443 # endif
444 # ifndef LANG_SWAHILI
445 # define LANG_SWAHILI 0x41
446 # endif
447 # ifndef LANG_SYRIAC
448 # define LANG_SYRIAC 0x5a
449 # endif
450 # ifndef LANG_TAGALOG
451 # define LANG_TAGALOG 0x64
452 # endif
453 # ifndef LANG_TAJIK
454 # define LANG_TAJIK 0x28
455 # endif
456 # ifndef LANG_TAMAZIGHT
457 # define LANG_TAMAZIGHT 0x5f
458 # endif
459 # ifndef LANG_TAMIL
460 # define LANG_TAMIL 0x49
461 # endif
462 # ifndef LANG_TATAR
463 # define LANG_TATAR 0x44
464 # endif
465 # ifndef LANG_TELUGU
466 # define LANG_TELUGU 0x4a
467 # endif
468 # ifndef LANG_THAI
469 # define LANG_THAI 0x1e
470 # endif
471 # ifndef LANG_TIBETAN
472 # define LANG_TIBETAN 0x51
473 # endif
474 # ifndef LANG_TIGRINYA
475 # define LANG_TIGRINYA 0x73
476 # endif
477 # ifndef LANG_TSONGA
478 # define LANG_TSONGA 0x31
479 # endif
480 # ifndef LANG_TSWANA
481 # define LANG_TSWANA 0x32
482 # endif
483 # ifndef LANG_TURKMEN
484 # define LANG_TURKMEN 0x42
485 # endif
486 # ifndef LANG_UIGHUR
487 # define LANG_UIGHUR 0x80
488 # endif
489 # ifndef LANG_UKRAINIAN
490 # define LANG_UKRAINIAN 0x22
491 # endif
492 # ifndef LANG_URDU
493 # define LANG_URDU 0x20
494 # endif
495 # ifndef LANG_UZBEK
496 # define LANG_UZBEK 0x43
497 # endif
498 # ifndef LANG_VENDA
499 # define LANG_VENDA 0x33
500 # endif
501 # ifndef LANG_VIETNAMESE
502 # define LANG_VIETNAMESE 0x2a
503 # endif
504 # ifndef LANG_WELSH
505 # define LANG_WELSH 0x52
506 # endif
507 # ifndef LANG_WOLOF
508 # define LANG_WOLOF 0x88
509 # endif
510 # ifndef LANG_XHOSA
511 # define LANG_XHOSA 0x34
512 # endif
513 # ifndef LANG_YAKUT
514 # define LANG_YAKUT 0x85
515 # endif
516 # ifndef LANG_YI
517 # define LANG_YI 0x78
518 # endif
519 # ifndef LANG_YIDDISH
520 # define LANG_YIDDISH 0x3d
521 # endif
522 # ifndef LANG_YORUBA
523 # define LANG_YORUBA 0x6a
524 # endif
525 # ifndef LANG_ZULU
526 # define LANG_ZULU 0x35
527 # endif
528 # ifndef SUBLANG_AFRIKAANS_SOUTH_AFRICA
529 # define SUBLANG_AFRIKAANS_SOUTH_AFRICA 0x01
530 # endif
531 # ifndef SUBLANG_ALBANIAN_ALBANIA
532 # define SUBLANG_ALBANIAN_ALBANIA 0x01
533 # endif
534 # ifndef SUBLANG_ALSATIAN_FRANCE
535 # define SUBLANG_ALSATIAN_FRANCE 0x01
536 # endif
537 # ifndef SUBLANG_AMHARIC_ETHIOPIA
538 # define SUBLANG_AMHARIC_ETHIOPIA 0x01
539 # endif
540 # ifndef SUBLANG_ARABIC_SAUDI_ARABIA
541 # define SUBLANG_ARABIC_SAUDI_ARABIA 0x01
542 # endif
543 # ifndef SUBLANG_ARABIC_IRAQ
544 # define SUBLANG_ARABIC_IRAQ 0x02
545 # endif
546 # ifndef SUBLANG_ARABIC_EGYPT
547 # define SUBLANG_ARABIC_EGYPT 0x03
548 # endif
549 # ifndef SUBLANG_ARABIC_LIBYA
550 # define SUBLANG_ARABIC_LIBYA 0x04
551 # endif
552 # ifndef SUBLANG_ARABIC_ALGERIA
553 # define SUBLANG_ARABIC_ALGERIA 0x05
554 # endif
555 # ifndef SUBLANG_ARABIC_MOROCCO
556 # define SUBLANG_ARABIC_MOROCCO 0x06
557 # endif
558 # ifndef SUBLANG_ARABIC_TUNISIA
559 # define SUBLANG_ARABIC_TUNISIA 0x07
560 # endif
561 # ifndef SUBLANG_ARABIC_OMAN
562 # define SUBLANG_ARABIC_OMAN 0x08
563 # endif
564 # ifndef SUBLANG_ARABIC_YEMEN
565 # define SUBLANG_ARABIC_YEMEN 0x09
566 # endif
567 # ifndef SUBLANG_ARABIC_SYRIA
568 # define SUBLANG_ARABIC_SYRIA 0x0a
569 # endif
570 # ifndef SUBLANG_ARABIC_JORDAN
571 # define SUBLANG_ARABIC_JORDAN 0x0b
572 # endif
573 # ifndef SUBLANG_ARABIC_LEBANON
574 # define SUBLANG_ARABIC_LEBANON 0x0c
575 # endif
576 # ifndef SUBLANG_ARABIC_KUWAIT
577 # define SUBLANG_ARABIC_KUWAIT 0x0d
578 # endif
579 # ifndef SUBLANG_ARABIC_UAE
580 # define SUBLANG_ARABIC_UAE 0x0e
581 # endif
582 # ifndef SUBLANG_ARABIC_BAHRAIN
583 # define SUBLANG_ARABIC_BAHRAIN 0x0f
584 # endif
585 # ifndef SUBLANG_ARABIC_QATAR
586 # define SUBLANG_ARABIC_QATAR 0x10
587 # endif
588 # ifndef SUBLANG_ARMENIAN_ARMENIA
589 # define SUBLANG_ARMENIAN_ARMENIA 0x01
590 # endif
591 # ifndef SUBLANG_ASSAMESE_INDIA
592 # define SUBLANG_ASSAMESE_INDIA 0x01
593 # endif
594 # ifndef SUBLANG_AZERI_LATIN
595 # define SUBLANG_AZERI_LATIN 0x01
596 # endif
597 # ifndef SUBLANG_AZERI_CYRILLIC
598 # define SUBLANG_AZERI_CYRILLIC 0x02
599 # endif
600 # ifndef SUBLANG_BASHKIR_RUSSIA
601 # define SUBLANG_BASHKIR_RUSSIA 0x01
602 # endif
603 # ifndef SUBLANG_BASQUE_BASQUE
604 # define SUBLANG_BASQUE_BASQUE 0x01
605 # endif
606 # ifndef SUBLANG_BELARUSIAN_BELARUS
607 # define SUBLANG_BELARUSIAN_BELARUS 0x01
608 # endif
609 # ifndef SUBLANG_BENGALI_INDIA
610 # define SUBLANG_BENGALI_INDIA 0x01
611 # endif
612 # ifndef SUBLANG_BENGALI_BANGLADESH
613 # define SUBLANG_BENGALI_BANGLADESH 0x02
614 # endif
615 # ifndef SUBLANG_BOSNIAN_BOSNIA_HERZEGOVINA_LATIN
616 # define SUBLANG_BOSNIAN_BOSNIA_HERZEGOVINA_LATIN 0x05
617 # endif
618 # ifndef SUBLANG_BOSNIAN_BOSNIA_HERZEGOVINA_CYRILLIC
619 # define SUBLANG_BOSNIAN_BOSNIA_HERZEGOVINA_CYRILLIC 0x08
620 # endif
621 # ifndef SUBLANG_BRETON_FRANCE
622 # define SUBLANG_BRETON_FRANCE 0x01
623 # endif
624 # ifndef SUBLANG_BULGARIAN_BULGARIA
625 # define SUBLANG_BULGARIAN_BULGARIA 0x01
626 # endif
627 # ifndef SUBLANG_CAMBODIAN_CAMBODIA
628 # define SUBLANG_CAMBODIAN_CAMBODIA 0x01
629 # endif
630 # ifndef SUBLANG_CATALAN_SPAIN
631 # define SUBLANG_CATALAN_SPAIN 0x01
632 # endif
633 # ifndef SUBLANG_CORSICAN_FRANCE
634 # define SUBLANG_CORSICAN_FRANCE 0x01
635 # endif
636 # ifndef SUBLANG_CROATIAN_CROATIA
637 # define SUBLANG_CROATIAN_CROATIA 0x01
638 # endif
639 # ifndef SUBLANG_CROATIAN_BOSNIA_HERZEGOVINA_LATIN
640 # define SUBLANG_CROATIAN_BOSNIA_HERZEGOVINA_LATIN 0x04
641 # endif
642 # ifndef SUBLANG_CHINESE_MACAU
643 # define SUBLANG_CHINESE_MACAU 0x05
644 # endif
645 # ifndef SUBLANG_CZECH_CZECH_REPUBLIC
646 # define SUBLANG_CZECH_CZECH_REPUBLIC 0x01
647 # endif
648 # ifndef SUBLANG_DANISH_DENMARK
649 # define SUBLANG_DANISH_DENMARK 0x01
650 # endif
651 # ifndef SUBLANG_DARI_AFGHANISTAN
652 # define SUBLANG_DARI_AFGHANISTAN 0x01
653 # endif
654 # ifndef SUBLANG_DIVEHI_MALDIVES
655 # define SUBLANG_DIVEHI_MALDIVES 0x01
656 # endif
657 # ifndef SUBLANG_DUTCH_SURINAM
658 # define SUBLANG_DUTCH_SURINAM 0x03
659 # endif
660 # ifndef SUBLANG_ENGLISH_SOUTH_AFRICA
661 # define SUBLANG_ENGLISH_SOUTH_AFRICA 0x07
662 # endif
663 # ifndef SUBLANG_ENGLISH_JAMAICA
664 # define SUBLANG_ENGLISH_JAMAICA 0x08
665 # endif
666 # ifndef SUBLANG_ENGLISH_CARIBBEAN
667 # define SUBLANG_ENGLISH_CARIBBEAN 0x09
668 # endif
669 # ifndef SUBLANG_ENGLISH_BELIZE
670 # define SUBLANG_ENGLISH_BELIZE 0x0a
671 # endif
672 # ifndef SUBLANG_ENGLISH_TRINIDAD
673 # define SUBLANG_ENGLISH_TRINIDAD 0x0b
674 # endif
675 # ifndef SUBLANG_ENGLISH_ZIMBABWE
676 # define SUBLANG_ENGLISH_ZIMBABWE 0x0c
677 # endif
678 # ifndef SUBLANG_ENGLISH_PHILIPPINES
679 # define SUBLANG_ENGLISH_PHILIPPINES 0x0d
680 # endif
681 # ifndef SUBLANG_ENGLISH_INDONESIA
682 # define SUBLANG_ENGLISH_INDONESIA 0x0e
683 # endif
684 # ifndef SUBLANG_ENGLISH_HONGKONG
685 # define SUBLANG_ENGLISH_HONGKONG 0x0f
686 # endif
687 # ifndef SUBLANG_ENGLISH_INDIA
688 # define SUBLANG_ENGLISH_INDIA 0x10
689 # endif
690 # ifndef SUBLANG_ENGLISH_MALAYSIA
691 # define SUBLANG_ENGLISH_MALAYSIA 0x11
692 # endif
693 # ifndef SUBLANG_ENGLISH_SINGAPORE
694 # define SUBLANG_ENGLISH_SINGAPORE 0x12
695 # endif
696 # ifndef SUBLANG_ESTONIAN_ESTONIA
697 # define SUBLANG_ESTONIAN_ESTONIA 0x01
698 # endif
699 # ifndef SUBLANG_FAEROESE_FAROE_ISLANDS
700 # define SUBLANG_FAEROESE_FAROE_ISLANDS 0x01
701 # endif
702 # ifndef SUBLANG_FARSI_IRAN
703 # define SUBLANG_FARSI_IRAN 0x01
704 # endif
705 # ifndef SUBLANG_FINNISH_FINLAND
706 # define SUBLANG_FINNISH_FINLAND 0x01
707 # endif
708 # ifndef SUBLANG_FRENCH_LUXEMBOURG
709 # define SUBLANG_FRENCH_LUXEMBOURG 0x05
710 # endif
711 # ifndef SUBLANG_FRENCH_MONACO
712 # define SUBLANG_FRENCH_MONACO 0x06
713 # endif
714 # ifndef SUBLANG_FRENCH_WESTINDIES
715 # define SUBLANG_FRENCH_WESTINDIES 0x07
716 # endif
717 # ifndef SUBLANG_FRENCH_REUNION
718 # define SUBLANG_FRENCH_REUNION 0x08
719 # endif
720 # ifndef SUBLANG_FRENCH_CONGO
721 # define SUBLANG_FRENCH_CONGO 0x09
722 # endif
723 # ifndef SUBLANG_FRENCH_SENEGAL
724 # define SUBLANG_FRENCH_SENEGAL 0x0a
725 # endif
726 # ifndef SUBLANG_FRENCH_CAMEROON
727 # define SUBLANG_FRENCH_CAMEROON 0x0b
728 # endif
729 # ifndef SUBLANG_FRENCH_COTEDIVOIRE
730 # define SUBLANG_FRENCH_COTEDIVOIRE 0x0c
731 # endif
732 # ifndef SUBLANG_FRENCH_MALI
733 # define SUBLANG_FRENCH_MALI 0x0d
734 # endif
735 # ifndef SUBLANG_FRENCH_MOROCCO
736 # define SUBLANG_FRENCH_MOROCCO 0x0e
737 # endif
738 # ifndef SUBLANG_FRENCH_HAITI
739 # define SUBLANG_FRENCH_HAITI 0x0f
740 # endif
741 # ifndef SUBLANG_FRISIAN_NETHERLANDS
742 # define SUBLANG_FRISIAN_NETHERLANDS 0x01
743 # endif
744 # ifndef SUBLANG_GALICIAN_SPAIN
745 # define SUBLANG_GALICIAN_SPAIN 0x01
746 # endif
747 # ifndef SUBLANG_GEORGIAN_GEORGIA
748 # define SUBLANG_GEORGIAN_GEORGIA 0x01
749 # endif
750 # ifndef SUBLANG_GERMAN_LUXEMBOURG
751 # define SUBLANG_GERMAN_LUXEMBOURG 0x04
752 # endif
753 # ifndef SUBLANG_GERMAN_LIECHTENSTEIN
754 # define SUBLANG_GERMAN_LIECHTENSTEIN 0x05
755 # endif
756 # ifndef SUBLANG_GREEK_GREECE
757 # define SUBLANG_GREEK_GREECE 0x01
758 # endif
759 # ifndef SUBLANG_GREENLANDIC_GREENLAND
760 # define SUBLANG_GREENLANDIC_GREENLAND 0x01
761 # endif
762 # ifndef SUBLANG_GUJARATI_INDIA
763 # define SUBLANG_GUJARATI_INDIA 0x01
764 # endif
765 # ifndef SUBLANG_HAUSA_NIGERIA_LATIN
766 # define SUBLANG_HAUSA_NIGERIA_LATIN 0x01
767 # endif
768 # ifndef SUBLANG_HEBREW_ISRAEL
769 # define SUBLANG_HEBREW_ISRAEL 0x01
770 # endif
771 # ifndef SUBLANG_HINDI_INDIA
772 # define SUBLANG_HINDI_INDIA 0x01
773 # endif
774 # ifndef SUBLANG_HUNGARIAN_HUNGARY
775 # define SUBLANG_HUNGARIAN_HUNGARY 0x01
776 # endif
777 # ifndef SUBLANG_ICELANDIC_ICELAND
778 # define SUBLANG_ICELANDIC_ICELAND 0x01
779 # endif
780 # ifndef SUBLANG_IGBO_NIGERIA
781 # define SUBLANG_IGBO_NIGERIA 0x01
782 # endif
783 # ifndef SUBLANG_INDONESIAN_INDONESIA
784 # define SUBLANG_INDONESIAN_INDONESIA 0x01
785 # endif
786 # ifndef SUBLANG_INUKTITUT_CANADA
787 # define SUBLANG_INUKTITUT_CANADA 0x01
788 # endif
789 # undef SUBLANG_INUKTITUT_CANADA_LATIN
790 # define SUBLANG_INUKTITUT_CANADA_LATIN 0x02
791 # undef SUBLANG_IRISH_IRELAND
792 # define SUBLANG_IRISH_IRELAND 0x02
793 # ifndef SUBLANG_JAPANESE_JAPAN
794 # define SUBLANG_JAPANESE_JAPAN 0x01
795 # endif
796 # ifndef SUBLANG_KANNADA_INDIA
797 # define SUBLANG_KANNADA_INDIA 0x01
798 # endif
799 # ifndef SUBLANG_KASHMIRI_INDIA
800 # define SUBLANG_KASHMIRI_INDIA 0x02
801 # endif
802 # ifndef SUBLANG_KAZAK_KAZAKHSTAN
803 # define SUBLANG_KAZAK_KAZAKHSTAN 0x01
804 # endif
805 # ifndef SUBLANG_KICHE_GUATEMALA
806 # define SUBLANG_KICHE_GUATEMALA 0x01
807 # endif
808 # ifndef SUBLANG_KINYARWANDA_RWANDA
809 # define SUBLANG_KINYARWANDA_RWANDA 0x01
810 # endif
811 # ifndef SUBLANG_KONKANI_INDIA
812 # define SUBLANG_KONKANI_INDIA 0x01
813 # endif
814 # ifndef SUBLANG_KYRGYZ_KYRGYZSTAN
815 # define SUBLANG_KYRGYZ_KYRGYZSTAN 0x01
816 # endif
817 # ifndef SUBLANG_LAO_LAOS
818 # define SUBLANG_LAO_LAOS 0x01
819 # endif
820 # ifndef SUBLANG_LATVIAN_LATVIA
821 # define SUBLANG_LATVIAN_LATVIA 0x01
822 # endif
823 # ifndef SUBLANG_LITHUANIAN_LITHUANIA
824 # define SUBLANG_LITHUANIAN_LITHUANIA 0x01
825 # endif
826 # undef SUBLANG_LOWER_SORBIAN_GERMANY
827 # define SUBLANG_LOWER_SORBIAN_GERMANY 0x02
828 # ifndef SUBLANG_LUXEMBOURGISH_LUXEMBOURG
829 # define SUBLANG_LUXEMBOURGISH_LUXEMBOURG 0x01
830 # endif
831 # ifndef SUBLANG_MACEDONIAN_MACEDONIA
832 # define SUBLANG_MACEDONIAN_MACEDONIA 0x01
833 # endif
834 # ifndef SUBLANG_MALAY_MALAYSIA
835 # define SUBLANG_MALAY_MALAYSIA 0x01
836 # endif
837 # ifndef SUBLANG_MALAY_BRUNEI_DARUSSALAM
838 # define SUBLANG_MALAY_BRUNEI_DARUSSALAM 0x02
839 # endif
840 # ifndef SUBLANG_MALAYALAM_INDIA
841 # define SUBLANG_MALAYALAM_INDIA 0x01
842 # endif
843 # ifndef SUBLANG_MALTESE_MALTA
844 # define SUBLANG_MALTESE_MALTA 0x01
845 # endif
846 # ifndef SUBLANG_MAORI_NEW_ZEALAND
847 # define SUBLANG_MAORI_NEW_ZEALAND 0x01
848 # endif
849 # ifndef SUBLANG_MAPUDUNGUN_CHILE
850 # define SUBLANG_MAPUDUNGUN_CHILE 0x01
851 # endif
852 # ifndef SUBLANG_MARATHI_INDIA
853 # define SUBLANG_MARATHI_INDIA 0x01
854 # endif
855 # ifndef SUBLANG_MOHAWK_CANADA
856 # define SUBLANG_MOHAWK_CANADA 0x01
857 # endif
858 # ifndef SUBLANG_MONGOLIAN_CYRILLIC_MONGOLIA
859 # define SUBLANG_MONGOLIAN_CYRILLIC_MONGOLIA 0x01
860 # endif
861 # ifndef SUBLANG_MONGOLIAN_PRC
862 # define SUBLANG_MONGOLIAN_PRC 0x02
863 # endif
864 # ifndef SUBLANG_NEPALI_NEPAL
865 # define SUBLANG_NEPALI_NEPAL 0x01
866 # endif
867 # ifndef SUBLANG_NEPALI_INDIA
868 # define SUBLANG_NEPALI_INDIA 0x02
869 # endif
870 # ifndef SUBLANG_OCCITAN_FRANCE
871 # define SUBLANG_OCCITAN_FRANCE 0x01
872 # endif
873 # ifndef SUBLANG_ORIYA_INDIA
874 # define SUBLANG_ORIYA_INDIA 0x01
875 # endif
876 # ifndef SUBLANG_PASHTO_AFGHANISTAN
877 # define SUBLANG_PASHTO_AFGHANISTAN 0x01
878 # endif
879 # ifndef SUBLANG_POLISH_POLAND
880 # define SUBLANG_POLISH_POLAND 0x01
881 # endif
882 # ifndef SUBLANG_PUNJABI_INDIA
883 # define SUBLANG_PUNJABI_INDIA 0x01
884 # endif
885 # ifndef SUBLANG_PUNJABI_PAKISTAN
886 # define SUBLANG_PUNJABI_PAKISTAN 0x02
887 # endif
888 # ifndef SUBLANG_QUECHUA_BOLIVIA
889 # define SUBLANG_QUECHUA_BOLIVIA 0x01
890 # endif
891 # ifndef SUBLANG_QUECHUA_ECUADOR
892 # define SUBLANG_QUECHUA_ECUADOR 0x02
893 # endif
894 # ifndef SUBLANG_QUECHUA_PERU
895 # define SUBLANG_QUECHUA_PERU 0x03
896 # endif
897 # ifndef SUBLANG_ROMANIAN_ROMANIA
898 # define SUBLANG_ROMANIAN_ROMANIA 0x01
899 # endif
900 # ifndef SUBLANG_ROMANIAN_MOLDOVA
901 # define SUBLANG_ROMANIAN_MOLDOVA 0x02
902 # endif
903 # ifndef SUBLANG_ROMANSH_SWITZERLAND
904 # define SUBLANG_ROMANSH_SWITZERLAND 0x01
905 # endif
906 # ifndef SUBLANG_RUSSIAN_RUSSIA
907 # define SUBLANG_RUSSIAN_RUSSIA 0x01
908 # endif
909 # ifndef SUBLANG_RUSSIAN_MOLDAVIA
910 # define SUBLANG_RUSSIAN_MOLDAVIA 0x02
911 # endif
912 # ifndef SUBLANG_SAMI_NORTHERN_NORWAY
913 # define SUBLANG_SAMI_NORTHERN_NORWAY 0x01
914 # endif
915 # ifndef SUBLANG_SAMI_NORTHERN_SWEDEN
916 # define SUBLANG_SAMI_NORTHERN_SWEDEN 0x02
917 # endif
918 # ifndef SUBLANG_SAMI_NORTHERN_FINLAND
919 # define SUBLANG_SAMI_NORTHERN_FINLAND 0x03
920 # endif
921 # ifndef SUBLANG_SAMI_LULE_NORWAY
922 # define SUBLANG_SAMI_LULE_NORWAY 0x04
923 # endif
924 # ifndef SUBLANG_SAMI_LULE_SWEDEN
925 # define SUBLANG_SAMI_LULE_SWEDEN 0x05
926 # endif
927 # ifndef SUBLANG_SAMI_SOUTHERN_NORWAY
928 # define SUBLANG_SAMI_SOUTHERN_NORWAY 0x06
929 # endif
930 # ifndef SUBLANG_SAMI_SOUTHERN_SWEDEN
931 # define SUBLANG_SAMI_SOUTHERN_SWEDEN 0x07
932 # endif
933 # undef SUBLANG_SAMI_SKOLT_FINLAND
934 # define SUBLANG_SAMI_SKOLT_FINLAND 0x08
935 # undef SUBLANG_SAMI_INARI_FINLAND
936 # define SUBLANG_SAMI_INARI_FINLAND 0x09
937 # ifndef SUBLANG_SANSKRIT_INDIA
938 # define SUBLANG_SANSKRIT_INDIA 0x01
939 # endif
940 # ifndef SUBLANG_SERBIAN_LATIN
941 # define SUBLANG_SERBIAN_LATIN 0x02
942 # endif
943 # ifndef SUBLANG_SERBIAN_CYRILLIC
944 # define SUBLANG_SERBIAN_CYRILLIC 0x03
945 # endif
946 # ifndef SUBLANG_SINDHI_INDIA
947 # define SUBLANG_SINDHI_INDIA 0x01
948 # endif
949 # undef SUBLANG_SINDHI_PAKISTAN
950 # define SUBLANG_SINDHI_PAKISTAN 0x02
951 # ifndef SUBLANG_SINDHI_AFGHANISTAN
952 # define SUBLANG_SINDHI_AFGHANISTAN 0x02
953 # endif
954 # ifndef SUBLANG_SINHALESE_SRI_LANKA
955 # define SUBLANG_SINHALESE_SRI_LANKA 0x01
956 # endif
957 # ifndef SUBLANG_SLOVAK_SLOVAKIA
958 # define SUBLANG_SLOVAK_SLOVAKIA 0x01
959 # endif
960 # ifndef SUBLANG_SLOVENIAN_SLOVENIA
961 # define SUBLANG_SLOVENIAN_SLOVENIA 0x01
962 # endif
963 # ifndef SUBLANG_SOTHO_SOUTH_AFRICA
964 # define SUBLANG_SOTHO_SOUTH_AFRICA 0x01
965 # endif
966 # ifndef SUBLANG_SPANISH_GUATEMALA
967 # define SUBLANG_SPANISH_GUATEMALA 0x04
968 # endif
969 # ifndef SUBLANG_SPANISH_COSTA_RICA
970 # define SUBLANG_SPANISH_COSTA_RICA 0x05
971 # endif
972 # ifndef SUBLANG_SPANISH_PANAMA
973 # define SUBLANG_SPANISH_PANAMA 0x06
974 # endif
975 # ifndef SUBLANG_SPANISH_DOMINICAN_REPUBLIC
976 # define SUBLANG_SPANISH_DOMINICAN_REPUBLIC 0x07
977 # endif
978 # ifndef SUBLANG_SPANISH_VENEZUELA
979 # define SUBLANG_SPANISH_VENEZUELA 0x08
980 # endif
981 # ifndef SUBLANG_SPANISH_COLOMBIA
982 # define SUBLANG_SPANISH_COLOMBIA 0x09
983 # endif
984 # ifndef SUBLANG_SPANISH_PERU
985 # define SUBLANG_SPANISH_PERU 0x0a
986 # endif
987 # ifndef SUBLANG_SPANISH_ARGENTINA
988 # define SUBLANG_SPANISH_ARGENTINA 0x0b
989 # endif
990 # ifndef SUBLANG_SPANISH_ECUADOR
991 # define SUBLANG_SPANISH_ECUADOR 0x0c
992 # endif
993 # ifndef SUBLANG_SPANISH_CHILE
994 # define SUBLANG_SPANISH_CHILE 0x0d
995 # endif
996 # ifndef SUBLANG_SPANISH_URUGUAY
997 # define SUBLANG_SPANISH_URUGUAY 0x0e
998 # endif
999 # ifndef SUBLANG_SPANISH_PARAGUAY
1000 # define SUBLANG_SPANISH_PARAGUAY 0x0f
1001 # endif
1002 # ifndef SUBLANG_SPANISH_BOLIVIA
1003 # define SUBLANG_SPANISH_BOLIVIA 0x10
1004 # endif
1005 # ifndef SUBLANG_SPANISH_EL_SALVADOR
1006 # define SUBLANG_SPANISH_EL_SALVADOR 0x11
1007 # endif
1008 # ifndef SUBLANG_SPANISH_HONDURAS
1009 # define SUBLANG_SPANISH_HONDURAS 0x12
1010 # endif
1011 # ifndef SUBLANG_SPANISH_NICARAGUA
1012 # define SUBLANG_SPANISH_NICARAGUA 0x13
1013 # endif
1014 # ifndef SUBLANG_SPANISH_PUERTO_RICO
1015 # define SUBLANG_SPANISH_PUERTO_RICO 0x14
1016 # endif
1017 # ifndef SUBLANG_SPANISH_US
1018 # define SUBLANG_SPANISH_US 0x15
1019 # endif
1020 # ifndef SUBLANG_SWAHILI_KENYA
1021 # define SUBLANG_SWAHILI_KENYA 0x01
1022 # endif
1023 # ifndef SUBLANG_SWEDISH_SWEDEN
1024 # define SUBLANG_SWEDISH_SWEDEN 0x01
1025 # endif
1026 # ifndef SUBLANG_SWEDISH_FINLAND
1027 # define SUBLANG_SWEDISH_FINLAND 0x02
1028 # endif
1029 # ifndef SUBLANG_SYRIAC_SYRIA
1030 # define SUBLANG_SYRIAC_SYRIA 0x01
1031 # endif
1032 # ifndef SUBLANG_TAGALOG_PHILIPPINES
1033 # define SUBLANG_TAGALOG_PHILIPPINES 0x01
1034 # endif
1035 # ifndef SUBLANG_TAJIK_TAJIKISTAN
1036 # define SUBLANG_TAJIK_TAJIKISTAN 0x01
1037 # endif
1038 # ifndef SUBLANG_TAMAZIGHT_ARABIC
1039 # define SUBLANG_TAMAZIGHT_ARABIC 0x01
1040 # endif
1041 # ifndef SUBLANG_TAMAZIGHT_ALGERIA_LATIN
1042 # define SUBLANG_TAMAZIGHT_ALGERIA_LATIN 0x02
1043 # endif
1044 # ifndef SUBLANG_TAMIL_INDIA
1045 # define SUBLANG_TAMIL_INDIA 0x01
1046 # endif
1047 # ifndef SUBLANG_TATAR_RUSSIA
1048 # define SUBLANG_TATAR_RUSSIA 0x01
1049 # endif
1050 # ifndef SUBLANG_TELUGU_INDIA
1051 # define SUBLANG_TELUGU_INDIA 0x01
1052 # endif
1053 # ifndef SUBLANG_THAI_THAILAND
1054 # define SUBLANG_THAI_THAILAND 0x01
1055 # endif
1056 # ifndef SUBLANG_TIBETAN_PRC
1057 # define SUBLANG_TIBETAN_PRC 0x01
1058 # endif
1059 # undef SUBLANG_TIBETAN_BHUTAN
1060 # define SUBLANG_TIBETAN_BHUTAN 0x02
1061 # ifndef SUBLANG_TIGRINYA_ETHIOPIA
1062 # define SUBLANG_TIGRINYA_ETHIOPIA 0x01
1063 # endif
1064 # ifndef SUBLANG_TIGRINYA_ERITREA
1065 # define SUBLANG_TIGRINYA_ERITREA 0x02
1066 # endif
1067 # ifndef SUBLANG_TSWANA_SOUTH_AFRICA
1068 # define SUBLANG_TSWANA_SOUTH_AFRICA 0x01
1069 # endif
1070 # ifndef SUBLANG_TURKISH_TURKEY
1071 # define SUBLANG_TURKISH_TURKEY 0x01
1072 # endif
1073 # ifndef SUBLANG_TURKMEN_TURKMENISTAN
1074 # define SUBLANG_TURKMEN_TURKMENISTAN 0x01
1075 # endif
1076 # ifndef SUBLANG_UIGHUR_PRC
1077 # define SUBLANG_UIGHUR_PRC 0x01
1078 # endif
1079 # ifndef SUBLANG_UKRAINIAN_UKRAINE
1080 # define SUBLANG_UKRAINIAN_UKRAINE 0x01
1081 # endif
1082 # ifndef SUBLANG_UPPER_SORBIAN_GERMANY
1083 # define SUBLANG_UPPER_SORBIAN_GERMANY 0x01
1084 # endif
1085 # ifndef SUBLANG_URDU_PAKISTAN
1086 # define SUBLANG_URDU_PAKISTAN 0x01
1087 # endif
1088 # ifndef SUBLANG_URDU_INDIA
1089 # define SUBLANG_URDU_INDIA 0x02
1090 # endif
1091 # ifndef SUBLANG_UZBEK_LATIN
1092 # define SUBLANG_UZBEK_LATIN 0x01
1093 # endif
1094 # ifndef SUBLANG_UZBEK_CYRILLIC
1095 # define SUBLANG_UZBEK_CYRILLIC 0x02
1096 # endif
1097 # ifndef SUBLANG_VIETNAMESE_VIETNAM
1098 # define SUBLANG_VIETNAMESE_VIETNAM 0x01
1099 # endif
1100 # ifndef SUBLANG_WELSH_UNITED_KINGDOM
1101 # define SUBLANG_WELSH_UNITED_KINGDOM 0x01
1102 # endif
1103 # ifndef SUBLANG_WOLOF_SENEGAL
1104 # define SUBLANG_WOLOF_SENEGAL 0x01
1105 # endif
1106 # ifndef SUBLANG_XHOSA_SOUTH_AFRICA
1107 # define SUBLANG_XHOSA_SOUTH_AFRICA 0x01
1108 # endif
1109 # ifndef SUBLANG_YAKUT_RUSSIA
1110 # define SUBLANG_YAKUT_RUSSIA 0x01
1111 # endif
1112 # ifndef SUBLANG_YI_PRC
1113 # define SUBLANG_YI_PRC 0x01
1114 # endif
1115 # ifndef SUBLANG_YORUBA_NIGERIA
1116 # define SUBLANG_YORUBA_NIGERIA 0x01
1117 # endif
1118 # ifndef SUBLANG_ZULU_SOUTH_AFRICA
1119 # define SUBLANG_ZULU_SOUTH_AFRICA 0x01
1120 # endif
1121 /* GetLocaleInfoA operations. */
1122 # ifndef LOCALE_SNAME
1123 # define LOCALE_SNAME 0x5c
1124 # endif
1125 # ifndef LOCALE_NAME_MAX_LENGTH
1126 # define LOCALE_NAME_MAX_LENGTH 85
1127 # endif
1128 /* Don't assume that UNICODE is not defined. */
1129 # undef GetLocaleInfo
1130 # define GetLocaleInfo GetLocaleInfoA
1131 # undef EnumSystemLocales
1132 # define EnumSystemLocales EnumSystemLocalesA
1133 #endif
1134
1135 /* We want to use the system's setlocale() function here, not the gnulib
1136 override. */
1137 #undef setlocale
1138
1139
1140 #if HAVE_CFPREFERENCESCOPYAPPVALUE
1141 /* Mac OS X 10.4 or newer */
1142
1143 /* Canonicalize a Mac OS X locale name to a Unix locale name.
1144 NAME is a sufficiently large buffer.
1145 On input, it contains the Mac OS X locale name.
1146 On output, it contains the Unix locale name. */
1147 # if !defined IN_LIBINTL
1148 static
1149 # endif
1150 void
1151 gl_locale_name_canonicalize (char *name)
1152 {
1153 /* This conversion is based on a posting by
1154 Deborah GoldSmith <[email protected]> on 2005-03-08,
1155 https://lists.apple.com/archives/carbon-dev/2005/Mar/msg00293.html */
1156
1157 /* Convert legacy (NeXTstep inherited) English names to Unix (ISO 639 and
1158 ISO 3166) names. Prior to Mac OS X 10.3, there is no API for doing this.
1159 Therefore we do it ourselves, using a table based on the results of the
1160 Mac OS X 10.3.8 function
1161 CFLocaleCreateCanonicalLocaleIdentifierFromString(). */
1162 typedef struct { const char legacy[21+1]; const char unixy[5+1]; }
1163 legacy_entry;
1164 static const legacy_entry legacy_table[] = {
1165 { "Afrikaans", "af" },
1166 { "Albanian", "sq" },
1167 { "Amharic", "am" },
1168 { "Arabic", "ar" },
1169 { "Armenian", "hy" },
1170 { "Assamese", "as" },
1171 { "Aymara", "ay" },
1172 { "Azerbaijani", "az" },
1173 { "Basque", "eu" },
1174 { "Belarusian", "be" },
1175 { "Belorussian", "be" },
1176 { "Bengali", "bn" },
1177 { "Brazilian Portugese", "pt_BR" },
1178 { "Brazilian Portuguese", "pt_BR" },
1179 { "Breton", "br" },
1180 { "Bulgarian", "bg" },
1181 { "Burmese", "my" },
1182 { "Byelorussian", "be" },
1183 { "Catalan", "ca" },
1184 { "Chewa", "ny" },
1185 { "Chichewa", "ny" },
1186 { "Chinese", "zh" },
1187 { "Chinese, Simplified", "zh_CN" },
1188 { "Chinese, Traditional", "zh_TW" },
1189 { "Chinese, Tradtional", "zh_TW" },
1190 { "Croatian", "hr" },
1191 { "Czech", "cs" },
1192 { "Danish", "da" },
1193 { "Dutch", "nl" },
1194 { "Dzongkha", "dz" },
1195 { "English", "en" },
1196 { "Esperanto", "eo" },
1197 { "Estonian", "et" },
1198 { "Faroese", "fo" },
1199 { "Farsi", "fa" },
1200 { "Finnish", "fi" },
1201 { "Flemish", "nl_BE" },
1202 { "French", "fr" },
1203 { "Galician", "gl" },
1204 { "Gallegan", "gl" },
1205 { "Georgian", "ka" },
1206 { "German", "de" },
1207 { "Greek", "el" },
1208 { "Greenlandic", "kl" },
1209 { "Guarani", "gn" },
1210 { "Gujarati", "gu" },
1211 { "Hawaiian", "haw" }, /* Yes, "haw", not "cpe". */
1212 { "Hebrew", "he" },
1213 { "Hindi", "hi" },
1214 { "Hungarian", "hu" },
1215 { "Icelandic", "is" },
1216 { "Indonesian", "id" },
1217 { "Inuktitut", "iu" },
1218 { "Irish", "ga" },
1219 { "Italian", "it" },
1220 { "Japanese", "ja" },
1221 { "Javanese", "jv" },
1222 { "Kalaallisut", "kl" },
1223 { "Kannada", "kn" },
1224 { "Kashmiri", "ks" },
1225 { "Kazakh", "kk" },
1226 { "Khmer", "km" },
1227 { "Kinyarwanda", "rw" },
1228 { "Kirghiz", "ky" },
1229 { "Korean", "ko" },
1230 { "Kurdish", "ku" },
1231 { "Latin", "la" },
1232 { "Latvian", "lv" },
1233 { "Lithuanian", "lt" },
1234 { "Macedonian", "mk" },
1235 { "Malagasy", "mg" },
1236 { "Malay", "ms" },
1237 { "Malayalam", "ml" },
1238 { "Maltese", "mt" },
1239 { "Manx", "gv" },
1240 { "Marathi", "mr" },
1241 { "Moldavian", "mo" },
1242 { "Mongolian", "mn" },
1243 { "Nepali", "ne" },
1244 { "Norwegian", "nb" }, /* Yes, "nb", not the obsolete "no". */
1245 { "Nyanja", "ny" },
1246 { "Nynorsk", "nn" },
1247 { "Oriya", "or" },
1248 { "Oromo", "om" },
1249 { "Panjabi", "pa" },
1250 { "Pashto", "ps" },
1251 { "Persian", "fa" },
1252 { "Polish", "pl" },
1253 { "Portuguese", "pt" },
1254 { "Portuguese, Brazilian", "pt_BR" },
1255 { "Punjabi", "pa" },
1256 { "Pushto", "ps" },
1257 { "Quechua", "qu" },
1258 { "Romanian", "ro" },
1259 { "Ruanda", "rw" },
1260 { "Rundi", "rn" },
1261 { "Russian", "ru" },
1262 { "Sami", "se_NO" }, /* Not just "se". */
1263 { "Sanskrit", "sa" },
1264 { "Scottish", "gd" },
1265 { "Serbian", "sr" },
1266 { "Simplified Chinese", "zh_CN" },
1267 { "Sindhi", "sd" },
1268 { "Sinhalese", "si" },
1269 { "Slovak", "sk" },
1270 { "Slovenian", "sl" },
1271 { "Somali", "so" },
1272 { "Spanish", "es" },
1273 { "Sundanese", "su" },
1274 { "Swahili", "sw" },
1275 { "Swedish", "sv" },
1276 { "Tagalog", "tl" },
1277 { "Tajik", "tg" },
1278 { "Tajiki", "tg" },
1279 { "Tamil", "ta" },
1280 { "Tatar", "tt" },
1281 { "Telugu", "te" },
1282 { "Thai", "th" },
1283 { "Tibetan", "bo" },
1284 { "Tigrinya", "ti" },
1285 { "Tongan", "to" },
1286 { "Traditional Chinese", "zh_TW" },
1287 { "Turkish", "tr" },
1288 { "Turkmen", "tk" },
1289 { "Uighur", "ug" },
1290 { "Ukrainian", "uk" },
1291 { "Urdu", "ur" },
1292 { "Uzbek", "uz" },
1293 { "Vietnamese", "vi" },
1294 { "Welsh", "cy" },
1295 { "Yiddish", "yi" }
1296 };
1297
1298 /* Convert new-style locale names with language tags (ISO 639 and ISO 15924)
1299 to Unix (ISO 639 and ISO 3166) names. */
1300 typedef struct { const char langtag[7+1]; const char unixy[12+1]; }
1301 langtag_entry;
1302 static const langtag_entry langtag_table[] = {
1303 /* Mac OS X has "az-Arab", "az-Cyrl", "az-Latn".
1304 The default script for az on Unix is Latin. */
1305 { "az-Latn", "az" },
1306 /* Mac OS X has "bs-Cyrl", "bs-Latn".
1307 The default script for bs on Unix is Latin. */
1308 { "bs-Latn", "bs" },
1309 /* Mac OS X has "ga-dots". Does not yet exist on Unix. */
1310 { "ga-dots", "ga" },
1311 /* Mac OS X has "kk-Cyrl".
1312 The default script for kk on Unix is Cyrillic. */
1313 { "kk-Cyrl", "kk" },
1314 /* Mac OS X has "mn-Cyrl", "mn-Mong".
1315 The default script for mn on Unix is Cyrillic. */
1316 { "mn-Cyrl", "mn" },
1317 /* Mac OS X has "ms-Arab", "ms-Latn".
1318 The default script for ms on Unix is Latin. */
1319 { "ms-Latn", "ms" },
1320 /* Mac OS X has "pa-Arab", "pa-Guru".
1321 Country codes are used to distinguish these on Unix. */
1322 { "pa-Arab", "pa_PK" },
1323 { "pa-Guru", "pa_IN" },
1324 /* Mac OS X has "shi-Latn", "shi-Tfng". Does not yet exist on Unix. */
1325 /* Mac OS X has "sr-Cyrl", "sr-Latn".
1326 The default script for sr on Unix is Cyrillic. */
1327 { "sr-Cyrl", "sr" },
1328 /* Mac OS X has "tg-Cyrl".
1329 The default script for tg on Unix is Cyrillic. */
1330 { "tg-Cyrl", "tg" },
1331 /* Mac OS X has "tk-Cyrl".
1332 The default script for tk on Unix is Cyrillic. */
1333 { "tk-Cyrl", "tk" },
1334 /* Mac OS X has "tt-Cyrl".
1335 The default script for tt on Unix is Cyrillic. */
1336 { "tt-Cyrl", "tt" },
1337 /* Mac OS X has "uz-Arab", "uz-Cyrl", "uz-Latn".
1338 The default script for uz on Unix is Latin. */
1339 { "uz-Latn", "uz" },
1340 /* Mac OS X has "vai-Latn", "vai-Vaii". Does not yet exist on Unix. */
1341 /* Mac OS X has "yue-Hans", "yue-Hant".
1342 The default script for yue on Unix is Simplified Han. */
1343 { "yue-Hans", "yue" },
1344 /* Mac OS X has "zh-Hans", "zh-Hant".
1345 Country codes are used to distinguish these on Unix. */
1346 { "zh-Hans", "zh_CN" },
1347 { "zh-Hant", "zh_TW" }
1348 };
1349
1350 /* Convert script names (ISO 15924) to Unix conventions.
1351 See https://www.unicode.org/iso15924/iso15924-codes.html */
1352 typedef struct { const char script[4+1]; const char unixy[9+1]; }
1353 script_entry;
1354 static const script_entry script_table[] = {
1355 { "Arab", "arabic" },
1356 { "Cyrl", "cyrillic" },
1357 { "Latn", "latin" },
1358 { "Mong", "mongolian" }
1359 };
1360
1361 /* Step 1: Convert using legacy_table. */
1362 if (name[0] >= 'A' && name[0] <= 'Z')
1363 {
1364 unsigned int i1, i2;
1365 i1 = 0;
1366 i2 = sizeof (legacy_table) / sizeof (legacy_entry);
1367 while (i2 - i1 > 1)
1368 {
1369 /* At this point we know that if name occurs in legacy_table,
1370 its index must be >= i1 and < i2. */
1371 unsigned int i = (i1 + i2) >> 1;
1372 const legacy_entry *p = &legacy_table[i];
1373 if (strcmp (name, p->legacy) < 0)
1374 i2 = i;
1375 else
1376 i1 = i;
1377 }
1378 if (strcmp (name, legacy_table[i1].legacy) == 0)
1379 {
1380 strcpy (name, legacy_table[i1].unixy);
1381 return;
1382 }
1383 }
1384
1385 /* Step 2: Convert using langtag_table and script_table. */
1386 if (strlen (name) == 7 && name[2] == '-')
1387 {
1388 unsigned int i1, i2;
1389 i1 = 0;
1390 i2 = sizeof (langtag_table) / sizeof (langtag_entry);
1391 while (i2 - i1 > 1)
1392 {
1393 /* At this point we know that if name occurs in langtag_table,
1394 its index must be >= i1 and < i2. */
1395 unsigned int i = (i1 + i2) >> 1;
1396 const langtag_entry *p = &langtag_table[i];
1397 if (strcmp (name, p->langtag) < 0)
1398 i2 = i;
1399 else
1400 i1 = i;
1401 }
1402 if (strcmp (name, langtag_table[i1].langtag) == 0)
1403 {
1404 strcpy (name, langtag_table[i1].unixy);
1405 return;
1406 }
1407
1408 i1 = 0;
1409 i2 = sizeof (script_table) / sizeof (script_entry);
1410 while (i2 - i1 > 1)
1411 {
1412 /* At this point we know that if (name + 3) occurs in script_table,
1413 its index must be >= i1 and < i2. */
1414 unsigned int i = (i1 + i2) >> 1;
1415 const script_entry *p = &script_table[i];
1416 if (strcmp (name + 3, p->script) < 0)
1417 i2 = i;
1418 else
1419 i1 = i;
1420 }
1421 if (strcmp (name + 3, script_table[i1].script) == 0)
1422 {
1423 name[2] = '@';
1424 strcpy (name + 3, script_table[i1].unixy);
1425 return;
1426 }
1427 }
1428
1429 /* Step 3: Convert new-style dash to Unix underscore. */
1430 {
1431 char *p;
1432 for (p = name; *p != '\0'; p++)
1433 if (*p == '-')
1434 *p = '_';
1435 }
1436 }
1437
1438 #endif
1439
1440
1441 #if defined WINDOWS_NATIVE || defined __CYGWIN__ /* Native Windows or Cygwin */
1442
1443 /* Canonicalize a Windows native locale name to a Unix locale name.
1444 NAME is a sufficiently large buffer.
1445 On input, it contains the Windows locale name.
1446 On output, it contains the Unix locale name. */
1447 # if !defined IN_LIBINTL
1448 static
1449 # endif
1450 void
1451 gl_locale_name_canonicalize (char *name)
1452 {
1453 /* FIXME: This is probably incomplete: it does not handle "zh-Hans" and
1454 "zh-Hant". */
1455 char *p;
1456
1457 for (p = name; *p != '\0'; p++)
1458 if (*p == '-')
1459 {
1460 *p = '_';
1461 p++;
1462 for (; *p != '\0'; p++)
1463 {
1464 if (*p >= 'a' && *p <= 'z')
1465 *p += 'A' - 'a';
1466 if (*p == '-')
1467 {
1468 *p = '\0';
1469 return;
1470 }
1471 }
1472 return;
1473 }
1474 }
1475
1476 # if !defined IN_LIBINTL
1477 static
1478 # endif
1479 const char *
1480 gl_locale_name_from_win32_LANGID (LANGID langid)
1481 {
1482 int is_utf8 = (GetACP () == 65001);
1483
1484 /* Activate the new code only when the GETTEXT_MUI environment variable is
1485 set, for the time being, since the new code is not well tested. */
1486 if (getenv ("GETTEXT_MUI") != NULL)
1487 {
1488 static char namebuf[256];
1489
1490 /* Query the system's notion of locale name.
1491 On Windows95/98/ME, GetLocaleInfoA returns some incorrect results.
1492 But we don't need to support systems that are so old. */
1493 if (GetLocaleInfoA (MAKELCID (langid, SORT_DEFAULT), LOCALE_SNAME,
1494 namebuf, sizeof (namebuf) - 1 - 6))
1495 {
1496 /* Convert it to a Unix locale name. */
1497 gl_locale_name_canonicalize (namebuf);
1498 if (is_utf8)
1499 strcat (namebuf, ".UTF-8");
1500 return namebuf;
1501 }
1502 }
1503 /* Internet Explorer has an LCID to RFC3066 name mapping stored in
1504 HKEY_CLASSES_ROOT\Mime\Database\Rfc1766. But we better don't use that
1505 since IE's i18n subsystem is known to be inconsistent with the native
1506 Windows base (e.g. they have different character conversion facilities
1507 that produce different results). */
1508 /* Use our own table. */
1509 #define N(name) (is_utf8 ? name ".UTF-8" : name)
1510 #define NM(name,modifier) (is_utf8 ? name ".UTF-8" modifier : name modifier)
1511 {
1512 int primary, sub;
1513
1514 /* Split into language and territory part. */
1515 primary = PRIMARYLANGID (langid);
1516 sub = SUBLANGID (langid);
1517
1518 /* Dispatch on language.
1519 See also https://www.unicode.org/unicode/onlinedat/languages.html .
1520 For details about languages, see https://www.ethnologue.com/ . */
1521 switch (primary)
1522 {
1523 case LANG_AFRIKAANS:
1524 switch (sub)
1525 {
1526 case SUBLANG_AFRIKAANS_SOUTH_AFRICA: return N("af_ZA");
1527 }
1528 return N("af");
1529 case LANG_ALBANIAN:
1530 switch (sub)
1531 {
1532 case SUBLANG_ALBANIAN_ALBANIA: return N("sq_AL");
1533 }
1534 return N("sq");
1535 case LANG_ALSATIAN:
1536 switch (sub)
1537 {
1538 case SUBLANG_ALSATIAN_FRANCE: return N("gsw_FR");
1539 }
1540 return N("gsw");
1541 case LANG_AMHARIC:
1542 switch (sub)
1543 {
1544 case SUBLANG_AMHARIC_ETHIOPIA: return N("am_ET");
1545 }
1546 return N("am");
1547 case LANG_ARABIC:
1548 switch (sub)
1549 {
1550 case SUBLANG_ARABIC_SAUDI_ARABIA: return N("ar_SA");
1551 case SUBLANG_ARABIC_IRAQ: return N("ar_IQ");
1552 case SUBLANG_ARABIC_EGYPT: return N("ar_EG");
1553 case SUBLANG_ARABIC_LIBYA: return N("ar_LY");
1554 case SUBLANG_ARABIC_ALGERIA: return N("ar_DZ");
1555 case SUBLANG_ARABIC_MOROCCO: return N("ar_MA");
1556 case SUBLANG_ARABIC_TUNISIA: return N("ar_TN");
1557 case SUBLANG_ARABIC_OMAN: return N("ar_OM");
1558 case SUBLANG_ARABIC_YEMEN: return N("ar_YE");
1559 case SUBLANG_ARABIC_SYRIA: return N("ar_SY");
1560 case SUBLANG_ARABIC_JORDAN: return N("ar_JO");
1561 case SUBLANG_ARABIC_LEBANON: return N("ar_LB");
1562 case SUBLANG_ARABIC_KUWAIT: return N("ar_KW");
1563 case SUBLANG_ARABIC_UAE: return N("ar_AE");
1564 case SUBLANG_ARABIC_BAHRAIN: return N("ar_BH");
1565 case SUBLANG_ARABIC_QATAR: return N("ar_QA");
1566 }
1567 return N("ar");
1568 case LANG_ARMENIAN:
1569 switch (sub)
1570 {
1571 case SUBLANG_ARMENIAN_ARMENIA: return N("hy_AM");
1572 }
1573 return N("hy");
1574 case LANG_ASSAMESE:
1575 switch (sub)
1576 {
1577 case SUBLANG_ASSAMESE_INDIA: return N("as_IN");
1578 }
1579 return N("as");
1580 case LANG_AZERI:
1581 switch (sub)
1582 {
1583 case 0x1e: return N("az");
1584 case SUBLANG_AZERI_LATIN: return N("az_AZ");
1585 case 0x1d: return NM("az","@cyrillic");
1586 case SUBLANG_AZERI_CYRILLIC: return NM("az_AZ","@cyrillic");
1587 }
1588 return N("az");
1589 case LANG_BASHKIR:
1590 switch (sub)
1591 {
1592 case SUBLANG_BASHKIR_RUSSIA: return N("ba_RU");
1593 }
1594 return N("ba");
1595 case LANG_BASQUE:
1596 switch (sub)
1597 {
1598 case SUBLANG_BASQUE_BASQUE: return N("eu_ES");
1599 }
1600 return N("eu"); /* Ambiguous: could be "eu_ES" or "eu_FR". */
1601 case LANG_BELARUSIAN:
1602 switch (sub)
1603 {
1604 case SUBLANG_BELARUSIAN_BELARUS: return N("be_BY");
1605 }
1606 return N("be");
1607 case LANG_BENGALI:
1608 switch (sub)
1609 {
1610 case SUBLANG_BENGALI_INDIA: return N("bn_IN");
1611 case SUBLANG_BENGALI_BANGLADESH: return N("bn_BD");
1612 }
1613 return N("bn");
1614 case LANG_BRETON:
1615 switch (sub)
1616 {
1617 case SUBLANG_BRETON_FRANCE: return N("br_FR");
1618 }
1619 return N("br");
1620 case LANG_BULGARIAN:
1621 switch (sub)
1622 {
1623 case SUBLANG_BULGARIAN_BULGARIA: return N("bg_BG");
1624 }
1625 return N("bg");
1626 case LANG_BURMESE:
1627 switch (sub)
1628 {
1629 case SUBLANG_DEFAULT: return N("my_MM");
1630 }
1631 return N("my");
1632 case LANG_CAMBODIAN:
1633 switch (sub)
1634 {
1635 case SUBLANG_CAMBODIAN_CAMBODIA: return N("km_KH");
1636 }
1637 return N("km");
1638 case LANG_CATALAN:
1639 switch (sub)
1640 {
1641 case SUBLANG_CATALAN_SPAIN: return N("ca_ES");
1642 }
1643 return N("ca");
1644 case LANG_CHEROKEE:
1645 switch (sub)
1646 {
1647 case SUBLANG_DEFAULT: return N("chr_US");
1648 }
1649 return N("chr");
1650 case LANG_CHINESE:
1651 switch (sub)
1652 {
1653 case SUBLANG_CHINESE_TRADITIONAL: case 0x1f: return N("zh_TW");
1654 case SUBLANG_CHINESE_SIMPLIFIED: case 0x00: return N("zh_CN");
1655 case SUBLANG_CHINESE_HONGKONG: return N("zh_HK"); /* traditional */
1656 case SUBLANG_CHINESE_SINGAPORE: return N("zh_SG"); /* simplified */
1657 case SUBLANG_CHINESE_MACAU: return N("zh_MO"); /* traditional */
1658 }
1659 return N("zh");
1660 case LANG_CORSICAN:
1661 switch (sub)
1662 {
1663 case SUBLANG_CORSICAN_FRANCE: return N("co_FR");
1664 }
1665 return N("co");
1666 case LANG_CROATIAN: /* LANG_CROATIAN == LANG_SERBIAN == LANG_BOSNIAN
1667 * What used to be called Serbo-Croatian
1668 * should really now be two separate
1669 * languages because of political reasons.
1670 * (Says tml, who knows nothing about Serbian
1671 * or Croatian.)
1672 * (I can feel those flames coming already.)
1673 */
1674 switch (sub)
1675 {
1676 /* Croatian */
1677 case 0x00: return N("hr");
1678 case SUBLANG_CROATIAN_CROATIA: return N("hr_HR");
1679 case SUBLANG_CROATIAN_BOSNIA_HERZEGOVINA_LATIN: return N("hr_BA");
1680 /* Serbian */
1681 case 0x1f: return N("sr");
1682 case 0x1c: return N("sr"); /* latin */
1683 case SUBLANG_SERBIAN_LATIN: return N("sr_CS"); /* latin */
1684 case 0x09: return N("sr_RS"); /* latin */
1685 case 0x0b: return N("sr_ME"); /* latin */
1686 case 0x06: return N("sr_BA"); /* latin */
1687 case 0x1b: return NM("sr","@cyrillic");
1688 case SUBLANG_SERBIAN_CYRILLIC: return NM("sr_CS","@cyrillic");
1689 case 0x0a: return NM("sr_RS","@cyrillic");
1690 case 0x0c: return NM("sr_ME","@cyrillic");
1691 case 0x07: return NM("sr_BA","@cyrillic");
1692 /* Bosnian */
1693 case 0x1e: return N("bs");
1694 case 0x1a: return N("bs"); /* latin */
1695 case SUBLANG_BOSNIAN_BOSNIA_HERZEGOVINA_LATIN: return N("bs_BA"); /* latin */
1696 case 0x19: return NM("bs","@cyrillic");
1697 case SUBLANG_BOSNIAN_BOSNIA_HERZEGOVINA_CYRILLIC: return NM("bs_BA","@cyrillic");
1698 }
1699 return N("hr");
1700 case LANG_CZECH:
1701 switch (sub)
1702 {
1703 case SUBLANG_CZECH_CZECH_REPUBLIC: return N("cs_CZ");
1704 }
1705 return N("cs");
1706 case LANG_DANISH:
1707 switch (sub)
1708 {
1709 case SUBLANG_DANISH_DENMARK: return N("da_DK");
1710 }
1711 return N("da");
1712 case LANG_DARI:
1713 /* FIXME: Adjust this when such locales appear on Unix. */
1714 switch (sub)
1715 {
1716 case SUBLANG_DARI_AFGHANISTAN: return N("prs_AF");
1717 }
1718 return N("prs");
1719 case LANG_DIVEHI:
1720 switch (sub)
1721 {
1722 case SUBLANG_DIVEHI_MALDIVES: return N("dv_MV");
1723 }
1724 return N("dv");
1725 case LANG_DUTCH:
1726 switch (sub)
1727 {
1728 case SUBLANG_DUTCH: return N("nl_NL");
1729 case SUBLANG_DUTCH_BELGIAN: /* FLEMISH, VLAAMS */ return N("nl_BE");
1730 case SUBLANG_DUTCH_SURINAM: return N("nl_SR");
1731 }
1732 return N("nl");
1733 case LANG_EDO:
1734 switch (sub)
1735 {
1736 case SUBLANG_DEFAULT: return N("bin_NG");
1737 }
1738 return N("bin");
1739 case LANG_ENGLISH:
1740 switch (sub)
1741 {
1742 /* SUBLANG_ENGLISH_US == SUBLANG_DEFAULT. Heh. I thought
1743 * English was the language spoken in England.
1744 * Oh well.
1745 */
1746 case SUBLANG_ENGLISH_US: return N("en_US");
1747 case SUBLANG_ENGLISH_UK: return N("en_GB");
1748 case SUBLANG_ENGLISH_AUS: return N("en_AU");
1749 case SUBLANG_ENGLISH_CAN: return N("en_CA");
1750 case SUBLANG_ENGLISH_NZ: return N("en_NZ");
1751 case SUBLANG_ENGLISH_EIRE: return N("en_IE");
1752 case SUBLANG_ENGLISH_SOUTH_AFRICA: return N("en_ZA");
1753 case SUBLANG_ENGLISH_JAMAICA: return N("en_JM");
1754 case SUBLANG_ENGLISH_CARIBBEAN: return N("en_GD"); /* Grenada? */
1755 case SUBLANG_ENGLISH_BELIZE: return N("en_BZ");
1756 case SUBLANG_ENGLISH_TRINIDAD: return N("en_TT");
1757 case SUBLANG_ENGLISH_ZIMBABWE: return N("en_ZW");
1758 case SUBLANG_ENGLISH_PHILIPPINES: return N("en_PH");
1759 case SUBLANG_ENGLISH_INDONESIA: return N("en_ID");
1760 case SUBLANG_ENGLISH_HONGKONG: return N("en_HK");
1761 case SUBLANG_ENGLISH_INDIA: return N("en_IN");
1762 case SUBLANG_ENGLISH_MALAYSIA: return N("en_MY");
1763 case SUBLANG_ENGLISH_SINGAPORE: return N("en_SG");
1764 }
1765 return N("en");
1766 case LANG_ESTONIAN:
1767 switch (sub)
1768 {
1769 case SUBLANG_ESTONIAN_ESTONIA: return N("et_EE");
1770 }
1771 return N("et");
1772 case LANG_FAEROESE:
1773 switch (sub)
1774 {
1775 case SUBLANG_FAEROESE_FAROE_ISLANDS: return N("fo_FO");
1776 }
1777 return N("fo");
1778 case LANG_FARSI:
1779 switch (sub)
1780 {
1781 case SUBLANG_FARSI_IRAN: return N("fa_IR");
1782 }
1783 return N("fa");
1784 case LANG_FINNISH:
1785 switch (sub)
1786 {
1787 case SUBLANG_FINNISH_FINLAND: return N("fi_FI");
1788 }
1789 return N("fi");
1790 case LANG_FRENCH:
1791 switch (sub)
1792 {
1793 case SUBLANG_FRENCH: return N("fr_FR");
1794 case SUBLANG_FRENCH_BELGIAN: /* WALLOON */ return N("fr_BE");
1795 case SUBLANG_FRENCH_CANADIAN: return N("fr_CA");
1796 case SUBLANG_FRENCH_SWISS: return N("fr_CH");
1797 case SUBLANG_FRENCH_LUXEMBOURG: return N("fr_LU");
1798 case SUBLANG_FRENCH_MONACO: return N("fr_MC");
1799 case SUBLANG_FRENCH_WESTINDIES: return N("fr"); /* Caribbean? */
1800 case SUBLANG_FRENCH_REUNION: return N("fr_RE");
1801 case SUBLANG_FRENCH_CONGO: return N("fr_CG");
1802 case SUBLANG_FRENCH_SENEGAL: return N("fr_SN");
1803 case SUBLANG_FRENCH_CAMEROON: return N("fr_CM");
1804 case SUBLANG_FRENCH_COTEDIVOIRE: return N("fr_CI");
1805 case SUBLANG_FRENCH_MALI: return N("fr_ML");
1806 case SUBLANG_FRENCH_MOROCCO: return N("fr_MA");
1807 case SUBLANG_FRENCH_HAITI: return N("fr_HT");
1808 }
1809 return N("fr");
1810 case LANG_FRISIAN:
1811 switch (sub)
1812 {
1813 case SUBLANG_FRISIAN_NETHERLANDS: return N("fy_NL");
1814 }
1815 return N("fy");
1816 case LANG_FULFULDE:
1817 /* Spoken in Nigeria, Guinea, Senegal, Mali, Niger, Cameroon, Benin. */
1818 switch (sub)
1819 {
1820 case SUBLANG_DEFAULT: return N("ff_NG");
1821 }
1822 return N("ff");
1823 case LANG_GAELIC:
1824 switch (sub)
1825 {
1826 case 0x01: /* SCOTTISH */
1827 /* old, superseded by LANG_SCOTTISH_GAELIC */
1828 return N("gd_GB");
1829 case SUBLANG_IRISH_IRELAND: return N("ga_IE");
1830 }
1831 return N("ga");
1832 case LANG_GALICIAN:
1833 switch (sub)
1834 {
1835 case SUBLANG_GALICIAN_SPAIN: return N("gl_ES");
1836 }
1837 return N("gl");
1838 case LANG_GEORGIAN:
1839 switch (sub)
1840 {
1841 case SUBLANG_GEORGIAN_GEORGIA: return N("ka_GE");
1842 }
1843 return N("ka");
1844 case LANG_GERMAN:
1845 switch (sub)
1846 {
1847 case SUBLANG_GERMAN: return N("de_DE");
1848 case SUBLANG_GERMAN_SWISS: return N("de_CH");
1849 case SUBLANG_GERMAN_AUSTRIAN: return N("de_AT");
1850 case SUBLANG_GERMAN_LUXEMBOURG: return N("de_LU");
1851 case SUBLANG_GERMAN_LIECHTENSTEIN: return N("de_LI");
1852 }
1853 return N("de");
1854 case LANG_GREEK:
1855 switch (sub)
1856 {
1857 case SUBLANG_GREEK_GREECE: return N("el_GR");
1858 }
1859 return N("el");
1860 case LANG_GREENLANDIC:
1861 switch (sub)
1862 {
1863 case SUBLANG_GREENLANDIC_GREENLAND: return N("kl_GL");
1864 }
1865 return N("kl");
1866 case LANG_GUARANI:
1867 switch (sub)
1868 {
1869 case SUBLANG_DEFAULT: return N("gn_PY");
1870 }
1871 return N("gn");
1872 case LANG_GUJARATI:
1873 switch (sub)
1874 {
1875 case SUBLANG_GUJARATI_INDIA: return N("gu_IN");
1876 }
1877 return N("gu");
1878 case LANG_HAUSA:
1879 switch (sub)
1880 {
1881 case 0x1f: return N("ha");
1882 case SUBLANG_HAUSA_NIGERIA_LATIN: return N("ha_NG");
1883 }
1884 return N("ha");
1885 case LANG_HAWAIIAN:
1886 /* FIXME: Do they mean Hawaiian ("haw_US", 1000 speakers)
1887 or Hawaii Creole English ("cpe_US", 600000 speakers)? */
1888 switch (sub)
1889 {
1890 case SUBLANG_DEFAULT: return N("cpe_US");
1891 }
1892 return N("cpe");
1893 case LANG_HEBREW:
1894 switch (sub)
1895 {
1896 case SUBLANG_HEBREW_ISRAEL: return N("he_IL");
1897 }
1898 return N("he");
1899 case LANG_HINDI:
1900 switch (sub)
1901 {
1902 case SUBLANG_HINDI_INDIA: return N("hi_IN");
1903 }
1904 return N("hi");
1905 case LANG_HUNGARIAN:
1906 switch (sub)
1907 {
1908 case SUBLANG_HUNGARIAN_HUNGARY: return N("hu_HU");
1909 }
1910 return N("hu");
1911 case LANG_IBIBIO:
1912 switch (sub)
1913 {
1914 case SUBLANG_DEFAULT: return N("nic_NG");
1915 }
1916 return N("nic");
1917 case LANG_ICELANDIC:
1918 switch (sub)
1919 {
1920 case SUBLANG_ICELANDIC_ICELAND: return N("is_IS");
1921 }
1922 return N("is");
1923 case LANG_IGBO:
1924 switch (sub)
1925 {
1926 case SUBLANG_IGBO_NIGERIA: return N("ig_NG");
1927 }
1928 return N("ig");
1929 case LANG_INDONESIAN:
1930 switch (sub)
1931 {
1932 case SUBLANG_INDONESIAN_INDONESIA: return N("id_ID");
1933 }
1934 return N("id");
1935 case LANG_INUKTITUT:
1936 switch (sub)
1937 {
1938 case 0x1e: return N("iu"); /* syllabic */
1939 case SUBLANG_INUKTITUT_CANADA: return N("iu_CA"); /* syllabic */
1940 case 0x1f: return NM("iu","@latin");
1941 case SUBLANG_INUKTITUT_CANADA_LATIN: return NM("iu_CA","@latin");
1942 }
1943 return N("iu");
1944 case LANG_ITALIAN:
1945 switch (sub)
1946 {
1947 case SUBLANG_ITALIAN: return N("it_IT");
1948 case SUBLANG_ITALIAN_SWISS: return N("it_CH");
1949 }
1950 return N("it");
1951 case LANG_JAPANESE:
1952 switch (sub)
1953 {
1954 case SUBLANG_JAPANESE_JAPAN: return N("ja_JP");
1955 }
1956 return N("ja");
1957 case LANG_KANNADA:
1958 switch (sub)
1959 {
1960 case SUBLANG_KANNADA_INDIA: return N("kn_IN");
1961 }
1962 return N("kn");
1963 case LANG_KANURI:
1964 switch (sub)
1965 {
1966 case SUBLANG_DEFAULT: return N("kr_NG");
1967 }
1968 return N("kr");
1969 case LANG_KASHMIRI:
1970 switch (sub)
1971 {
1972 case SUBLANG_DEFAULT: return N("ks_PK");
1973 case SUBLANG_KASHMIRI_INDIA: return N("ks_IN");
1974 }
1975 return N("ks");
1976 case LANG_KAZAK:
1977 switch (sub)
1978 {
1979 case SUBLANG_KAZAK_KAZAKHSTAN: return N("kk_KZ");
1980 }
1981 return N("kk");
1982 case LANG_KICHE:
1983 /* FIXME: Adjust this when such locales appear on Unix. */
1984 switch (sub)
1985 {
1986 case SUBLANG_KICHE_GUATEMALA: return N("qut_GT");
1987 }
1988 return N("qut");
1989 case LANG_KINYARWANDA:
1990 switch (sub)
1991 {
1992 case SUBLANG_KINYARWANDA_RWANDA: return N("rw_RW");
1993 }
1994 return N("rw");
1995 case LANG_KONKANI:
1996 switch (sub)
1997 {
1998 case SUBLANG_KONKANI_INDIA: return N("kok_IN");
1999 }
2000 return N("kok");
2001 case LANG_KOREAN:
2002 switch (sub)
2003 {
2004 case SUBLANG_DEFAULT: return N("ko_KR");
2005 }
2006 return N("ko");
2007 case LANG_KYRGYZ:
2008 switch (sub)
2009 {
2010 case SUBLANG_KYRGYZ_KYRGYZSTAN: return N("ky_KG");
2011 }
2012 return N("ky");
2013 case LANG_LAO:
2014 switch (sub)
2015 {
2016 case SUBLANG_LAO_LAOS: return N("lo_LA");
2017 }
2018 return N("lo");
2019 case LANG_LATIN:
2020 switch (sub)
2021 {
2022 case SUBLANG_DEFAULT: return N("la_VA");
2023 }
2024 return N("la");
2025 case LANG_LATVIAN:
2026 switch (sub)
2027 {
2028 case SUBLANG_LATVIAN_LATVIA: return N("lv_LV");
2029 }
2030 return N("lv");
2031 case LANG_LITHUANIAN:
2032 switch (sub)
2033 {
2034 case SUBLANG_LITHUANIAN_LITHUANIA: return N("lt_LT");
2035 }
2036 return N("lt");
2037 case LANG_LUXEMBOURGISH:
2038 switch (sub)
2039 {
2040 case SUBLANG_LUXEMBOURGISH_LUXEMBOURG: return N("lb_LU");
2041 }
2042 return N("lb");
2043 case LANG_MACEDONIAN:
2044 switch (sub)
2045 {
2046 case SUBLANG_MACEDONIAN_MACEDONIA: return N("mk_MK");
2047 }
2048 return N("mk");
2049 case LANG_MALAY:
2050 switch (sub)
2051 {
2052 case SUBLANG_MALAY_MALAYSIA: return N("ms_MY");
2053 case SUBLANG_MALAY_BRUNEI_DARUSSALAM: return N("ms_BN");
2054 }
2055 return N("ms");
2056 case LANG_MALAYALAM:
2057 switch (sub)
2058 {
2059 case SUBLANG_MALAYALAM_INDIA: return N("ml_IN");
2060 }
2061 return N("ml");
2062 case LANG_MALTESE:
2063 switch (sub)
2064 {
2065 case SUBLANG_MALTESE_MALTA: return N("mt_MT");
2066 }
2067 return N("mt");
2068 case LANG_MANIPURI:
2069 switch (sub)
2070 {
2071 case SUBLANG_DEFAULT: return N("mni_IN");
2072 }
2073 return N("mni");
2074 case LANG_MAORI:
2075 switch (sub)
2076 {
2077 case SUBLANG_MAORI_NEW_ZEALAND: return N("mi_NZ");
2078 }
2079 return N("mi");
2080 case LANG_MAPUDUNGUN:
2081 switch (sub)
2082 {
2083 case SUBLANG_MAPUDUNGUN_CHILE: return N("arn_CL");
2084 }
2085 return N("arn");
2086 case LANG_MARATHI:
2087 switch (sub)
2088 {
2089 case SUBLANG_MARATHI_INDIA: return N("mr_IN");
2090 }
2091 return N("mr");
2092 case LANG_MOHAWK:
2093 switch (sub)
2094 {
2095 case SUBLANG_MOHAWK_CANADA: return N("moh_CA");
2096 }
2097 return N("moh");
2098 case LANG_MONGOLIAN:
2099 switch (sub)
2100 {
2101 case SUBLANG_MONGOLIAN_CYRILLIC_MONGOLIA: case 0x1e: return N("mn_MN");
2102 case SUBLANG_MONGOLIAN_PRC: case 0x1f: return N("mn_CN");
2103 }
2104 return N("mn"); /* Ambiguous: could be "mn_CN" or "mn_MN". */
2105 case LANG_NEPALI:
2106 switch (sub)
2107 {
2108 case SUBLANG_NEPALI_NEPAL: return N("ne_NP");
2109 case SUBLANG_NEPALI_INDIA: return N("ne_IN");
2110 }
2111 return N("ne");
2112 case LANG_NORWEGIAN:
2113 switch (sub)
2114 {
2115 case 0x1f: return N("nb");
2116 case SUBLANG_NORWEGIAN_BOKMAL: return N("nb_NO");
2117 case 0x1e: return N("nn");
2118 case SUBLANG_NORWEGIAN_NYNORSK: return N("nn_NO");
2119 }
2120 return N("no");
2121 case LANG_OCCITAN:
2122 switch (sub)
2123 {
2124 case SUBLANG_OCCITAN_FRANCE: return N("oc_FR");
2125 }
2126 return N("oc");
2127 case LANG_ORIYA:
2128 switch (sub)
2129 {
2130 case SUBLANG_ORIYA_INDIA: return N("or_IN");
2131 }
2132 return N("or");
2133 case LANG_OROMO:
2134 switch (sub)
2135 {
2136 case SUBLANG_DEFAULT: return N("om_ET");
2137 }
2138 return N("om");
2139 case LANG_PAPIAMENTU:
2140 switch (sub)
2141 {
2142 case SUBLANG_DEFAULT: return N("pap_AN");
2143 }
2144 return N("pap");
2145 case LANG_PASHTO:
2146 switch (sub)
2147 {
2148 case SUBLANG_PASHTO_AFGHANISTAN: return N("ps_AF");
2149 }
2150 return N("ps"); /* Ambiguous: could be "ps_PK" or "ps_AF". */
2151 case LANG_POLISH:
2152 switch (sub)
2153 {
2154 case SUBLANG_POLISH_POLAND: return N("pl_PL");
2155 }
2156 return N("pl");
2157 case LANG_PORTUGUESE:
2158 switch (sub)
2159 {
2160 /* Hmm. SUBLANG_PORTUGUESE_BRAZILIAN == SUBLANG_DEFAULT.
2161 Same phenomenon as SUBLANG_ENGLISH_US == SUBLANG_DEFAULT. */
2162 case SUBLANG_PORTUGUESE_BRAZILIAN: return N("pt_BR");
2163 case SUBLANG_PORTUGUESE: return N("pt_PT");
2164 }
2165 return N("pt");
2166 case LANG_PUNJABI:
2167 switch (sub)
2168 {
2169 case SUBLANG_PUNJABI_INDIA: return N("pa_IN"); /* Gurmukhi script */
2170 case SUBLANG_PUNJABI_PAKISTAN: return N("pa_PK"); /* Arabic script */
2171 }
2172 return N("pa");
2173 case LANG_QUECHUA:
2174 /* Note: Microsoft uses the non-ISO language code "quz". */
2175 switch (sub)
2176 {
2177 case SUBLANG_QUECHUA_BOLIVIA: return N("qu_BO");
2178 case SUBLANG_QUECHUA_ECUADOR: return N("qu_EC");
2179 case SUBLANG_QUECHUA_PERU: return N("qu_PE");
2180 }
2181 return N("qu");
2182 case LANG_ROMANIAN:
2183 switch (sub)
2184 {
2185 case SUBLANG_ROMANIAN_ROMANIA: return N("ro_RO");
2186 case SUBLANG_ROMANIAN_MOLDOVA: return N("ro_MD");
2187 }
2188 return N("ro");
2189 case LANG_ROMANSH:
2190 switch (sub)
2191 {
2192 case SUBLANG_ROMANSH_SWITZERLAND: return N("rm_CH");
2193 }
2194 return N("rm");
2195 case LANG_RUSSIAN:
2196 switch (sub)
2197 {
2198 case SUBLANG_RUSSIAN_RUSSIA: return N("ru_RU");
2199 case SUBLANG_RUSSIAN_MOLDAVIA: return N("ru_MD");
2200 }
2201 return N("ru"); /* Ambiguous: could be "ru_RU" or "ru_UA" or "ru_MD". */
2202 case LANG_SAMI:
2203 switch (sub)
2204 {
2205 /* Northern Sami */
2206 case 0x00: return N("se");
2207 case SUBLANG_SAMI_NORTHERN_NORWAY: return N("se_NO");
2208 case SUBLANG_SAMI_NORTHERN_SWEDEN: return N("se_SE");
2209 case SUBLANG_SAMI_NORTHERN_FINLAND: return N("se_FI");
2210 /* Lule Sami */
2211 case 0x1f: return N("smj");
2212 case SUBLANG_SAMI_LULE_NORWAY: return N("smj_NO");
2213 case SUBLANG_SAMI_LULE_SWEDEN: return N("smj_SE");
2214 /* Southern Sami */
2215 case 0x1e: return N("sma");
2216 case SUBLANG_SAMI_SOUTHERN_NORWAY: return N("sma_NO");
2217 case SUBLANG_SAMI_SOUTHERN_SWEDEN: return N("sma_SE");
2218 /* Skolt Sami */
2219 case 0x1d: return N("sms");
2220 case SUBLANG_SAMI_SKOLT_FINLAND: return N("sms_FI");
2221 /* Inari Sami */
2222 case 0x1c: return N("smn");
2223 case SUBLANG_SAMI_INARI_FINLAND: return N("smn_FI");
2224 }
2225 return N("se"); /* or "smi"? */
2226 case LANG_SANSKRIT:
2227 switch (sub)
2228 {
2229 case SUBLANG_SANSKRIT_INDIA: return N("sa_IN");
2230 }
2231 return N("sa");
2232 case LANG_SCOTTISH_GAELIC:
2233 switch (sub)
2234 {
2235 case SUBLANG_DEFAULT: return N("gd_GB");
2236 }
2237 return N("gd");
2238 case LANG_SINDHI:
2239 switch (sub)
2240 {
2241 case SUBLANG_SINDHI_INDIA: return N("sd_IN");
2242 case SUBLANG_SINDHI_PAKISTAN: return N("sd_PK");
2243 /*case SUBLANG_SINDHI_AFGHANISTAN: return N("sd_AF");*/
2244 }
2245 return N("sd");
2246 case LANG_SINHALESE:
2247 switch (sub)
2248 {
2249 case SUBLANG_SINHALESE_SRI_LANKA: return N("si_LK");
2250 }
2251 return N("si");
2252 case LANG_SLOVAK:
2253 switch (sub)
2254 {
2255 case SUBLANG_SLOVAK_SLOVAKIA: return N("sk_SK");
2256 }
2257 return N("sk");
2258 case LANG_SLOVENIAN:
2259 switch (sub)
2260 {
2261 case SUBLANG_SLOVENIAN_SLOVENIA: return N("sl_SI");
2262 }
2263 return N("sl");
2264 case LANG_SOMALI:
2265 switch (sub)
2266 {
2267 case SUBLANG_DEFAULT: return N("so_SO");
2268 }
2269 return N("so");
2270 case LANG_SORBIAN:
2271 switch (sub)
2272 {
2273 /* Upper Sorbian */
2274 case 0x00: return N("hsb");
2275 case SUBLANG_UPPER_SORBIAN_GERMANY: return N("hsb_DE");
2276 /* Lower Sorbian */
2277 case 0x1f: return N("dsb");
2278 case SUBLANG_LOWER_SORBIAN_GERMANY: return N("dsb_DE");
2279 }
2280 return N("wen");
2281 case LANG_SOTHO:
2282 /* <https://docs.microsoft.com/en-us/windows/desktop/Intl/language-identifier-constants-and-strings>
2283 calls it "Sesotho sa Leboa"; according to
2284 <https://www.ethnologue.com/show_language.asp?code=nso>
2285 <https://www.ethnologue.com/show_language.asp?code=sot>
2286 it's the same as Northern Sotho. */
2287 switch (sub)
2288 {
2289 case SUBLANG_SOTHO_SOUTH_AFRICA: return N("nso_ZA");
2290 }
2291 return N("nso");
2292 case LANG_SPANISH:
2293 switch (sub)
2294 {
2295 case SUBLANG_SPANISH: return N("es_ES");
2296 case SUBLANG_SPANISH_MEXICAN: return N("es_MX");
2297 case SUBLANG_SPANISH_MODERN:
2298 return NM("es_ES","@modern"); /* not seen on Unix */
2299 case SUBLANG_SPANISH_GUATEMALA: return N("es_GT");
2300 case SUBLANG_SPANISH_COSTA_RICA: return N("es_CR");
2301 case SUBLANG_SPANISH_PANAMA: return N("es_PA");
2302 case SUBLANG_SPANISH_DOMINICAN_REPUBLIC: return N("es_DO");
2303 case SUBLANG_SPANISH_VENEZUELA: return N("es_VE");
2304 case SUBLANG_SPANISH_COLOMBIA: return N("es_CO");
2305 case SUBLANG_SPANISH_PERU: return N("es_PE");
2306 case SUBLANG_SPANISH_ARGENTINA: return N("es_AR");
2307 case SUBLANG_SPANISH_ECUADOR: return N("es_EC");
2308 case SUBLANG_SPANISH_CHILE: return N("es_CL");
2309 case SUBLANG_SPANISH_URUGUAY: return N("es_UY");
2310 case SUBLANG_SPANISH_PARAGUAY: return N("es_PY");
2311 case SUBLANG_SPANISH_BOLIVIA: return N("es_BO");
2312 case SUBLANG_SPANISH_EL_SALVADOR: return N("es_SV");
2313 case SUBLANG_SPANISH_HONDURAS: return N("es_HN");
2314 case SUBLANG_SPANISH_NICARAGUA: return N("es_NI");
2315 case SUBLANG_SPANISH_PUERTO_RICO: return N("es_PR");
2316 case SUBLANG_SPANISH_US: return N("es_US");
2317 }
2318 return N("es");
2319 case LANG_SUTU:
2320 switch (sub)
2321 {
2322 case SUBLANG_DEFAULT: return N("bnt_TZ"); /* or "st_LS" or "nso_ZA"? */
2323 }
2324 return N("bnt");
2325 case LANG_SWAHILI:
2326 switch (sub)
2327 {
2328 case SUBLANG_SWAHILI_KENYA: return N("sw_KE");
2329 }
2330 return N("sw");
2331 case LANG_SWEDISH:
2332 switch (sub)
2333 {
2334 case SUBLANG_SWEDISH_SWEDEN: return N("sv_SE");
2335 case SUBLANG_SWEDISH_FINLAND: return N("sv_FI");
2336 }
2337 return N("sv");
2338 case LANG_SYRIAC:
2339 switch (sub)
2340 {
2341 case SUBLANG_SYRIAC_SYRIA: return N("syr_SY"); /* An extinct language. */
2342 }
2343 return N("syr");
2344 case LANG_TAGALOG:
2345 switch (sub)
2346 {
2347 case SUBLANG_TAGALOG_PHILIPPINES: return N("tl_PH"); /* or "fil_PH"? */
2348 }
2349 return N("tl"); /* or "fil"? */
2350 case LANG_TAJIK:
2351 switch (sub)
2352 {
2353 case 0x1f: return N("tg");
2354 case SUBLANG_TAJIK_TAJIKISTAN: return N("tg_TJ");
2355 }
2356 return N("tg");
2357 case LANG_TAMAZIGHT:
2358 /* Note: Microsoft uses the non-ISO language code "tmz". */
2359 switch (sub)
2360 {
2361 case SUBLANG_TAMAZIGHT_ARABIC: return N("ber_MA");
2362 case 0x1f: return NM("ber","@latin");
2363 case SUBLANG_TAMAZIGHT_ALGERIA_LATIN: return N("ber_DZ");
2364 }
2365 return N("ber");
2366 case LANG_TAMIL:
2367 switch (sub)
2368 {
2369 case SUBLANG_TAMIL_INDIA: return N("ta_IN");
2370 }
2371 return N("ta"); /* Ambiguous: could be "ta_IN" or "ta_LK" or "ta_SG". */
2372 case LANG_TATAR:
2373 switch (sub)
2374 {
2375 case SUBLANG_TATAR_RUSSIA: return N("tt_RU");
2376 }
2377 return N("tt");
2378 case LANG_TELUGU:
2379 switch (sub)
2380 {
2381 case SUBLANG_TELUGU_INDIA: return N("te_IN");
2382 }
2383 return N("te");
2384 case LANG_THAI:
2385 switch (sub)
2386 {
2387 case SUBLANG_THAI_THAILAND: return N("th_TH");
2388 }
2389 return N("th");
2390 case LANG_TIBETAN:
2391 switch (sub)
2392 {
2393 case SUBLANG_TIBETAN_PRC:
2394 /* Most Tibetans would not like "bo_CN". But Tibet does not yet
2395 have a country code of its own. */
2396 return N("bo");
2397 case SUBLANG_TIBETAN_BHUTAN: return N("bo_BT");
2398 }
2399 return N("bo");
2400 case LANG_TIGRINYA:
2401 switch (sub)
2402 {
2403 case SUBLANG_TIGRINYA_ETHIOPIA: return N("ti_ET");
2404 case SUBLANG_TIGRINYA_ERITREA: return N("ti_ER");
2405 }
2406 return N("ti");
2407 case LANG_TSONGA:
2408 switch (sub)
2409 {
2410 case SUBLANG_DEFAULT: return N("ts_ZA");
2411 }
2412 return N("ts");
2413 case LANG_TSWANA:
2414 /* Spoken in South Africa, Botswana. */
2415 switch (sub)
2416 {
2417 case SUBLANG_TSWANA_SOUTH_AFRICA: return N("tn_ZA");
2418 }
2419 return N("tn");
2420 case LANG_TURKISH:
2421 switch (sub)
2422 {
2423 case SUBLANG_TURKISH_TURKEY: return N("tr_TR");
2424 }
2425 return N("tr");
2426 case LANG_TURKMEN:
2427 switch (sub)
2428 {
2429 case SUBLANG_TURKMEN_TURKMENISTAN: return N("tk_TM");
2430 }
2431 return N("tk");
2432 case LANG_UIGHUR:
2433 switch (sub)
2434 {
2435 case SUBLANG_UIGHUR_PRC: return N("ug_CN");
2436 }
2437 return N("ug");
2438 case LANG_UKRAINIAN:
2439 switch (sub)
2440 {
2441 case SUBLANG_UKRAINIAN_UKRAINE: return N("uk_UA");
2442 }
2443 return N("uk");
2444 case LANG_URDU:
2445 switch (sub)
2446 {
2447 case SUBLANG_URDU_PAKISTAN: return N("ur_PK");
2448 case SUBLANG_URDU_INDIA: return N("ur_IN");
2449 }
2450 return N("ur");
2451 case LANG_UZBEK:
2452 switch (sub)
2453 {
2454 case 0x1f: return N("uz");
2455 case SUBLANG_UZBEK_LATIN: return N("uz_UZ");
2456 case 0x1e: return NM("uz","@cyrillic");
2457 case SUBLANG_UZBEK_CYRILLIC: return NM("uz_UZ","@cyrillic");
2458 }
2459 return N("uz");
2460 case LANG_VENDA:
2461 switch (sub)
2462 {
2463 case SUBLANG_DEFAULT: return N("ve_ZA");
2464 }
2465 return N("ve");
2466 case LANG_VIETNAMESE:
2467 switch (sub)
2468 {
2469 case SUBLANG_VIETNAMESE_VIETNAM: return N("vi_VN");
2470 }
2471 return N("vi");
2472 case LANG_WELSH:
2473 switch (sub)
2474 {
2475 case SUBLANG_WELSH_UNITED_KINGDOM: return N("cy_GB");
2476 }
2477 return N("cy");
2478 case LANG_WOLOF:
2479 switch (sub)
2480 {
2481 case SUBLANG_WOLOF_SENEGAL: return N("wo_SN");
2482 }
2483 return N("wo");
2484 case LANG_XHOSA:
2485 switch (sub)
2486 {
2487 case SUBLANG_XHOSA_SOUTH_AFRICA: return N("xh_ZA");
2488 }
2489 return N("xh");
2490 case LANG_YAKUT:
2491 switch (sub)
2492 {
2493 case SUBLANG_YAKUT_RUSSIA: return N("sah_RU");
2494 }
2495 return N("sah");
2496 case LANG_YI:
2497 switch (sub)
2498 {
2499 case SUBLANG_YI_PRC: return N("ii_CN");
2500 }
2501 return N("ii");
2502 case LANG_YIDDISH:
2503 switch (sub)
2504 {
2505 case SUBLANG_DEFAULT: return N("yi_IL");
2506 }
2507 return N("yi");
2508 case LANG_YORUBA:
2509 switch (sub)
2510 {
2511 case SUBLANG_YORUBA_NIGERIA: return N("yo_NG");
2512 }
2513 return N("yo");
2514 case LANG_ZULU:
2515 switch (sub)
2516 {
2517 case SUBLANG_ZULU_SOUTH_AFRICA: return N("zu_ZA");
2518 }
2519 return N("zu");
2520 default: return N("C");
2521 }
2522 }
2523 #undef NM
2524 #undef N
2525 }
2526
2527 # if !defined IN_LIBINTL
2528 static
2529 # endif
2530 const char *
2531 gl_locale_name_from_win32_LCID (LCID lcid)
2532 {
2533 LANGID langid;
2534
2535 /* Strip off the sorting rules, keep only the language part. */
2536 langid = LANGIDFROMLCID (lcid);
2537
2538 return gl_locale_name_from_win32_LANGID (langid);
2539 }
2540
2541 # ifdef WINDOWS_NATIVE
2542
2543 /* Two variables to interface between get_lcid and the EnumLocales
2544 callback function below. */
2545 static LCID found_lcid;
2546 static char lname[LC_MAX * (LOCALE_NAME_MAX_LENGTH + 1) + 1];
2547
2548 /* Callback function for EnumLocales. */
2549 static BOOL CALLBACK
2550 enum_locales_fn (LPSTR locale_num_str)
2551 {
2552 char *endp;
2553 char locval[2 * LOCALE_NAME_MAX_LENGTH + 1 + 1];
2554 LCID try_lcid = strtoul (locale_num_str, &endp, 16);
2555
2556 if (GetLocaleInfo (try_lcid, LOCALE_SENGLANGUAGE,
2557 locval, LOCALE_NAME_MAX_LENGTH))
2558 {
2559 strcat (locval, "_");
2560 if (GetLocaleInfo (try_lcid, LOCALE_SENGCOUNTRY,
2561 locval + strlen (locval), LOCALE_NAME_MAX_LENGTH))
2562 {
2563 size_t locval_len = strlen (locval);
2564
2565 if (strncmp (locval, lname, locval_len) == 0
2566 && (lname[locval_len] == '.'
2567 || lname[locval_len] == '\0'))
2568 {
2569 found_lcid = try_lcid;
2570 return FALSE;
2571 }
2572 }
2573 }
2574 return TRUE;
2575 }
2576
2577 /* This lock protects the get_lcid against multiple simultaneous calls. */
2578 gl_lock_define_initialized(static, get_lcid_lock)
2579
2580 /* Return the Locale ID (LCID) number given the locale's name, a
2581 string, in LOCALE_NAME. This works by enumerating all the locales
2582 supported by the system, until we find one whose name matches
2583 LOCALE_NAME. */
2584 static LCID
2585 get_lcid (const char *locale_name)
2586 {
2587 /* A simple cache. */
2588 static LCID last_lcid;
2589 static char last_locale[1000];
2590
2591 /* Lock while looking for an LCID, to protect access to static
2592 variables: last_lcid, last_locale, found_lcid, and lname. */
2593 gl_lock_lock (get_lcid_lock);
2594 if (last_lcid > 0 && strcmp (locale_name, last_locale) == 0)
2595 {
2596 gl_lock_unlock (get_lcid_lock);
2597 return last_lcid;
2598 }
2599 strncpy (lname, locale_name, sizeof (lname) - 1);
2600 lname[sizeof (lname) - 1] = '\0';
2601 found_lcid = 0;
2602 EnumSystemLocales (enum_locales_fn, LCID_SUPPORTED);
2603 if (found_lcid > 0)
2604 {
2605 last_lcid = found_lcid;
2606 strcpy (last_locale, locale_name);
2607 }
2608 gl_lock_unlock (get_lcid_lock);
2609 return found_lcid;
2610 }
2611
2612 # endif
2613 #endif
2614
2615
2616 const char *
2617 gl_locale_name_thread_unsafe (int category, _GL_UNUSED const char *categoryname)
2618 {
2619 if (category == LC_ALL)
2620 /* Invalid argument. */
2621 abort ();
2622 #if HAVE_GOOD_USELOCALE
2623 {
2624 locale_t thread_locale = uselocale (NULL);
2625 if (thread_locale != LC_GLOBAL_LOCALE)
2626 {
2627 struct string_with_storage ret =
2628 getlocalename_l_unsafe (category, thread_locale);
2629 return ret.value;
2630 }
2631 }
2632 #endif
2633 /* On WINDOWS_NATIVE, don't use GetThreadLocale() here, because when
2634 SetThreadLocale has not been called - which is a very frequent case -
2635 the value of GetThreadLocale() ignores past calls to 'setlocale'. */
2636 return NULL;
2637 }
2638
2639 /* XPG3 defines the result of 'setlocale (category, NULL)' as:
2640 "Directs 'setlocale()' to query 'category' and return the current
2641 setting of 'local'."
2642 However it does not specify the exact format. Neither do SUSV2 and
2643 ISO C 99. So we can use this feature only on selected systems, where
2644 the return value has the XPG syntax
2645 language[_territory][.codeset][@modifier]
2646 or
2647 C[.codeset]
2648 namely
2649 - glibc systems (except for aliases from /usr/share/locale/locale.alias,
2650 that no one uses any more),
2651 - musl libc,
2652 - FreeBSD, NetBSD,
2653 - Solaris,
2654 - Haiku.
2655 We cannot use it on
2656 - macOS, Cygwin (because these systems have a facility for customizing the
2657 default locale, and setlocale (category, NULL) ignores it and merely
2658 returns "C" or "C.UTF-8"),
2659 - OpenBSD (because on OpenBSD ≤ 6.1, LC_ALL does not set the LC_NUMERIC,
2660 LC_TIME, LC_COLLATE, LC_MONETARY categories).
2661 - AIX (because here the return value has the syntax
2662 language[_script]_territory[.codeset]
2663 e.g. zh_Hans_CN.UTF-8),
2664 - native Windows (because it has locale names such as French_France.1252),
2665 - Android (because it only supports the C and C.UTF-8 locales).
2666 */
2667 #if defined _LIBC || ((defined __GLIBC__ && __GLIBC__ >= 2) && !defined __UCLIBC__) || MUSL_LIBC || defined __FreeBSD__ || defined __NetBSD__ || defined __sun || defined __HAIKU__
2668 # define HAVE_LOCALE_NULL
2669 #endif
2670
2671 const char *
2672 gl_locale_name_posix_unsafe (int category, _GL_UNUSED const char *categoryname)
2673 {
2674 if (category == LC_ALL)
2675 /* Invalid argument. */
2676 abort ();
2677 #if defined WINDOWS_NATIVE
2678 if (LC_MIN <= category && category <= LC_MAX)
2679 {
2680 const char *locname =
2681 /* setlocale_null (category) is identical to setlocale (category, NULL)
2682 on this platform. */
2683 setlocale (category, NULL);
2684
2685 /* Convert locale name to LCID. We don't want to use
2686 LocaleNameToLCID because (a) it is only available since Vista,
2687 and (b) it doesn't accept locale names returned by 'setlocale'. */
2688 LCID lcid = get_lcid (locname);
2689
2690 if (lcid > 0)
2691 return gl_locale_name_from_win32_LCID (lcid);
2692 }
2693 #endif
2694 {
2695 const char *locname;
2696
2697 /* Use the POSIX methods of looking to 'LC_ALL', 'LC_xxx', and 'LANG'.
2698 On some systems this can be done by the 'setlocale' function itself. */
2699 #if defined HAVE_LC_MESSAGES && defined HAVE_LOCALE_NULL
2700 /* All platforms for which HAVE_LOCALE_NULL is defined happen to have
2701 SETLOCALE_NULL_ONE_MTSAFE defined to 1. Therefore it is OK, here,
2702 to call setlocale_null_unlocked instead of setlocale_null. */
2703 locname = setlocale_null_unlocked (category);
2704 #else
2705 /* On other systems we ignore what setlocale reports and instead look at the
2706 environment variables directly. This is necessary
2707 1. on systems which have a facility for customizing the default locale
2708 (macOS, native Windows, Cygwin) and where the system's setlocale()
2709 function ignores this default locale (macOS, Cygwin), in two cases:
2710 a. when the user missed to use the setlocale() override from libintl
2711 (for example by not including <libintl.h>),
2712 b. when setlocale supports only the "C" locale, such as on Cygwin
2713 1.5.x. In this case even the override from libintl cannot help.
2714 2. on all systems where setlocale supports only the "C" locale. */
2715 /* Strictly speaking, it is a POSIX violation to look at the environment
2716 variables regardless whether setlocale has been called or not. POSIX
2717 says:
2718 "For C-language programs, the POSIX locale shall be the
2719 default locale when the setlocale() function is not called."
2720 But we assume that all programs that use internationalized APIs call
2721 setlocale (LC_ALL, ""). */
2722 locname = gl_locale_name_environ (category, categoryname);
2723 #endif
2724 /* Convert the locale name from the format returned by setlocale() or found
2725 in the environment variables to the XPG syntax. */
2726 #if defined WINDOWS_NATIVE
2727 if (locname != NULL)
2728 {
2729 /* Convert locale name to LCID. We don't want to use
2730 LocaleNameToLCID because (a) it is only available since Vista,
2731 and (b) it doesn't accept locale names returned by 'setlocale'. */
2732 LCID lcid = get_lcid (locname);
2733
2734 if (lcid > 0)
2735 return gl_locale_name_from_win32_LCID (lcid);
2736 }
2737 #endif
2738 return locname;
2739 }
2740 }
2741
2742 const char *
2743 gl_locale_name_default (void)
2744 {
2745 /* POSIX:2001 says:
2746 "All implementations shall define a locale as the default locale, to be
2747 invoked when no environment variables are set, or set to the empty
2748 string. This default locale can be the POSIX locale or any other
2749 implementation-defined locale. Some implementations may provide
2750 facilities for local installation administrators to set the default
2751 locale, customizing it for each location. POSIX:2001 does not require
2752 such a facility.
2753
2754 The systems with such a facility are Mac OS X and Windows: They provide a
2755 GUI that allows the user to choose a locale.
2756 - On Mac OS X, by default, none of LC_* or LANG are set. Starting with
2757 Mac OS X 10.4 or 10.5, LANG is set for processes launched by the
2758 'Terminal' application (but sometimes to an incorrect value "UTF-8").
2759 When no environment variable is set, setlocale (LC_ALL, "") uses the
2760 "C" locale.
2761 - On native Windows, by default, none of LC_* or LANG are set.
2762 When no environment variable is set, setlocale (LC_ALL, "") uses the
2763 locale chosen by the user.
2764 - On Cygwin 1.5.x, by default, none of LC_* or LANG are set.
2765 When no environment variable is set, setlocale (LC_ALL, "") uses the
2766 "C" locale.
2767 - On Cygwin 1.7, by default, LANG is set to "C.UTF-8" when the default
2768 ~/.profile is executed.
2769 When no environment variable is set, setlocale (LC_ALL, "") uses the
2770 "C.UTF-8" locale, which operates in the same way as the "C" locale.
2771 */
2772
2773 #if !(HAVE_CFPREFERENCESCOPYAPPVALUE || defined WINDOWS_NATIVE || defined __CYGWIN__)
2774
2775 /* The system does not have a way of setting the locale, other than the
2776 POSIX specified environment variables. We use C as default locale. */
2777 return "C";
2778
2779 #else
2780
2781 /* Return an XPG style locale name language[_territory][@modifier].
2782 Don't even bother determining the codeset; it's not useful in this
2783 context, because message catalogs are not specific to a single
2784 codeset. */
2785
2786 # if HAVE_CFPREFERENCESCOPYAPPVALUE
2787 /* Mac OS X 10.4 or newer */
2788 /* Don't use the API introduced in Mac OS X 10.5, CFLocaleCopyCurrent,
2789 because in macOS 10.13.4 it has the following behaviour:
2790 When two or more languages are specified in the
2791 "System Preferences > Language & Region > Preferred Languages" panel,
2792 it returns en_CC where CC is the territory (even when English is not among
2793 the preferred languages!). What we want instead is what
2794 CFLocaleCopyCurrent returned in earlier macOS releases and what
2795 CFPreferencesCopyAppValue still returns, namely ll_CC where ll is the
2796 first among the preferred languages and CC is the territory. */
2797 {
2798 /* Cache the locale name, since CoreFoundation calls are expensive. */
2799 static const char *cached_localename;
2800
2801 if (cached_localename == NULL)
2802 {
2803 char namebuf[256];
2804 CFTypeRef value =
2805 CFPreferencesCopyAppValue (CFSTR ("AppleLocale"),
2806 kCFPreferencesCurrentApplication);
2807 if (value != NULL && CFGetTypeID (value) == CFStringGetTypeID ())
2808 {
2809 CFStringRef name = (CFStringRef)value;
2810
2811 if (CFStringGetCString (name, namebuf, sizeof (namebuf),
2812 kCFStringEncodingASCII))
2813 {
2814 gl_locale_name_canonicalize (namebuf);
2815 cached_localename = strdup (namebuf);
2816 }
2817 }
2818 if (cached_localename == NULL)
2819 cached_localename = "C";
2820 }
2821 return cached_localename;
2822 }
2823
2824 # endif
2825
2826 # if defined WINDOWS_NATIVE || defined __CYGWIN__ /* Native Windows or Cygwin */
2827 {
2828 LCID lcid;
2829
2830 /* Use native Windows API locale ID. */
2831 lcid = GetThreadLocale ();
2832
2833 return gl_locale_name_from_win32_LCID (lcid);
2834 }
2835 # endif
2836 #endif
2837 }
2838
2839 /* Determine the current locale's name, and canonicalize it into XPG syntax
2840 language[_territory][.codeset][@modifier]
2841 The codeset part in the result is not reliable; the locale_charset()
2842 should be used for codeset information instead.
2843 The result must not be freed. It is only valid in the current thread,
2844 until the next uselocale(), setlocale(), newlocale(), or freelocale()
2845 call. */
2846
2847 const char *
2848 gl_locale_name_unsafe (int category, const char *categoryname)
2849 {
2850 const char *retval;
2851
2852 if (category == LC_ALL)
2853 /* Invalid argument. */
2854 abort ();
2855
2856 retval = gl_locale_name_thread_unsafe (category, categoryname);
2857 if (retval != NULL)
2858 return retval;
2859
2860 retval = gl_locale_name_posix_unsafe (category, categoryname);
2861 if (retval != NULL)
2862 return retval;
2863
2864 return gl_locale_name_default ();
2865 }