language.c 22.3 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14
/* GIMP - The GNU Image Manipulation Program
 * Copyright (C) 1995 Spencer Kimball and Peter Mattis
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program 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 General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
15
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
16 17 18 19 20 21 22 23 24
 */

/* Win32 language lookup table:
 * Copyright (C) 2007-2008 Dieter Verfaillie <dieterv@optionexplicit.be>
 */

#include "config.h"

#include <locale.h>
25

26 27 28 29 30 31 32 33 34 35 36 37 38 39
#include <glib.h>

#ifdef G_OS_WIN32
#include <windows.h>
#include <winnls.h>
#endif

#include "language.h"


void
language_init (const gchar *language)
{
#ifdef G_OS_WIN32
40 41 42 43 44
  if (! language                       &&
      g_getenv ("LANG")        == NULL &&
      g_getenv ("LC_MESSAGES") == NULL &&
      g_getenv ("LC_ALL")      == NULL &&
      g_getenv ("LANGUAGE")    == NULL)
45 46 47 48 49 50 51 52 53 54 55 56
    {
      /* FIXME: This is a hack. gettext doesn't pick the right language
       * by default on Windows, so we enforce the right one. The
       * following code is an adaptation of Python code from
       * pynicotine. For reasons why this approach is needed, and why
       * the GetLocaleInfo() approach in other libs falls flat, see:
       * http://blogs.msdn.com/b/michkap/archive/2007/04/15/2146890.aspx
       */

      switch (GetUserDefaultUILanguage())
        {
        case 1078:
57
          language = "af";          /* Afrikaans - South Africa */
58 59
          break;
        case 1052:
60
          language = "sq";          /* Albanian - Albania */
61 62
          break;
        case 1118:
63
          language = "am";          /* Amharic - Ethiopia */
64 65
          break;
        case 1025:
66
          language = "ar_SA";       /* Arabic - Saudi Arabia */
67 68
          break;
        case 5121:
69
          language = "ar_DZ";       /* Arabic - Algeria */
70 71
          break;
        case 15361:
72
          language = "ar_BH";       /* Arabic - Bahrain */
73 74
          break;
        case 3073:
75
          language = "ar_EG";       /* Arabic - Egypt */
76 77
          break;
        case 2049:
78
          language = "ar_IQ";       /* Arabic - Iraq */
79 80
          break;
        case 11265:
81
          language = "ar_JO";       /* Arabic - Jordan */
82 83
          break;
        case 13313:
84
          language = "ar_KW";       /* Arabic - Kuwait */
85 86
          break;
        case 12289:
87
          language = "ar_LB";       /* Arabic - Lebanon */
88 89
          break;
        case 4097:
90
          language = "ar_LY";       /* Arabic - Libya */
91 92
          break;
        case 6145:
93
          language = "ar_MO";       /* Arabic - Morocco */
94 95
          break;
        case 8193:
96
          language = "ar_OM";       /* Arabic - Oman */
97 98
          break;
        case 16385:
99
          language = "ar_QA";       /* Arabic - Qatar */
100 101
          break;
        case 10241:
102
          language = "ar_SY";       /* Arabic - Syria */
103 104
          break;
        case 7169:
105
          language = "ar_TN";       /* Arabic - Tunisia */
106 107
          break;
        case 14337:
108
          language = "ar_AE";       /* Arabic - U.A.E. */
109 110
          break;
        case 9217:
111
          language = "ar_YE";       /* Arabic - Yemen */
112 113
          break;
        case 1067:
114
          language = "hy";          /* Armenian - Armenia */
115 116
          break;
        case 1101:
117
          language = "as";          /* Assamese */
118 119
          break;
        case 2092:
120
          language = NULL;          /* Azeri (Cyrillic) */
121 122
          break;
        case 1068:
123
          language = NULL;          /* Azeri (Latin) */
124 125
          break;
        case 1069:
126
          language = "eu";          /* Basque */
127 128
          break;
        case 1059:
129
          language = "be";          /* Belarusian */
130 131
          break;
        case 1093:
132
          language = "bn_IN";       /* Bengali (India) */
133 134
          break;
        case 2117:
135
          language = "bn_BD";       /* Bengali (Bangladesh) */
136 137
          break;
        case 5146:
138
          language = "bs";          /* Bosnian (Bosnia/Herzegovina) */
139 140
          break;
        case 1026:
141
          language = "bg";          /* Bulgarian */
142 143
          break;
        case 1109:
144
          language = "my";          /* Burmese */
145 146
          break;
        case 1027:
147
          language = "ca";          /* Catalan */
148 149
          break;
        case 1116:
150
          language = NULL;          /* Cherokee - United States */
151 152
          break;
        case 2052:
153
          language = "zh_CN";       /* Chinese - People"s Republic of China */
154 155
          break;
        case 4100:
156
          language = "zh_SG";       /* Chinese - Singapore */
157 158
          break;
        case 1028:
159
          language = "zh_TW";       /* Chinese - Taiwan */
160 161
          break;
        case 3076:
162
          language = "zh_HK";       /* Chinese - Hong Kong SAR */
163 164
          break;
        case 5124:
165
          language = "zh_MO";       /* Chinese - Macao SAR */
166 167
          break;
        case 1050:
168
          language = "hr_HR";       /* Croatian */
169 170
          break;
        case 4122:
171
          language = "hr_BA";       /* Croatian (Bosnia/Herzegovina) */
172 173
          break;
        case 1029:
174
          language = "cs";          /* Czech */
175 176
          break;
        case 1030:
177
          language = "da";          /* Danish */
178 179
          break;
        case 1125:
180
          language = "dv";          /* Divehi */
181 182
          break;
        case 1043:
183
          language = "nl_NL";       /* Dutch - Netherlands */
184 185
          break;
        case 2067:
186
          language = "nl_BE";       /* Dutch - Belgium */
187 188
          break;
        case 1126:
189
          language = NULL;          /* Edo */
190 191
          break;
        case 1033:
192
          language = "en_US";       /* English - United States */
193 194
          break;
        case 2057:
195
          language = "en_UK";       /* English - United Kingdom */
196 197
          break;
        case 3081:
198
          language = "en_AU";       /* English - Australia */
199 200
          break;
        case 10249:
201
          language = "en_BZ";       /* English - Belize */
202 203
          break;
        case 4105:
204
          language = "en_CA";       /* English - Canada */
205 206
          break;
        case 9225:
207
          language = "en";          /* English - Caribbean */
208 209
          break;
        case 15369:
210
          language = "en_HK";       /* English - Hong Kong SAR */
211 212
          break;
        case 16393:
213
          language = "en_IN";       /* English - India */
214 215
          break;
        case 14345:
216
          language = "en_ID";       /* English - Indonesia */
217 218
          break;
        case 6153:
219
          language = "en_IR";       /* English - Ireland */
220 221
          break;
        case 8201:
222
          language = "en_JM";       /* English - Jamaica */
223 224
          break;
        case 17417:
225
          language = "en_MW";       /* English - Malaysia */
226 227
          break;
        case 5129:
228
          language = "en_NZ";       /* English - New Zealand */
229 230
          break;
        case 13321:
231
          language = "en_PH";       /* English - Philippines */
232 233
          break;
        case 18441:
234
          language = "en_SG";       /* English - Singapore */
235 236
          break;
        case 7177:
237
          language = "en_ZA";       /* English - South Africa */
238 239
          break;
        case 11273:
240
          language = "en_TT";       /* English - Trinidad */
241 242
          break;
        case 12297:
243
          language = "en_ZW";       /* English - Zimbabwe */
244 245
          break;
        case 1061:
246
          language = "et";          /* Estonian */
247 248
          break;
        case 1080:
249
          language = "fo";          /* Faroese */
250 251
          break;
        case 1065:
252
          language = "fa";          /* Farsi */
253 254
          break;
        case 1124:
255
          language = NULL;          /* Filipino */
256 257
          break;
        case 1035:
258
          language = "fi";          /* Finnish */
259 260
          break;
        case 1036:
261
          language = "fr_FR";       /* French - France */
262 263
          break;
        case 2060:
264
          language = "fr_BE";       /* French - Belgium */
265 266
          break;
        case 11276:
267
          language = "fr_CM";       /* French - Cameroon */
268 269
          break;
        case 3084:
270
          language = "fr_CA";       /* French - Canada */
271 272
          break;
        case 9228:
273
          language = "fr_CD";       /* French - Democratic Rep. of Congo */
274 275
          break;
        case 12300:
276
          language = "fr_CI";       /* French - Cote d"Ivoire */
277 278
          break;
        case 15372:
279
          language = "fr_HT";       /* French - Haiti */
280 281
          break;
        case 5132:
282
          language = "fr_LU";       /* French - Luxembourg */
283 284
          break;
        case 13324:
285
          language = "fr_ML";       /* French - Mali */
286 287
          break;
        case 6156:
288
          language = "fr_MC";       /* French - Monaco */
289 290
          break;
        case 14348:
291
          language = "fr_MA";       /* French - Morocco */
292 293
          break;
        case 58380:
294
          language = "fr";          /* French - North Africa */
295 296
          break;
        case 8204:
297
          language = "fr_RE";       /* French - Reunion */
298 299
          break;
        case 10252:
300
          language = "fr_SN";       /* French - Senegal */
301 302
          break;
        case 4108:
303
          language = "fr_CH";       /* French - Switzerland */
304 305
          break;
        case 7180:
306
          language = "fr";          /* French - West Indies */
307 308
          break;
        case 1122:
309
          language = "fy";          /* Frisian - Netherlands */
310 311
          break;
        case 1127:
312
          language = NULL;          /* Fulfulde - Nigeria */
313 314
          break;
        case 1071:
315
          language = "mk";          /* FYRO Macedonian */
316 317
          break;
        case 2108:
318
          language = "ga";          /* Gaelic (Ireland) */
319 320
          break;
        case 1084:
321
          language = "gd";          /* Gaelic (Scotland) */
322 323
          break;
        case 1110:
324
          language = "gl";          /* Galician */
325 326
          break;
        case 1079:
327
          language = "ka";          /* Georgian */
328 329
          break;
        case 1031:
330
          language = "de_DE";       /* German - Germany */
331 332
          break;
        case 3079:
333
          language = "de_AT";       /* German - Austria */
334 335
          break;
        case 5127:
336
          language = "de_LI";       /* German - Liechtenstein */
337 338
          break;
        case 4103:
339
          language = "de_LU";       /* German - Luxembourg */
340 341
          break;
        case 2055:
342
          language = "de_CH";       /* German - Switzerland */
343 344
          break;
        case 1032:
345
          language = "el";          /* Greek */
346 347
          break;
        case 1140:
348
          language = "gn";          /* Guarani - Paraguay */
349 350
          break;
        case 1095:
351
          language = "gu";          /* Gujarati */
352 353
          break;
        case 1128:
354
          language = "ha";          /* Hausa - Nigeria */
355 356
          break;
        case 1141:
357
          language = NULL;          /* Hawaiian - United States */
358 359
          break;
        case 1037:
360
          language = "he";          /* Hebrew */
361 362
          break;
        case 1081:
363
          language = "hi";          /* Hindi */
364 365
          break;
        case 1038:
366
          language = "hu";          /* Hungarian */
367 368
          break;
        case 1129:
369
          language = NULL;          /* Ibibio - Nigeria */
370 371
          break;
        case 1039:
372
          language = "is";          /* Icelandic */
373 374
          break;
        case 1136:
375
          language = "ig";          /* Igbo - Nigeria */
376 377
          break;
        case 1057:
378
          language = "id";          /* Indonesian */
379 380
          break;
        case 1117:
381
          language = "iu";          /* Inuktitut */
382 383
          break;
        case 1040:
384
          language = "it_IT";       /* Italian - Italy */
385 386
          break;
        case 2064:
387
          language = "it_CH";       /* Italian - Switzerland */
388 389
          break;
        case 1041:
390
          language = "ja";          /* Japanese */
391 392
          break;
        case 1099:
393
          language = "kn";          /* Kannada */
394 395
          break;
        case 1137:
396
          language = "kr";          /* Kanuri - Nigeria */
397 398
          break;
        case 2144:
399
          language = "ks";          /* Kashmiri */
400 401
          break;
        case 1120:
402
          language = "ks";          /* Kashmiri (Arabic) */
403 404
          break;
        case 1087:
405
          language = "kk";          /* Kazakh */
406 407
          break;
        case 1107:
408
          language = "km";          /* Khmer */
409 410
          break;
        case 1111:
411
          language = NULL;          /* Konkani */
412 413
          break;
        case 1042:
414
          language = "ko";          /* Korean */
415 416
          break;
        case 1088:
417
          language = "ky";          /* Kyrgyz (Cyrillic) */
418 419
          break;
        case 1108:
420
          language = "lo";          /* Lao */
421 422
          break;
        case 1142:
423
          language = "la";          /* Latin */
424 425
          break;
        case 1062:
426
          language = "lv";          /* Latvian */
427 428
          break;
        case 1063:
429
          language = "lt";          /* Lithuanian */
430 431
          break;
        case 1086:
432
          language = "ms_MY";       /* Malay - Malaysia */
433 434
          break;
        case 2110:
435
          language = "ms_BN";       /* Malay - Brunei Darussalam */
436 437
          break;
        case 1100:
438
          language = "ml";          /* Malayalam */
439 440
          break;
        case 1082:
441
          language = "mt";          /* Maltese */
442 443
          break;
        case 1112:
444
          language = NULL;          /* Manipuri */
445 446
          break;
        case 1153:
447
          language = "mi";          /* Maori - New Zealand */
448 449
          break;
        case 1102:
450
          language = "mr";          /* Marathi */
451 452
          break;
        case 1104:
453
          language = "mn";          /* Mongolian (Cyrillic) */
454 455
          break;
        case 2128:
456
          language = "mn";          /* Mongolian (Mongolian) */
457 458
          break;
        case 1121:
459
          language = "ne_NP";       /* Nepali */
460 461
          break;
        case 2145:
462
          language = "ne_IN";       /* Nepali - India */
463 464
          break;
        case 1044:
465
          language = "no";          /* Norwegian (Bokmᅢᆬl) */
466 467
          break;
        case 2068:
468
          language = "no";          /* Norwegian (Nynorsk) */
469 470
          break;
        case 1096:
471
          language = "or";          /* Oriya */
472 473
          break;
        case 1138:
474
          language = "om";          /* Oromo */
475 476
          break;
        case 1145:
477
          language = NULL;          /* Papiamentu */
478 479
          break;
        case 1123:
480
          language = "ps";          /* Pashto */
481 482
          break;
        case 1045:
483
          language = "pl";          /* Polish */
484 485
          break;
        case 1046:
486
          language = "pt_BR";       /* Portuguese - Brazil */
487 488
          break;
        case 2070:
489
          language = "pt_PT";       /* Portuguese - Portugal */
490 491
          break;
        case 1094:
492
          language = "pa";          /* Punjabi */
493 494
          break;
        case 2118:
495
          language = "pa_PK";       /* Punjabi (Pakistan) */
496 497
          break;
        case 1131:
498
          language = "qu_BO";       /* Quecha - Bolivia */
499 500
          break;
        case 2155:
501
          language = "qu_EC";       /* Quecha - Ecuador */
502 503
          break;
        case 3179:
504
          language = "qu_PE";       /* Quecha - Peru */
505 506
          break;
        case 1047:
507
          language = "rm";          /* Rhaeto-Romanic */
508 509
          break;
        case 1048:
510
          language = "ro_RO";       /* Romanian */
511 512
          break;
        case 2072:
513
          language = "ro_MD";       /* Romanian - Moldava */
514 515
          break;
        case 1049:
516
          language = "ru_RU";       /* Russian */
517 518
          break;
        case 2073:
519
          language = "ru_MD";       /* Russian - Moldava */
520 521
          break;
        case 1083:
522
          language = NULL;          /* Sami (Lappish) */
523 524
          break;
        case 1103:
525
          language = "sa";          /* Sanskrit */
526 527
          break;
        case 1132:
528
          language = NULL;          /* Sepedi */
529 530
          break;
        case 3098:
531
          language = "sr";          /* Serbian (Cyrillic) */
532 533
          break;
        case 2074:
534
          language = "sr@latin";    /* Serbian (Latin) */
535 536
          break;
        case 1113:
537
          language = "sd_IN";       /* Sindhi - India */
538 539
          break;
        case 2137:
540
          language = "sd_PK";       /* Sindhi - Pakistan */
541 542
          break;
        case 1115:
543
          language = "si";          /* Sinhalese - Sri Lanka */
544 545
          break;
        case 1051:
546
          language = "sk";          /* Slovak */
547 548
          break;
        case 1060:
549
          language = "sl";          /* Slovenian */
550 551
          break;
        case 1143:
552
          language = "so";          /* Somali */
553 554
          break;
        case 1070:
555
          language = NULL;          /* Sorbian */
556 557
          break;
        case 3082:
558
          language = "es";          /* Spanish - Spain (Modern Sort) */
559 560
          break;
        case 1034:
561
          language = "es";          /* Spanish - Spain (Traditional Sort) */
562 563
          break;
        case 11274:
564
          language = "es_AR";       /* Spanish - Argentina */
565 566
          break;
        case 16394:
567
          language = "es_BO";       /* Spanish - Bolivia */
568 569
          break;
        case 13322:
570
          language = "es_CL";       /* Spanish - Chile */
571 572
          break;
        case 9226:
573
          language = "es_CO";       /* Spanish - Colombia */
574 575
          break;
        case 5130:
576
          language = "es_CR";       /* Spanish - Costa Rica */
577 578
          break;
        case 7178:
579
          language = "es_DO";       /* Spanish - Dominican Republic */
580 581
          break;
        case 12298:
582
          language = "es_EC";       /* Spanish - Ecuador */
583 584
          break;
        case 17418:
585
          language = "es_SV";       /* Spanish - El Salvador */
586 587
          break;
        case 4106:
588
          language = "es_GT";       /* Spanish - Guatemala */
589 590
          break;
        case 18442:
591
          language = "es_HN";       /* Spanish - Honduras */
592 593
          break;
        case 58378:
594
          language = "es";          /* Spanish - Latin America */
595 596
          break;
        case 2058:
597
          language = "es_MX";       /* Spanish - Mexico */
598 599
          break;
        case 19466:
600
          language = "es_NI";       /* Spanish - Nicaragua */
601 602
          break;
        case 6154:
603
          language = "es_PA";       /* Spanish - Panama */
604 605
          break;
        case 15370:
606
          language = "es_PY";       /* Spanish - Paraguay */
607 608
          break;
        case 10250:
609
          language = "es_PE";       /* Spanish - Peru */
610 611
          break;
        case 20490:
612
          language = "es_PR";       /* Spanish - Puerto Rico */
613 614
          break;
        case 21514:
615
          language = "es_US";       /* Spanish - United States */
616 617
          break;
        case 14346:
618
          language = "es_UY";       /* Spanish - Uruguay */
619 620
          break;
        case 8202:
621
          language = "es_VE";       /* Spanish - Venezuela */
622 623
          break;
        case 1072:
624
          language = NULL;          /* Sutu */
625 626
          break;
        case 1089:
627
          language = "sw";          /* Swahili */
628 629
          break;
        case 1053:
630
          language = "sv_SE";       /* Swedish */
631 632
          break;
        case 2077:
633
          language = "sv_FI";       /* Swedish - Finland */
634 635
          break;
        case 1114:
636
          language = NULL;          /* Syriac */
637 638
          break;
        case 1064:
639
          language = "tg";          /* Tajik */
640 641
          break;
        case 1119:
642
          language = NULL;          /* Tamazight (Arabic) */
643 644
          break;
        case 2143:
645
          language = NULL;          /* Tamazight (Latin) */
646 647
          break;
        case 1097:
648
          language = "ta";          /* Tamil */
649 650
          break;
        case 1092:
651
          language = "tt";          /* Tatar */
652 653
          break;
        case 1098:
654
          language = "te";          /* Telugu */
655 656
          break;
        case 1054:
657
          language = "th";          /* Thai */
658 659
          break;
        case 2129:
660
          language = "bo_BT";       /* Tibetan - Bhutan */
661 662
          break;
        case 1105:
663
          language = "bo_CN";       /* Tibetan - People"s Republic of China */
664 665
          break;
        case 2163:
666
          language = "ti_ER";       /* Tigrigna - Eritrea */
667 668
          break;
        case 1139:
669
          language = "ti_ET";       /* Tigrigna - Ethiopia */
670 671
          break;
        case 1073:
672
          language = "ts";          /* Tsonga */
673 674
          break;
        case 1074:
675
          language = "tn";          /* Tswana */
676 677
          break;
        case 1055:
678
          language = "tr";          /* Turkish */
679 680
          break;
        case 1090:
681
          language = "tk";          /* Turkmen */
682 683
          break;
        case 1152:
684
          language = "ug";          /* Uighur - China */
685 686
          break;
        case 1058:
687
          language = "uk";          /* Ukrainian */
688 689
          break;
        case 1056:
690
          language = "ur";          /* Urdu */
691 692
          break;
        case 2080:
693
          language = "ur_IN";       /* Urdu - India */
694 695
          break;
        case 2115:
696
          language = "uz";          /* Uzbek (Cyrillic) */
697 698
          break;
        case 1091:
699
          language = "uz@latin";    /* Uzbek (Latin) */
700 701
          break;
        case 1075:
702
          language = "ve";          /* Venda */
703 704
          break;
        case 1066:
705
          language = "vi";          /* Vietnamese */
706 707
          break;
        case 1106:
708
          language = "cy";          /* Welsh */
709 710
          break;
        case 1076:
711
          language = "xh";          /* Xhosa */
712 713
          break;
        case 1144:
714
          language = NULL;          /* Yi */
715 716
          break;
        case 1085:
717
          language = "yi";          /* Yiddish */
718 719
          break;
        case 1130:
720
          language = "yo";          /* Yoruba */
721 722
          break;
        case 1077:
723
          language = "zu";          /* Zulu */
724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739
          break;
        default:
          language = NULL;
        }
    }
#endif

  /*  We already set the locale according to the environment, so just
   *  return early if no language is set in gimprc.
   */
  if (! language)
    return;

  g_setenv ("LANGUAGE", language, TRUE);
  setlocale (LC_ALL, "");
}