summaryrefslogtreecommitdiff
path: root/i18npool/source/isolang/isolang.cxx
blob: c24df3bc765b4c24f25f7938ce9c5ac3373f1a15 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*************************************************************************
 *
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * Copyright 2000, 2010 Oracle and/or its affiliates.
 *
 * OpenOffice.org - a multi-platform office productivity suite
 *
 * This file is part of OpenOffice.org.
 *
 * OpenOffice.org is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License version 3
 * only, as published by the Free Software Foundation.
 *
 * OpenOffice.org is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License version 3 for more details
 * (a copy is included in the LICENSE file that accompanied this code).
 *
 * You should have received a copy of the GNU Lesser General Public License
 * version 3 along with OpenOffice.org.  If not, see
 * <http://www.openoffice.org/license.html>
 * for a copy of the LGPLv3 License.
 *
 ************************************************************************/

#include <rtl/ustring.hxx>
#include <rtl/string.hxx>
#include <rtl/ustrbuf.hxx>
#include <rtl/strbuf.hxx>

#include "i18npool/mslangid.hxx"

// =======================================================================

struct IsoLangEngEntry
{
    LanguageType        mnLang;
    sal_Char            maCountry[3];
};

struct IsoLangNoneStdEntry
{
    LanguageType        mnLang;
    sal_Char            maLangStr[4];
    sal_Char            maCountry[9];
};

struct IsoLangOtherEntry
{
    LanguageType        mnLang;
    const sal_Char*     mpLangStr;
};

// -----------------------------------------------------------------------

// Entries for languages are lower case, for countries upper case, as
// recommended by rfc4646 (obsoletes rfc3066 (obsoletes rfc1766)).
// convertIsoNamesToLanguage() is case insensitive
//
// Sort order: Most used first.
//
// The default entry for a LangID <-> ISO mapping has to be first. For
// conversion of legacy mappings one LangID can map to multiple ISO codes, and
// one ISO code combination can map to multiple LangIDs. For compatibility with
// already existing calls it can also be a sequence as follows:

// LANGUAGE_ENGLISH,    "en", ""
// LANGUAGE_ENGLISH_US, "en", "US"

// Here, in a convertIsoNamesToLanguage() call "en-US" is converted to
// LANGUAGE_ENGLISH_US and "en" is converted to LANGUAGE_ENGLISH. A call with
// "en-ZZ" (not in table) would result in LANGUAGE_ENGLISH because the first
// entry matching the language and not having a country is returned, regardless
// of whether being sorted before or after other entries of the same language
// with some country. To obtain a _locale_ (not language only) in the order
// given, convertLocaleToLanguageWithFallback() must be called.

// If the sequence instead was

// LANGUAGE_ENGLISH_US, "en", "US"
// LANGUAGE_ENGLISH,    "en", ""

// in a convertIsoNamesToLanguage() call "en-US" is still converted to
// LANGUAGE_ENGLISH_US, but "en" is _also_ converted to LANGUAGE_ENGLISH_US
// because no country was passed and it is the first entry to match the
// language, see code. A call with "en-ZZ" (not in table) would still result in
// LANGUAGE_ENGLISH.

/* erAck: 2007-07-05T20:01+0200  TODO: The entire suite's "primary language
 * only" usage and locale fall back should be cleaned up and made consistent. I
 * strongly doubt that most callers exactly expect the behavior described.
 * Currently these primary LangIDs are used literally in OOo code:
 * LANGUAGE_ENGLISH LANGUAGE_CHINESE LANGUAGE_MALAY
 * LANGUAGE_AZERI LANGUAGE_URDU LANGUAGE_KASHMIRI
 */

static MsLangId::IsoLangEntry const aImplIsoLangEntries[] =
{
    // MS-LANGID codes               ISO639-1/2/3 ISO3166
    { LANGUAGE_ENGLISH,                     "en", ""   },
    { LANGUAGE_ENGLISH_US,                  "en", "US" },
    { LANGUAGE_ENGLISH_UK,                  "en", "GB" },
    { LANGUAGE_ENGLISH_AUS,                 "en", "AU" },
    { LANGUAGE_ENGLISH_CAN,                 "en", "CA" },
    { LANGUAGE_FRENCH,                      "fr", "FR" },
    { LANGUAGE_FRENCH,                      "fr", ""   },
    { LANGUAGE_GERMAN,                      "de", "DE" },
    { LANGUAGE_ITALIAN,                     "it", "IT" },
    { LANGUAGE_DUTCH,                       "nl", "NL" },
    { LANGUAGE_SPANISH_MODERN,              "es", "ES" },
    { LANGUAGE_SPANISH_DATED,               "es", "ES" },
    { LANGUAGE_PORTUGUESE,                  "pt", "PT" },
    { LANGUAGE_PORTUGUESE_BRAZILIAN,        "pt", "BR" },
    { LANGUAGE_DANISH,                      "da", "DK" },
    { LANGUAGE_GREEK,                       "el", "GR" },
    { LANGUAGE_CHINESE,                     "zh", ""   },
    { LANGUAGE_CHINESE_SIMPLIFIED,          "zh", "CN" },
    { LANGUAGE_CHINESE_TRADITIONAL,         "zh", "TW" },
    { LANGUAGE_CHINESE_HONGKONG,            "zh", "HK" },
    { LANGUAGE_CHINESE_SINGAPORE,           "zh", "SG" },
    { LANGUAGE_CHINESE_MACAU,               "zh", "MO" },
    { LANGUAGE_ENGLISH_HONG_KONG_SAR,       "en", "HK" },
    { LANGUAGE_JAPANESE,                    "ja", "JP" },
    { LANGUAGE_KOREAN,                      "ko", "KR" },
    { LANGUAGE_KOREAN_JOHAB,                "ko", "KR" },
    { LANGUAGE_USER_KOREAN_NORTH,           "ko", "KP" },
    { LANGUAGE_SWEDISH,                     "sv", "SE" },
    { LANGUAGE_SWEDISH_FINLAND,             "sv", "FI" },
    { LANGUAGE_FINNISH,                     "fi", "FI" },
    { LANGUAGE_RUSSIAN,                     "ru", "RU" },
    { LANGUAGE_TATAR,                       "tt", "RU" },
    { LANGUAGE_ENGLISH_NZ,                  "en", "NZ" },
    { LANGUAGE_ENGLISH_EIRE,                "en", "IE" },
    { LANGUAGE_DUTCH_BELGIAN,               "nl", "BE" },
    { LANGUAGE_FRENCH_BELGIAN,              "fr", "BE" },
    { LANGUAGE_FRENCH_CANADIAN,             "fr", "CA" },
    { LANGUAGE_FRENCH_SWISS,                "fr", "CH" },
    { LANGUAGE_GERMAN_SWISS,                "de", "CH" },
    { LANGUAGE_GERMAN_AUSTRIAN,             "de", "AT" },
    { LANGUAGE_ITALIAN_SWISS,               "it", "CH" },
    { LANGUAGE_ALBANIAN,                    "sq", "AL" },
    { LANGUAGE_ARABIC_SAUDI_ARABIA,         "ar", "SA" },
    { LANGUAGE_ARABIC_EGYPT,                "ar", "EG" },
    { LANGUAGE_ARABIC_UAE,                  "ar", "AE" },
    { LANGUAGE_ARABIC_IRAQ,                 "ar", "IQ" },
    { LANGUAGE_ARABIC_LIBYA,                "ar", "LY" },
    { LANGUAGE_ARABIC_ALGERIA,              "ar", "DZ" },
    { LANGUAGE_ARABIC_MOROCCO,              "ar", "MA" },
    { LANGUAGE_ARABIC_TUNISIA,              "ar", "TN" },
    { LANGUAGE_ARABIC_OMAN,                 "ar", "OM" },
    { LANGUAGE_ARABIC_YEMEN,                "ar", "YE" },
    { LANGUAGE_ARABIC_SYRIA,                "ar", "SY" },
    { LANGUAGE_ARABIC_JORDAN,               "ar", "JO" },
    { LANGUAGE_ARABIC_LEBANON,              "ar", "LB" },
    { LANGUAGE_ARABIC_KUWAIT,               "ar", "KW" },
    { LANGUAGE_ARABIC_BAHRAIN,              "ar", "BH" },
    { LANGUAGE_ARABIC_QATAR,                "ar", "QA" },
    { LANGUAGE_USER_ARABIC_CHAD,            "ar", "TD" },
    { LANGUAGE_USER_ARABIC_COMOROS,         "ar", "KM" },
    { LANGUAGE_USER_ARABIC_DJIBOUTI,        "ar", "DJ" },
    { LANGUAGE_USER_ARABIC_ERITREA,         "ar", "ER" },
    { LANGUAGE_USER_ARABIC_ISRAEL,          "ar", "IL" },
    { LANGUAGE_USER_ARABIC_MAURITANIA,      "ar", "MR" },
    { LANGUAGE_USER_ARABIC_PALESTINE,       "ar", "PS" },
    { LANGUAGE_USER_ARABIC_SOMALIA,         "ar", "SO" },
    { LANGUAGE_USER_ARABIC_SUDAN,           "ar", "SD" },
    { LANGUAGE_ARABIC_PRIMARY_ONLY,         "ar", ""   },
    { LANGUAGE_BASQUE,                      "eu", ""   },
    { LANGUAGE_BULGARIAN,                   "bg", "BG" },
    { LANGUAGE_CZECH,                       "cs", "CZ" },
    { LANGUAGE_CZECH,                       "cz", ""   },
    { LANGUAGE_ENGLISH_JAMAICA,             "en", "JM" },
    { LANGUAGE_ENGLISH_CARRIBEAN,           "en", "BS" },   // not 100%, because AG is Bahamas
    { LANGUAGE_ENGLISH_BELIZE,              "en", "BZ" },
    { LANGUAGE_ENGLISH_TRINIDAD,            "en", "TT" },
    { LANGUAGE_ENGLISH_ZIMBABWE,            "en", "ZW" },
    { LANGUAGE_ENGLISH_INDONESIA,           "en", "ID" },
    { LANGUAGE_ESTONIAN,                    "et", "EE" },
    { LANGUAGE_FAEROESE,                    "fo", "FO" },
    { LANGUAGE_FARSI,                       "fa", "IR" },
    { LANGUAGE_FRENCH_LUXEMBOURG,           "fr", "LU" },
    { LANGUAGE_FRENCH_MONACO,               "fr", "MC" },
    { LANGUAGE_GERMAN_LUXEMBOURG,           "de", "LU" },
    { LANGUAGE_GERMAN_LIECHTENSTEIN,        "de", "LI" },
    { LANGUAGE_HEBREW,                      "he", "IL" },   // new: old was "iw"
    { LANGUAGE_HEBREW,                      "iw", "IL" },   // old: new is "he"
    { LANGUAGE_HUNGARIAN,                   "hu", "HU" },
    { LANGUAGE_ICELANDIC,                   "is", "IS" },
    { LANGUAGE_INDONESIAN,                  "id", "ID" },   // new: old was "in"
    { LANGUAGE_INDONESIAN,                  "in", "ID" },   // old: new is "id"
    { LANGUAGE_NORWEGIAN,                   "no", "NO" },
    { LANGUAGE_NORWEGIAN_BOKMAL,            "nb", "NO" },
    { LANGUAGE_NORWEGIAN_NYNORSK,           "nn", "NO" },
    { LANGUAGE_POLISH,                      "pl", "PL" },
    { LANGUAGE_RHAETO_ROMAN,                "rm", "CH" },
    { LANGUAGE_ROMANIAN,                    "ro", "RO" },
    { LANGUAGE_ROMANIAN_MOLDOVA,            "ro", "MD" },
    { LANGUAGE_SLOVAK,                      "sk", "SK" },
    { LANGUAGE_SLOVENIAN,                   "sl", "SI" },
    { LANGUAGE_SPANISH_MEXICAN,             "es", "MX" },
    { LANGUAGE_SPANISH_GUATEMALA,           "es", "GT" },
    { LANGUAGE_SPANISH_COSTARICA,           "es", "CR" },
    { LANGUAGE_SPANISH_PANAMA,              "es", "PA" },
    { LANGUAGE_SPANISH_DOMINICAN_REPUBLIC,  "es", "DO" },
    { LANGUAGE_SPANISH_VENEZUELA,           "es", "VE" },
    { LANGUAGE_SPANISH_COLOMBIA,            "es", "CO" },
    { LANGUAGE_SPANISH_PERU,                "es", "PE" },
    { LANGUAGE_SPANISH_ARGENTINA,           "es", "AR" },
    { LANGUAGE_SPANISH_ECUADOR,             "es", "EC" },
    { LANGUAGE_SPANISH_CHILE,               "es", "CL" },
    { LANGUAGE_SPANISH_URUGUAY,             "es", "UY" },
    { LANGUAGE_SPANISH_PARAGUAY,            "es", "PY" },
    { LANGUAGE_SPANISH_BOLIVIA,             "es", "BO" },
    { LANGUAGE_SPANISH_EL_SALVADOR,         "es", "SV" },
    { LANGUAGE_SPANISH_HONDURAS,            "es", "HN" },
    { LANGUAGE_SPANISH_NICARAGUA,           "es", "NI" },
    { LANGUAGE_SPANISH_PUERTO_RICO,         "es", "PR" },
    { LANGUAGE_SPANISH_UNITED_STATES,       "es", "US" },
    { LANGUAGE_SPANISH_LATIN_AMERICA,       "es", ""   },
    { LANGUAGE_TURKISH,                     "tr", "TR" },
    { LANGUAGE_UKRAINIAN,                   "uk", "UA" },
    { LANGUAGE_VIETNAMESE,                  "vi", "VN" },
    { LANGUAGE_LATVIAN,                     "lv", "LV" },
    { LANGUAGE_MACEDONIAN,                  "mk", "MK" },
    { LANGUAGE_MALAY,                       "ms", ""   },
    { LANGUAGE_MALAY_MALAYSIA,              "ms", "MY" },
    { LANGUAGE_MALAY_BRUNEI_DARUSSALAM,     "ms", "BN" },
    { LANGUAGE_ENGLISH_MALAYSIA,            "en", "MY" },
    { LANGUAGE_THAI,                        "th", "TH" },
    { LANGUAGE_LITHUANIAN,                  "lt", "LT" },
    { LANGUAGE_LITHUANIAN_CLASSIC,          "lt", "LT" },
    { LANGUAGE_CROATIAN,                    "hr", "HR" },   // Croatian in Croatia
    { LANGUAGE_CROATIAN_BOSNIA_HERZEGOVINA, "hr", "BA" },
    { LANGUAGE_BOSNIAN_LATIN_BOSNIA_HERZEGOVINA,        "bs", "BA" },
//  { LANGUAGE_BOSNIAN_CYRILLIC_BOSNIA_AND_HERZEGOVINA, "bs", "BA" },   // script codes not supported yet
    { LANGUAGE_USER_SERBIAN_CYRILLIC_SERBIA,        "sr", "RS" },   // Serbian Cyrillic in Serbia
    { LANGUAGE_SERBIAN_CYRILLIC,                    "sr", "YU" },   // legacy Serbian Cyrillic in Serbia and Montenegro (former Yugoslavia); kludge, needed to be sr_CS instead, sr_CS not supported by ICU 2.6 (3.4 does)
    { LANGUAGE_SERBIAN_CYRILLIC,                    "sr", "CS" },   // alias to be able to integrate localizations, rsc needs it
    { LANGUAGE_USER_SERBIAN_CYRILLIC_MONTENEGRO,    "sr", "ME" },
    { LANGUAGE_SERBIAN_CYRILLIC_BOSNIA_HERZEGOVINA, "sr", "BA" },
    { LANGUAGE_SERBIAN,                             "sr", ""   },   // SERBIAN is only LID, MS-LCID not defined (was dupe of CROATIAN)
    { LANGUAGE_USER_SERBIAN_LATIN_SERBIA,           "sh", "RS" },   // Serbian Latin in Serbia; kludge, needed to be sr_Latn_RS instead, script codes not supported yet
    { LANGUAGE_SERBIAN_LATIN,                       "sh", "YU" },   // legacy Serbian Latin in Serbia and Montenegro (former Yugoslavia); kludge, needed to be sr_Latn_CS instead, script codes not supported yet
    { LANGUAGE_SERBIAN_LATIN,                       "sh", "CS" },   // Serbian Latin in Serbia and Montenegro; kludge, needed to be sr_Latn_CS instead, script codes not supported yet
    { LANGUAGE_USER_SERBIAN_LATIN_MONTENEGRO,       "sh", "ME" },   // Serbian Latin in Montenegro; kludge, needed to be sr_Latn_ME instead, script codes not supported yet
    { LANGUAGE_SERBIAN_LATIN_BOSNIA_HERZEGOVINA,    "sh", "BA" },
    { LANGUAGE_SERBIAN_LATIN_NEUTRAL,               "sh", ""   },   // kludge, needed to be sr_Latn instead, script codes not supported yet
    { LANGUAGE_ARMENIAN,                    "hy", "AM" },
    { LANGUAGE_AZERI,                       "az", ""   },
    { LANGUAGE_AZERI_LATIN,                 "az", "AZ" },
//  { LANGUAGE_AZERI_CYRILLIC,              "az", "AZ" },   // script codes not supported yet
    { LANGUAGE_UZBEK_LATIN,                 "uz", "UZ" },
//  { LANGUAGE_UZBEK_CYRILLIC,              "uz", "UZ" },   // script codes not supported yet
    { LANGUAGE_BENGALI_BANGLADESH,          "bn", "BD" },
    { LANGUAGE_BENGALI,                     "bn", "IN" },
    { LANGUAGE_BURMESE,                     "my", "MM" },
    { LANGUAGE_KAZAK,                       "kk", "KZ" },
    { LANGUAGE_ENGLISH_INDIA,               "en", "IN" },
    { LANGUAGE_URDU,                        "ur", ""   },
    { LANGUAGE_URDU_INDIA,                  "ur", "IN" },
    { LANGUAGE_URDU_PAKISTAN,               "ur", "PK" },
    { LANGUAGE_HINDI,                       "hi", "IN" },
    { LANGUAGE_GUJARATI,                    "gu", "IN" },
    { LANGUAGE_KANNADA,                     "kn", "IN" },
    { LANGUAGE_ASSAMESE,                    "as", "IN" },
    { LANGUAGE_KASHMIRI,                    "ks", ""   },
    { LANGUAGE_KASHMIRI_INDIA,              "ks", "IN" },
    { LANGUAGE_MALAYALAM,                   "ml", "IN" },
    { LANGUAGE_MANIPURI,                   "mni", "IN" },
    { LANGUAGE_MARATHI,                     "mr", "IN" },
    { LANGUAGE_KONKANI,                    "kok", "IN" },
    { LANGUAGE_NEPALI,                      "ne", "NP" },
    { LANGUAGE_NEPALI_INDIA,                "ne", "IN" },
    { LANGUAGE_ORIYA,                       "or", "IN" },
    { LANGUAGE_PUNJABI,                     "pa", "IN" },
    { LANGUAGE_SANSKRIT,                    "sa", "IN" },
    { LANGUAGE_SINDHI,                      "sd", "IN" },
    { LANGUAGE_TAMIL,                       "ta", "IN" },
    { LANGUAGE_TELUGU,                      "te", "IN" },
    { LANGUAGE_PUNJABI_PAKISTAN,           "lah", "PK" },   // preferring "lah" over "pa" for Western Punjabi, see http://www.ethnologue.com/show_language.asp?code=PNB
    { LANGUAGE_PUNJABI_PAKISTAN,            "pa", "PK" },
    { LANGUAGE_SINDHI_PAKISTAN,             "sd", "PK" },
    { LANGUAGE_BELARUSIAN,                  "be", "BY" },
    { LANGUAGE_CATALAN,                     "ca", "ES" },   // Spain (default)
    { LANGUAGE_CATALAN,                     "ca", "AD" },   // Andorra
    { LANGUAGE_USER_CATALAN_VALENCIAN,                     "ca", "XV" },   // XV: ISO 3166 user-assigned; workaround for UI localization only, do not use in document content!
    { LANGUAGE_CATALAN,                    "qcv", "ES" },   // qcv: ISO 639-3 reserved-for-local-use; UI localization quirk only, do not use in document content!
//    { LANGUAGE_USER_CATALAN_VALENCIAN,      "ca", "ES" },   // In case MS format files escaped into the wild, map them back.
    { LANGUAGE_FRENCH_CAMEROON,             "fr", "CM" },
    { LANGUAGE_FRENCH_COTE_D_IVOIRE,        "fr", "CI" },
    { LANGUAGE_FRENCH_MALI,                 "fr", "ML" },
    { LANGUAGE_FRENCH_SENEGAL,              "fr", "SN" },
    { LANGUAGE_FRENCH_ZAIRE,                "fr", "CD" },   // Democratic Republic Of Congo
    { LANGUAGE_FRENCH_MOROCCO,              "fr", "MA" },
    { LANGUAGE_FRENCH_REUNION,              "fr", "RE" },
    { LANGUAGE_FRENCH_NORTH_AFRICA,         "fr", ""   },
    { LANGUAGE_FRENCH_WEST_INDIES,          "fr", ""   },   // unknown ISO country code
    { LANGUAGE_FRISIAN_NETHERLANDS,         "fy", "NL" },
    { LANGUAGE_GAELIC_IRELAND,              "ga", "IE" },
    { LANGUAGE_GAELIC_SCOTLAND,             "gd", "GB" },
    { LANGUAGE_GALICIAN,                    "gl", "ES" },
    { LANGUAGE_GEORGIAN,                    "ka", "GE" },
    { LANGUAGE_KHMER,                       "km", "KH" },
    { LANGUAGE_KIRGHIZ,                     "ky", "KG" },
    { LANGUAGE_LAO,                         "lo", "LA" },
    { LANGUAGE_MALTESE,                     "mt", "MT" },
    { LANGUAGE_MONGOLIAN,                   "mn", "MN" },   // Cyrillic script
    { LANGUAGE_MONGOLIAN_MONGOLIAN,         "mn", "MN" },
    { LANGUAGE_RUSSIAN_MOLDOVA,             "mo", "MD" },
    { LANGUAGE_SWAHILI,                     "sw", "KE" },
    { LANGUAGE_USER_SWAHILI_TANZANIA,       "sw", "TZ" },
    { LANGUAGE_TAJIK,                       "tg", "TJ" },
    { LANGUAGE_TIBETAN,                     "bo", "CN" },   // CN politically correct?
    { LANGUAGE_DZONGKHA,                    "dz", "BT" },
    { LANGUAGE_TURKMEN,                     "tk", "TM" },
    { LANGUAGE_WELSH,                       "cy", "GB" },
    { LANGUAGE_SESOTHO,                     "st", "ZA" },
    { LANGUAGE_SEPEDI,                     "nso", "ZA" },
    { LANGUAGE_SEPEDI,                      "ns", "ZA" },   // fake "ns" for compatibility with existing OOo1.1.x localization to be able to read those documents
    { LANGUAGE_TSONGA,                      "ts", "ZA" },
    { LANGUAGE_TSWANA,                      "tn", "ZA" },
    { LANGUAGE_ENGLISH_SAFRICA,             "en", "ZA" },
    { LANGUAGE_AFRIKAANS,                   "af", "ZA" },
    { LANGUAGE_VENDA,                       "ve", "ZA" },   // default 639-1
    { LANGUAGE_VENDA,                      "ven", "ZA" },   // 639-2 may have been used temporarily since 2004-07-23
    { LANGUAGE_XHOSA,                       "xh", "ZA" },
    { LANGUAGE_ZULU,                        "zu", "ZA" },
    { LANGUAGE_QUECHUA_ECUADOR,             "qu", "EC" },
    { LANGUAGE_QUECHUA_PERU,                "qu", "PE" },
    { LANGUAGE_QUECHUA_BOLIVIA,             "qu", "BO" },   // macro: quh-BO, qul-BO
    { LANGUAGE_PASHTO,                      "ps", "AF" },
    { LANGUAGE_OROMO,                       "om", "ET" },
    { LANGUAGE_DHIVEHI,                     "dv", "MV" },
    { LANGUAGE_UIGHUR_CHINA,                "ug", "CN" },
    { LANGUAGE_TIGRIGNA_ETHIOPIA,           "ti", "ET" },
    { LANGUAGE_TIGRIGNA_ERITREA,            "ti", "ER" },
    { LANGUAGE_AMHARIC_ETHIOPIA,            "am", "ET" },
    { LANGUAGE_GUARANI_PARAGUAY,           "gug", "PY" },
    { LANGUAGE_HAWAIIAN_UNITED_STATES,     "haw", "US" },
    { LANGUAGE_EDO,                        "bin", "NG" },
    { LANGUAGE_FULFULDE_NIGERIA,            "ff", "NG" },
    { LANGUAGE_HAUSA_NIGERIA,               "ha", "NG" },
    { LANGUAGE_USER_HAUSA_GHANA,            "ha", "GH" },
    { LANGUAGE_IGBO_NIGERIA,                "ig", "NG" },
    { LANGUAGE_KANURI_NIGERIA,              "kr", "NG" },
    { LANGUAGE_YORUBA,                      "yo", "NG" },
    { LANGUAGE_SOMALI,                      "so", "SO" },
    { LANGUAGE_PAPIAMENTU,                 "pap", "AN" },
    { LANGUAGE_USER_PAPIAMENTU_ARUBA,      "pap", "AW" },
    { LANGUAGE_ENGLISH_SINGAPORE,           "en", "SG" },
    { LANGUAGE_USER_YIDDISH_US,             "yi", "US" },
    { LANGUAGE_YIDDISH,                     "yi", "IL" },   // new: old was "ji"
    { LANGUAGE_YIDDISH,                     "ji", "IL" },   // old: new is "yi"
    { LANGUAGE_SYRIAC,                     "syr", "TR" },   // "TR" according to http://www.ethnologue.com/show_language.asp?code=SYC
    { LANGUAGE_SINHALESE_SRI_LANKA,         "si", "LK" },
    { LANGUAGE_CHEROKEE_UNITED_STATES,     "chr", "US" },
    { LANGUAGE_INUKTITUT_LATIN_CANADA,      "iu", "CA" },
//  { LANGUAGE_INUKTITUT_SYLLABICS_CANADA,  "iu", "CA" },   // script codes not supported yet
    { LANGUAGE_SAMI_NORTHERN_NORWAY,        "se", "NO" },
    { LANGUAGE_SAMI_INARI,                 "smn", "FI" },
    { LANGUAGE_SAMI_LULE_NORWAY,           "smj", "NO" },
    { LANGUAGE_SAMI_LULE_SWEDEN,           "smj", "SE" },
    { LANGUAGE_SAMI_NORTHERN_FINLAND,       "se", "FI" },
    { LANGUAGE_SAMI_NORTHERN_SWEDEN,        "se", "SE" },
    { LANGUAGE_SAMI_SKOLT,                 "sms", "FI" },
    { LANGUAGE_SAMI_SOUTHERN_NORWAY,       "sma", "NO" },
    { LANGUAGE_SAMI_SOUTHERN_SWEDEN,       "sma", "SE" },
    { LANGUAGE_USER_SAMI_KILDIN_RUSSIA,    "sjd", "RU" },
    { LANGUAGE_MAPUDUNGUN_CHILE,           "arn", "CL" },
    { LANGUAGE_CORSICAN_FRANCE,             "co", "FR" },
    { LANGUAGE_ALSATIAN_FRANCE,            "gsw", "FR" },   // in fact 'gsw' is Schwyzerduetsch (Swiss German), which is a dialect of Alemannic German, as is Alsatian. They aren't distinct languages and share this code.
    { LANGUAGE_YAKUT_RUSSIA,               "sah", "RU" },
    { LANGUAGE_MOHAWK_CANADA,              "moh", "CA" },
    { LANGUAGE_BASHKIR_RUSSIA,              "ba", "RU" },
    { LANGUAGE_KICHE_GUATEMALA,            "qut", "GT" },
    { LANGUAGE_DARI_AFGHANISTAN,           "gbz", "AF" },
    { LANGUAGE_WOLOF_SENEGAL,               "wo", "SN" },
    { LANGUAGE_FILIPINO,                   "fil", "PH" },
    { LANGUAGE_USER_TAGALOG,                "tl", "PH" },
    { LANGUAGE_ENGLISH_PHILIPPINES,         "en", "PH" },
//  { LANGUAGE_IBIBIO_NIGERIA,             "nic", "NG" },   // ISO "nic" is only a collective language code
    { LANGUAGE_YI,                          "ii", "CN" },
    { LANGUAGE_TAMAZIGHT_LATIN,            "kab", "DZ" },   // In practice Kabyle is the language used for this
    { LANGUAGE_OBSOLETE_USER_KABYLE,       "kab", "DZ" },
    { LANGUAGE_TAMAZIGHT_LATIN,            "ber", "DZ" },   // In practice Algeria has standardized on Kabyle as the member of the "ber" collective which gets used there.
    { LANGUAGE_TAMAZIGHT_TIFINAGH,         "ber", "MA" },   // Morocco is officially using Tifinagh for its Berber languages so store it to distinguish explicitly from LANGUAGE_TAMAZIGHT_LATIN, even though as a collective language its not of much use
//  { LANGUAGE_TAMAZIGHT_ARABIC,           "ber", ""   },   // ISO "ber" only collective!
    { LANGUAGE_LATIN,                       "la", "VA" },
    { LANGUAGE_OBSOLETE_USER_LATIN,         "la", "VA" },
    { LANGUAGE_USER_ESPERANTO,              "eo", ""   },
    { LANGUAGE_USER_INTERLINGUA,            "ia", ""   },
    { LANGUAGE_MAORI_NEW_ZEALAND,           "mi", "NZ" },
    { LANGUAGE_OBSOLETE_USER_MAORI,         "mi", "NZ" },
    { LANGUAGE_KINYARWANDA_RWANDA,          "rw", "RW" },
    { LANGUAGE_OBSOLETE_USER_KINYARWANDA,   "rw", "RW" },
    { LANGUAGE_UPPER_SORBIAN_GERMANY,      "hsb", "DE" },   // MS maps this to 'wen-DE', which is nonsense. 'wen' is a collective language code, 'WEN' is a SIL code, see http://www.ethnologue.com/14/show_iso639.asp?code=wen and http://www.ethnologue.com/14/show_language.asp?code=WEN
    { LANGUAGE_OBSOLETE_USER_UPPER_SORBIAN,"hsb", "DE" },
    { LANGUAGE_LOWER_SORBIAN_GERMANY,      "dsb", "DE" },   // MS maps this to 'wee-DE', which is nonsense. 'WEE' is a SIL code, see http://www.ethnologue.com/14/show_language.asp?code=WEE
    { LANGUAGE_OBSOLETE_USER_LOWER_SORBIAN,"dsb", "DE" },
    { LANGUAGE_OCCITAN_FRANCE,              "oc", "FR" },
    { LANGUAGE_OBSOLETE_USER_OCCITAN,       "oc", "FR" },
    { LANGUAGE_USER_KURDISH_TURKEY,         "ku", "TR" },
    { LANGUAGE_USER_KURDISH_SYRIA,          "ku", "SY" },
    { LANGUAGE_USER_KURDISH_IRAQ,           "ku", "IQ" },
    { LANGUAGE_USER_KURDISH_IRAN,           "ku", "IR" },
    { LANGUAGE_USER_SARDINIAN,              "sc", "IT" },   // macrolanguage code
    { LANGUAGE_USER_SARDINIAN_CAMPIDANESE, "sro", "IT" },
    { LANGUAGE_USER_SARDINIAN_GALLURESE,   "sdn", "IT" },
    { LANGUAGE_USER_SARDINIAN_LOGUDORESE,  "src", "IT" },
    { LANGUAGE_USER_SARDINIAN_SASSARESE,   "sdc", "IT" },
    { LANGUAGE_BRETON_FRANCE,               "br", "FR" },
    { LANGUAGE_OBSOLETE_USER_BRETON,        "br", "FR" },
    { LANGUAGE_KALAALLISUT_GREENLAND,       "kl", "GL" },
    { LANGUAGE_OBSOLETE_USER_KALAALLISUT,   "kl", "GL" },
    { LANGUAGE_USER_SWAZI,                  "ss", "ZA" },
    { LANGUAGE_USER_NDEBELE_SOUTH,          "nr", "ZA" },
    { LANGUAGE_USER_TSWANA_BOTSWANA,        "tn", "BW" },
    { LANGUAGE_USER_MOORE,                 "mos", "BF" },
    { LANGUAGE_USER_BAMBARA,                "bm", "ML" },
    { LANGUAGE_USER_AKAN,                   "ak", "GH" },
    { LANGUAGE_LUXEMBOURGISH_LUXEMBOURG,    "lb", "LU" },
    { LANGUAGE_OBSOLETE_USER_LUXEMBOURGISH, "lb", "LU" },
    { LANGUAGE_USER_FRIULIAN,              "fur", "IT" },
    { LANGUAGE_USER_FIJIAN,                 "fj", "FJ" },
    { LANGUAGE_USER_AFRIKAANS_NAMIBIA,      "af", "NA" },
    { LANGUAGE_USER_ENGLISH_NAMIBIA,        "en", "NA" },
    { LANGUAGE_USER_WALLOON,                "wa", "BE" },
    { LANGUAGE_USER_COPTIC,                "cop", "EG" },
    { LANGUAGE_USER_GASCON,                "gsc", "FR" },
    { LANGUAGE_USER_GERMAN_BELGIUM,         "de", "BE" },
    { LANGUAGE_USER_CHUVASH,                "cv", "RU" },
    { LANGUAGE_USER_EWE_GHANA,              "ee", "GH" },
    { LANGUAGE_USER_ENGLISH_GHANA,          "en", "GH" },
    { LANGUAGE_USER_SANGO,                  "sg", "CF" },
    { LANGUAGE_USER_GANDA,                  "lg", "UG" },
    { LANGUAGE_USER_LINGALA_DRCONGO,        "ln", "CD" },
    { LANGUAGE_USER_LOW_GERMAN,            "nds", "DE" },
    { LANGUAGE_USER_HILIGAYNON,            "hil", "PH" },
    { LANGUAGE_USER_ENGLISH_MALAWI,         "en", "MW" },   /* en default for MW */
    { LANGUAGE_USER_NYANJA,                 "ny", "MW" },
    { LANGUAGE_USER_KASHUBIAN,             "csb", "PL" },
    { LANGUAGE_USER_SPANISH_CUBA,           "es", "CU" },
    { LANGUAGE_USER_QUECHUA_NORTH_BOLIVIA, "qul", "BO" },
    { LANGUAGE_USER_QUECHUA_SOUTH_BOLIVIA, "quh", "BO" },
    { LANGUAGE_USER_BODO_INDIA,            "brx", "IN" },
    { LANGUAGE_USER_DOGRI_INDIA,           "dgo", "IN" },
    { LANGUAGE_USER_MAITHILI_INDIA,        "mai", "IN" },
    { LANGUAGE_USER_SANTALI_INDIA,         "sat", "IN" },
    { LANGUAGE_USER_TETUN,                 "tet", "ID" },
    { LANGUAGE_USER_TETUN_TIMOR_LESTE,     "tet", "TL" },
    { LANGUAGE_USER_TOK_PISIN,             "tpi", "PG" },
    { LANGUAGE_USER_SHUSWAP,               "shs", "CA" },
    { LANGUAGE_USER_ANCIENT_GREEK,         "grc", "GR" },
    { LANGUAGE_USER_ASTURIAN,              "ast", "ES" },
    { LANGUAGE_USER_LATGALIAN,             "ltg", "LV" },
    { LANGUAGE_USER_MAORE,                 "swb", "YT" },
    { LANGUAGE_USER_BUSHI,                 "buc", "YT" },
    { LANGUAGE_USER_TAHITIAN,               "ty", "PF" },
    { LANGUAGE_USER_MALAGASY_PLATEAU,      "plt", "MG" },
    { LANGUAGE_USER_MALAGASY_PLATEAU,       "mg", "MG" },
    { LANGUAGE_USER_BAFIA,                 "ksf", "CM" },
    { LANGUAGE_USER_GIKUYU,                 "ki", "KE" },
    { LANGUAGE_USER_RUSYN_UKRAINE,         "rue", "UA" },
    { LANGUAGE_USER_RUSYN_SLOVAKIA,        "rue", "SK" },
    { LANGUAGE_USER_LIMBU,                 "lif", "NP" },
    { LANGUAGE_USER_LOJBAN,                "jbo", ""   },
    { LANGUAGE_USER_HAITIAN,                "ht", "HT" },
    { LANGUAGE_FRENCH_HAITI,                "fr", "HT" },
    { LANGUAGE_USER_BEEMBE,                "beq", "CG" },
    { LANGUAGE_USER_BEKWEL,                "bkw", "CG" },
    { LANGUAGE_USER_KITUBA,                "mkw", "CG" },
    { LANGUAGE_USER_LARI,                  "ldi", "CG" },
    { LANGUAGE_USER_MBOCHI,                "mdw", "CG" },
    { LANGUAGE_USER_TEKE_EBOO,             "ebo", "CG" },
    { LANGUAGE_USER_TEKE_IBALI,            "tek", "CG" },
    { LANGUAGE_USER_TEKE_TYEE,             "tyx", "CG" },
    { LANGUAGE_USER_VILI,                  "vif", "CG" },
    { LANGUAGE_USER_PORTUGUESE_ANGOLA,      "pt", "AO" },
    { LANGUAGE_USER_MANX,                   "gv", "GB" },
    { LANGUAGE_USER_ARAGONESE,              "an", "ES" },
    { LANGUAGE_USER_KEYID,                 "qtz", ""   },   // key id pseudolanguage used for UI testing
    { LANGUAGE_USER_PALI_LATIN,            "pli", ""   },   // Pali with Latin script
    { LANGUAGE_USER_KYRGYZ_CHINA,           "ky", "CN" },
    { LANGUAGE_USER_KOMI_ZYRIAN,           "kpv", "RU" },
    { LANGUAGE_USER_KOMI_PERMYAK,          "koi", "RU" },
    { LANGUAGE_USER_PITJANTJATJARA,        "pjt", "AU" },
    { LANGUAGE_USER_ERYZA,                 "myv", "RU" },
    { LANGUAGE_USER_MARI_MEADOW,           "mhr", "RU" },
    { LANGUAGE_NONE,                       "zxx", ""   },   // added to ISO 639-2 on 2006-01-11: Used to declare the absence of linguistic information
    { LANGUAGE_DONTKNOW,                    "",   ""   }    // marks end of table
};

static MsLangId::IsoLangEntry aLastResortFallbackEntry =
{ LANGUAGE_ENGLISH_US, "en", "US" };

// -----------------------------------------------------------------------

// In this table are the countries which should mapped to a specific
// english language
static IsoLangEngEntry const aImplIsoLangEngEntries[] =
{
    { LANGUAGE_ENGLISH_UK,                  "AO" },         // Angola
    { LANGUAGE_ENGLISH_UK,                  "BJ" },         // Benin
    { LANGUAGE_ENGLISH_UK,                  "BW" },         // Botswana
    { LANGUAGE_ENGLISH_UK,                  "BI" },         // Burundi
    { LANGUAGE_ENGLISH_UK,                  "CM" },         // Cameroon
    { LANGUAGE_ENGLISH_UK,                  "GA" },         // Gabon
    { LANGUAGE_ENGLISH_UK,                  "GM" },         // Gambia
    { LANGUAGE_ENGLISH_UK,                  "GH" },         // Ghana
    { LANGUAGE_ENGLISH_UK,                  "GN" },         // Guinea
    { LANGUAGE_ENGLISH_UK,                  "LS" },         // Lesotho
    { LANGUAGE_ENGLISH_UK,                  "MW" },         // Malawi
    { LANGUAGE_ENGLISH_UK,                  "MT" },         // Malta
    { LANGUAGE_ENGLISH_UK,                  "NA" },         // Namibia
    { LANGUAGE_ENGLISH_UK,                  "NG" },         // Nigeria
    { LANGUAGE_ENGLISH_UK,                  "UG" },         // Uganda
    { LANGUAGE_ENGLISH_UK,                  "ZM" },         // Zambia
    { LANGUAGE_ENGLISH_UK,                  "ZW" },         // Zimbabwe
    { LANGUAGE_ENGLISH_UK,                  "SZ" },         // Swaziland
    { LANGUAGE_ENGLISH_UK,                  "NG" },         // Sierra Leone
    { LANGUAGE_ENGLISH_UK,                  "KN" },         // Saint Kitts and Nevis
    { LANGUAGE_ENGLISH_UK,                  "SH" },         // St. Helena
    { LANGUAGE_ENGLISH_UK,                  "IO" },         // British Indian Oceanic Territory
    { LANGUAGE_ENGLISH_UK,                  "FK" },         // Falkland Islands
    { LANGUAGE_ENGLISH_UK,                  "GI" },         // Gibraltar
    { LANGUAGE_ENGLISH_UK,                  "KI" },         // Kiribati
    { LANGUAGE_ENGLISH_UK,                  "VG" },         // Virgin Islands
    { LANGUAGE_ENGLISH_UK,                  "MU" },         // Mauritius
    { LANGUAGE_ENGLISH_UK,                  "FJ" },         // Fiji
    { LANGUAGE_ENGLISH_US,                  "KI" },         // Kiribati
    { LANGUAGE_ENGLISH_US,                  "LR" },         // Liberia
    { LANGUAGE_ENGLISH_US,                  "GU" },         // Guam
    { LANGUAGE_ENGLISH_US,                  "MH" },         // Marshall Islands
    { LANGUAGE_ENGLISH_US,                  "PW" },         // Palau
    { LANGUAGE_ENGLISH_CARRIBEAN,           "AI" },         // Anguilla
    { LANGUAGE_ENGLISH_CARRIBEAN,           "AG" },         // Antigua and Barbuda
    { LANGUAGE_ENGLISH_CARRIBEAN,           "BS" },         // Bahamas
    { LANGUAGE_ENGLISH_CARRIBEAN,           "BB" },         // Barbedos
    { LANGUAGE_ENGLISH_CARRIBEAN,           "BM" },         // Bermuda
    { LANGUAGE_ENGLISH_CARRIBEAN,           "KY" },         // Cayman Islands
    { LANGUAGE_ENGLISH_CARRIBEAN,           "GD" },         // Grenada
    { LANGUAGE_ENGLISH_CARRIBEAN,           "DM" },         // Dominica
    { LANGUAGE_ENGLISH_CARRIBEAN,           "HT" },         // Haiti
    { LANGUAGE_ENGLISH_CARRIBEAN,           "MS" },         // Montserrat
    { LANGUAGE_ENGLISH_CARRIBEAN,           "FM" },         // Micronesia
    { LANGUAGE_ENGLISH_CARRIBEAN,           "VC" },         // St. Vincent / Grenadines
    { LANGUAGE_ENGLISH_CARRIBEAN,           "LC" },         // Saint Lucia
    { LANGUAGE_ENGLISH_CARRIBEAN,           "TC" },         // Turks & Caicos Islands
    { LANGUAGE_ENGLISH_CARRIBEAN,           "GY" },         // Guyana
    { LANGUAGE_ENGLISH_CARRIBEAN,           "TT" },         // Trinidad and Tobago
    { LANGUAGE_ENGLISH_AUS,                 "CX" },         // Christmas Islands
    { LANGUAGE_ENGLISH_AUS,                 "CC" },         // Cocos (Keeling) Islands
    { LANGUAGE_ENGLISH_AUS,                 "NF" },         // Norfolk Island
    { LANGUAGE_ENGLISH_AUS,                 "PG" },         // Papua New Guinea
    { LANGUAGE_ENGLISH_AUS,                 "SB" },         // Solomon Islands
    { LANGUAGE_ENGLISH_AUS,                 "TV" },         // Tuvalu
    { LANGUAGE_ENGLISH_AUS,                 "NR" },         // Nauru
    { LANGUAGE_ENGLISH_NZ,                  "CK" },         // Cook Islands
    { LANGUAGE_ENGLISH_NZ,                  "NU" },         // Niue
    { LANGUAGE_ENGLISH_NZ,                  "TK" },         // Tokelau
    { LANGUAGE_ENGLISH_NZ,                  "TO" },         // Tonga
    { LANGUAGE_DONTKNOW,                    ""   }          // marks end of table
};

// -----------------------------------------------------------------------

static IsoLangNoneStdEntry const aImplIsoNoneStdLangEntries[] =
{
    { LANGUAGE_NORWEGIAN_BOKMAL,            "no", "BOK"      }, // registered subtags for "no" in rfc1766
    { LANGUAGE_NORWEGIAN_NYNORSK,           "no", "NYN"      }, // registered subtags for "no" in rfc1766
    { LANGUAGE_SERBIAN_LATIN,               "sr", "latin"    },
    { LANGUAGE_SERBIAN_CYRILLIC,            "sr", "cyrillic" },
    { LANGUAGE_AZERI_LATIN,                 "az", "latin"    },
    { LANGUAGE_AZERI_CYRILLIC,              "az", "cyrillic" },
    { LANGUAGE_DONTKNOW,                    "",   ""         }  // marks end of table
};

// -----------------------------------------------------------------------

// in this table are only names to find the best language
static IsoLangNoneStdEntry const aImplIsoNoneStdLangEntries2[] =
{
    { LANGUAGE_NORWEGIAN_BOKMAL,            "no", "bokmaal"  },
    { LANGUAGE_NORWEGIAN_BOKMAL,            "no", "bokmal"   },
    { LANGUAGE_NORWEGIAN_NYNORSK,           "no", "nynorsk"  },
    { LANGUAGE_DONTKNOW,                    "",   ""         }  // marks end of table
};

// -----------------------------------------------------------------------

// in this table are only names to find the best language
static IsoLangOtherEntry const aImplOtherEntries[] =
{
    { LANGUAGE_ENGLISH_US,                  "c"              },
    { LANGUAGE_CHINESE,                     "chinese"        },
    { LANGUAGE_GERMAN,                      "german"         },
    { LANGUAGE_JAPANESE,                    "japanese"       },
    { LANGUAGE_KOREAN,                      "korean"         },
    { LANGUAGE_ENGLISH_US,                  "posix"          },
    { LANGUAGE_CHINESE_TRADITIONAL,         "tchinese"       },
    { LANGUAGE_DONTKNOW,                    NULL             }  // marks end of table
};

// =======================================================================

// static
void MsLangId::convertLanguageToIsoNames( LanguageType nLang,
        rtl::OUString& rLangStr, rtl::OUString& rCountry )
{
    if ( nLang == LANGUAGE_SYSTEM )
        nLang = MsLangId::getSystemLanguage();

    // Search for LangID (in this table we find only defined ISO combinations)
    const IsoLangEntry* pEntry = aImplIsoLangEntries;
    do
    {
        if ( pEntry->mnLang == nLang )
        {
            rLangStr = rtl::OUString::createFromAscii( pEntry->maLangStr );
            rCountry = rtl::OUString::createFromAscii( pEntry->maCountry );
            return;
        }
        ++pEntry;
    }
    while ( pEntry->mnLang != LANGUAGE_DONTKNOW );

    // Search for LangID if we didn't find a specific ISO combination.
    // All entries in this table are allowed for mime specifications,
    // but not defined ISO combinations.
    const IsoLangNoneStdEntry* pNoneStdEntry = aImplIsoNoneStdLangEntries;
    do
    {
        if ( pNoneStdEntry->mnLang == nLang )
        {
            rLangStr = rtl::OUString::createFromAscii( pNoneStdEntry->maLangStr );
            rCountry = rtl::OUString::createFromAscii( pNoneStdEntry->maCountry );
            return;
        }
        ++pNoneStdEntry;
    }
    while ( pNoneStdEntry->mnLang != LANGUAGE_DONTKNOW );

    // not found
    rLangStr = rtl::OUString();
    rCountry = rtl::OUString();
}

// -----------------------------------------------------------------------

// static
void MsLangId::convertLanguageToIsoNames( LanguageType nLang,
        rtl::OString& rLangStr, rtl::OString& rCountry )
{
    if ( nLang == LANGUAGE_SYSTEM )
        nLang = MsLangId::getSystemLanguage();

    // Search for LangID (in this table we find only defined ISO combinations)
    const IsoLangEntry* pEntry = aImplIsoLangEntries;
    do
    {
        if ( pEntry->mnLang == nLang )
        {                          // avoid embedded \0 warning
            rLangStr = rtl::OString( static_cast< const char* >( pEntry->maLangStr ));
            rCountry = rtl::OString( static_cast< const char* >( pEntry->maCountry ));
            return;
        }
        ++pEntry;
    }
    while ( pEntry->mnLang != LANGUAGE_DONTKNOW );

    // Search for LangID if we didn't find a specific ISO combination.
    // All entries in this table are allowed for mime specifications,
    // but not defined ISO combinations.
    const IsoLangNoneStdEntry* pNoneStdEntry = aImplIsoNoneStdLangEntries;
    do
    {
        if ( pNoneStdEntry->mnLang == nLang )
        {                          // avoid embedded \0 warning
            rLangStr = rtl::OString( static_cast< const char* >( pNoneStdEntry->maLangStr ));
            rCountry = rtl::OString( static_cast< const char* >( pNoneStdEntry->maCountry ));
            return;
        }
        ++pNoneStdEntry;
    }
    while ( pNoneStdEntry->mnLang != LANGUAGE_DONTKNOW );

    // not found
    rLangStr = rtl::OString();
    rCountry = rtl::OString();
}

// -----------------------------------------------------------------------

static const MsLangId::IsoLangEntry & lcl_lookupFallbackEntry( LanguageType nLang )
{
    LanguageType nPrimary = MsLangId::getPrimaryLanguage( nLang);

    // Search for LangID and remember first lang-only.
    const MsLangId::IsoLangEntry* pFirstPrimary = NULL;
    const MsLangId::IsoLangEntry* pEntry = aImplIsoLangEntries;
    do
    {
        if (pEntry->mnLang == nLang)
        {
            if (*pEntry->maCountry)
                return *pEntry;
            switch (nLang)
            {
                // These are known to have no country assigned.
                case LANGUAGE_BASQUE:
                case LANGUAGE_USER_ESPERANTO:
                case LANGUAGE_USER_INTERLINGUA:
                case LANGUAGE_USER_LOJBAN:
                    return *pEntry;
                default:
                    ;   // nothing
            }
        }
        if (!pFirstPrimary &&
                MsLangId::getPrimaryLanguage( pEntry->mnLang) == nPrimary)
            pFirstPrimary = pEntry;
        ++pEntry;
    }
    while ( pEntry->mnLang != LANGUAGE_DONTKNOW );

    // Language not found at all => use default.
    if (!pFirstPrimary)
        return aLastResortFallbackEntry;

    // Search for first entry of primary language with any country.
    pEntry = pFirstPrimary;
    do
    {
        if (MsLangId::getPrimaryLanguage( pEntry->mnLang) == nLang)
        {
            if (*pEntry->maCountry)
                return *pEntry;
        }
        ++pEntry;
    }
    while ( pEntry->mnLang != LANGUAGE_DONTKNOW );

    return aLastResortFallbackEntry;
}

// static
LanguageType MsLangId::lookupFallbackLanguage( LanguageType nLang )
{
    return lcl_lookupFallbackEntry( nLang).mnLang;
}


// static
::com::sun::star::lang::Locale MsLangId::lookupFallbackLocale( LanguageType nLang )
{
    const MsLangId::IsoLangEntry& rEntry = lcl_lookupFallbackEntry( nLang);
    return ::com::sun::star::lang::Locale(
            rtl::OUString::createFromAscii( rEntry.maLangStr),
            rtl::OUString::createFromAscii( rEntry.maCountry),
            rtl::OUString());
}

// -----------------------------------------------------------------------

static const MsLangId::IsoLangEntry & lcl_lookupFallbackEntry(
        const ::com::sun::star::lang::Locale & rLocale )
{
    // language is lower case in table
    rtl::OUString aLowerLang = rLocale.Language.toAsciiLowerCase();
    // country is upper case in table
    rtl::OUString aUpperCountry = rLocale.Country.toAsciiUpperCase();
    sal_Int32 nCountryLen = aUpperCountry.getLength();

    // Search for locale and remember first lang-only.
    const MsLangId::IsoLangEntry* pFirstLang = NULL;
    const MsLangId::IsoLangEntry* pEntry = aImplIsoLangEntries;
    do
    {
        if (aLowerLang.equalsAscii( pEntry->maLangStr))
        {
            if (*pEntry->maCountry)
            {
                if (nCountryLen && aUpperCountry.equalsAscii( pEntry->maCountry))
                    return *pEntry;
            }
            else
            {
                switch (pEntry->mnLang)
                {
                    // These are known to have no country assigned.
                    case LANGUAGE_BASQUE:
                    case LANGUAGE_USER_ESPERANTO:
                    case LANGUAGE_USER_INTERLINGUA:
                    case LANGUAGE_USER_LOJBAN:
                        return *pEntry;
                    default:
                        ;   // nothing
                }
            }
            if (!pFirstLang)
                pFirstLang = pEntry;
        }
        ++pEntry;
    }
    while ( pEntry->mnLang != LANGUAGE_DONTKNOW );

    // Language not found at all => use default.
    if (!pFirstLang)
        return aLastResortFallbackEntry;

    // Search for first entry of language with any country.
    pEntry = pFirstLang;
    do
    {
        if (aLowerLang.equalsAscii( pEntry->maLangStr))
        {
            if (*pEntry->maCountry)
                return *pEntry;
        }
        ++pEntry;
    }
    while ( pEntry->mnLang != LANGUAGE_DONTKNOW );

    return aLastResortFallbackEntry;
}

// static
LanguageType MsLangId::lookupFallbackLanguage(
        const ::com::sun::star::lang::Locale & rLocale )
{
    return lcl_lookupFallbackEntry( rLocale).mnLang;
}


// static
::com::sun::star::lang::Locale MsLangId::lookupFallbackLocale(
        const ::com::sun::star::lang::Locale & rLocale )
{
    const MsLangId::IsoLangEntry& rEntry = lcl_lookupFallbackEntry( rLocale);
    return ::com::sun::star::lang::Locale(
            rtl::OUString::createFromAscii( rEntry.maLangStr),
            rtl::OUString::createFromAscii( rEntry.maCountry),
            rtl::OUString());
}

// -----------------------------------------------------------------------

// static
rtl::OUString MsLangId::convertLanguageToIsoString( LanguageType nLang,
        sal_Unicode cSep )
{
    rtl::OUString   aLangStr;
    rtl::OUString   aCountry;
    convertLanguageToIsoNames( nLang, aLangStr, aCountry );
    if ( !aCountry.isEmpty() )
    {
        rtl::OUStringBuffer aBuf( aLangStr);
        aBuf.append( cSep );
        aBuf.append( aCountry );
        return aBuf.makeStringAndClear();
    }
    else
        return aLangStr;
}

// -----------------------------------------------------------------------

// static
rtl::OString MsLangId::convertLanguageToIsoByteString( LanguageType nLang,
        sal_Char cSep )
{
    rtl::OString  aLangStr;
    rtl::OString  aCountry;
    convertLanguageToIsoNames( nLang, aLangStr, aCountry );
    if ( !aCountry.isEmpty() )
    {
        rtl::OStringBuffer aBuf( aLangStr);
        aBuf.append( cSep );
        aBuf.append( aCountry );
        return aBuf.makeStringAndClear();
    }
    return aLangStr;
}

// =======================================================================

// static
LanguageType MsLangId::convertIsoNamesToLanguage( const rtl::OUString& rLang,
        const rtl::OUString& rCountry )
{
    // language is lower case in table
    rtl::OUString aLowerLang = rLang.toAsciiLowerCase();
    // country is upper case in table
    rtl::OUString aUpperCountry = rCountry.toAsciiUpperCase();

    //  first look for exact match
    const IsoLangEntry* pFirstLang = NULL;
    const IsoLangEntry* pEntry = aImplIsoLangEntries;
    do
    {
        if ( aLowerLang.equalsAscii( pEntry->maLangStr ) )
        {
            if ( aUpperCountry.isEmpty() ||
                 aUpperCountry.equalsAscii( pEntry->maCountry ) )
                return pEntry->mnLang;
            if ( !pFirstLang )
                pFirstLang = pEntry;
            else if ( !*pEntry->maCountry )
                pFirstLang = pEntry;
        }
        ++pEntry;
    }
    while ( pEntry->mnLang != LANGUAGE_DONTKNOW );

    // some eng countries should be mapped to a specific english language
    if ( aLowerLang == "en" )
    {
        const IsoLangEngEntry* pEngEntry = aImplIsoLangEngEntries;
        do
        {
            if ( aUpperCountry.equalsAscii( pEngEntry->maCountry ) )
                return pEngEntry->mnLang;
            ++pEngEntry;
        }
        while ( pEngEntry->mnLang != LANGUAGE_DONTKNOW );
    }

    // test for specific languages which are not used standard ISO 3166 codes
    const IsoLangNoneStdEntry* pNoneStdEntry = aImplIsoNoneStdLangEntries;
    do
    {
        if ( aLowerLang.equalsAscii( pNoneStdEntry->maLangStr ) )
        {
            // The countries in this table are not all in upper case
            if ( aUpperCountry.equalsIgnoreAsciiCaseAscii( pNoneStdEntry->maCountry ) )
                return pNoneStdEntry->mnLang;
        }
        ++pNoneStdEntry;
    }
    while ( pNoneStdEntry->mnLang != LANGUAGE_DONTKNOW );
    pNoneStdEntry = aImplIsoNoneStdLangEntries2;
    do
    {
        if ( aLowerLang.equalsAscii( pNoneStdEntry->maLangStr ) )
        {
            // The countries in this table are not all in upper case
            if ( aUpperCountry.equalsIgnoreAsciiCaseAscii( pNoneStdEntry->maCountry ) )
                return pNoneStdEntry->mnLang;
        }
        ++pNoneStdEntry;
    }
    while ( pNoneStdEntry->mnLang != LANGUAGE_DONTKNOW );

    // If the language is correct, than we return the default language
    if ( pFirstLang )
        return pFirstLang->mnLang;

    //  if only the country is set, look for any entry matching the country
    //  (to allow reading country and language in separate steps, in any order)
    if ( !rCountry.isEmpty() && rLang.isEmpty() )
    {
        const IsoLangEntry* pEntry2 = aImplIsoLangEntries;
        do
        {
            if ( aUpperCountry.equalsAscii( pEntry2->maCountry ) )
                return pEntry2->mnLang;
            ++pEntry2;
        }
        while ( pEntry2->mnLang != LANGUAGE_DONTKNOW );

        aLowerLang = aUpperCountry.toAsciiLowerCase();
    }

    // Now look for all other definitions, which are not standard
    const IsoLangOtherEntry* pOtherEntry = aImplOtherEntries;
    do
    {
        if ( aLowerLang.equalsAscii( pOtherEntry->mpLangStr ) )
            return pOtherEntry->mnLang;
        ++pOtherEntry;
    }
    while ( pOtherEntry->mnLang != LANGUAGE_DONTKNOW );

    return LANGUAGE_DONTKNOW;
}

// -----------------------------------------------------------------------

// static
LanguageType MsLangId::convertIsoNamesToLanguage( const rtl::OString& rLang,
        const rtl::OString& rCountry )
{
    rtl::OUString aLang = OStringToOUString( rLang, RTL_TEXTENCODING_ASCII_US);
    rtl::OUString aCountry = OStringToOUString( rCountry, RTL_TEXTENCODING_ASCII_US);
    return convertIsoNamesToLanguage( aLang, aCountry);
}

// -----------------------------------------------------------------------

// static
LanguageType MsLangId::convertIsoStringToLanguage(
        const rtl::OUString& rString, sal_Unicode cSep )
{
    rtl::OUString   aLang;
    rtl::OUString   aCountry;
    sal_Int32  nSepPos = rString.indexOf( cSep );
    if ( nSepPos >= 0 )
    {
        aLang = rString.copy( 0, nSepPos );
        aCountry = rString.copy( nSepPos+1 );
    }
    else
        aLang = rString;

    return convertIsoNamesToLanguage( aLang, aCountry );
}

// -----------------------------------------------------------------------

struct IsoLangGLIBCModifiersEntry
{
    LanguageType  mnLang;
    sal_Char      maLangStr[4];
    sal_Char      maCountry[3];
    sal_Char      maAtString[9];
};

static IsoLangGLIBCModifiersEntry const aImplIsoLangGLIBCModifiersEntries[] =
{
    // MS-LANGID codes               ISO639-1/2/3 ISO3166            glibc modifier
    { LANGUAGE_BOSNIAN_CYRILLIC_BOSNIA_HERZEGOVINA, "bs", "BA", "cyrillic" },
    { LANGUAGE_USER_SERBIAN_LATIN_SERBIA,           "sr", "RS", "latin" },   // Serbian Latin in Serbia
    { LANGUAGE_SERBIAN_LATIN,                       "sr", "CS", "latin" },   // Serbian Latin in Serbia and Montenegro
    { LANGUAGE_USER_SERBIAN_LATIN_MONTENEGRO,       "sr", "ME", "latin" },   // Serbian Latin in Montenegro
    { LANGUAGE_SERBIAN_LATIN_NEUTRAL,               "sr", "",   "latin" },
    { LANGUAGE_AZERI_CYRILLIC,                      "az", "AZ", "cyrillic" },
    { LANGUAGE_UZBEK_CYRILLIC,                      "uz", "UZ", "cyrillic" },
    { LANGUAGE_DONTKNOW,                            "",   "",   ""   }       // marks end of table
};

// convert a unix locale string into LanguageType

// static
LanguageType MsLangId::convertUnxByteStringToLanguage(
        const rtl::OString& rString )
{
    rtl::OString  aLang;
    rtl::OString  aCountry;
    rtl::OString  aAtString;

    sal_Int32  nLangSepPos    = rString.indexOf( (sal_Char)'_' );
    sal_Int32  nCountrySepPos = rString.indexOf( (sal_Char)'.' );
    sal_Int32  nAtPos         = rString.indexOf( (sal_Char)'@' );

    if (nCountrySepPos < 0)
        nCountrySepPos = nAtPos;
    if (nCountrySepPos < 0)
        nCountrySepPos = rString.getLength();

    if (nAtPos >= 0)
        aAtString = rString.copy( nAtPos+1 );

    if (   ((nLangSepPos >= 0) && (nLangSepPos > nCountrySepPos))
        || ((nLangSepPos < 0)) )
    {
        // eg. "el.sun_eu_greek", "tchinese", "es.ISO8859-15"
        aLang    = rString.copy( 0, nCountrySepPos );
    }
    else if ( nLangSepPos >= 0 )
    {
        // well formed iso names like "en_US.UTF-8", "sh_BA.ISO8859-2@bosnia"
        aLang    = rString.copy( 0, nLangSepPos );
        aCountry = rString.copy( nLangSepPos+1, nCountrySepPos - nLangSepPos - 1);
    }

    //  if there is a glibc modifier, first look for exact match in modifier table
    if (!aAtString.isEmpty())
    {
        // language is lower case in table
        rtl::OString aLowerLang = aLang.toAsciiLowerCase();
        // country is upper case in table
        rtl::OString aUpperCountry = aCountry.toAsciiUpperCase();
        const IsoLangGLIBCModifiersEntry* pGLIBCModifiersEntry = aImplIsoLangGLIBCModifiersEntries;
        do
        {                         // avoid embedded \0 warning
            if (( aLowerLang.equals( static_cast< const char* >( pGLIBCModifiersEntry->maLangStr ))) &&
               ( aAtString.equals( static_cast< const char* >( pGLIBCModifiersEntry->maAtString ))))
            {
                if ( aUpperCountry.isEmpty() ||
                     aUpperCountry.equals( static_cast< const char* >( pGLIBCModifiersEntry->maCountry )))
               {
                    return pGLIBCModifiersEntry->mnLang;
               }
            }
            ++pGLIBCModifiersEntry;
        }
        while ( pGLIBCModifiersEntry->mnLang != LANGUAGE_DONTKNOW );
    }

    return convertIsoNamesToLanguage( aLang, aCountry );
}

// -----------------------------------------------------------------------
// pass one IsoLangEntry to the outer world of the resource compiler

// static
const MsLangId::IsoLangEntry* MsLangId::getIsoLangEntry( size_t nIndex )
{
    if (nIndex < SAL_N_ELEMENTS(aImplIsoLangEntries))
        return &aImplIsoLangEntries[ nIndex];
    return 0;
}

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */