@publishpress/potomatic 0.0.0-stage → 1.4.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,1113 @@
1
+ /**
2
+ * Language Mapping Utility.
3
+ *
4
+ * Comprehensive mapping of language codes and locales to English language names.
5
+ * Based on GlotPress locales data from WordPress.org translation platform.
6
+ *
7
+ * Supports multiple formats:
8
+ * - WordPress locales (zh_CN, fr_FR, ru_RU)
9
+ * - ISO 639-1 codes (zh, fr, ru)
10
+ * - BCP 47 style (zh-CN, fr-FR, ru-RU)
11
+ * - GlotPress slugs (zh-cn, fr-fr, ru-ru)
12
+ *
13
+ * Source: https://raw.githubusercontent.com/GlotPress/GlotPress/refs/heads/develop/locales/locales.php
14
+ *
15
+ * @since 1.0.0
16
+ */
17
+
18
+ /**
19
+ * Primary language mapping from various locale formats to English names.
20
+ * This is the comprehensive mapping extracted from GlotPress locales data.
21
+ * Supports multiple locale code formats including WordPress (underscore), BCP 47 (dash),
22
+ * ISO 639-1/639-2 codes, and GlotPress slug formats.
23
+ *
24
+ * @since 1.0.0
25
+ *
26
+ * @type {Object.<string, string>}
27
+ */
28
+ const LANGUAGE_MAPPING = {
29
+ // Afrikaans
30
+ af: 'Afrikaans',
31
+ af_ZA: 'Afrikaans',
32
+ 'af-za': 'Afrikaans',
33
+ afr: 'Afrikaans',
34
+
35
+ // Akan
36
+ ak: 'Akan',
37
+ ak_GH: 'Akan',
38
+ 'ak-gh': 'Akan',
39
+ aka: 'Akan',
40
+
41
+ // Amharic
42
+ am: 'Amharic',
43
+ am_ET: 'Amharic',
44
+ 'am-et': 'Amharic',
45
+ amh: 'Amharic',
46
+
47
+ // Arabic
48
+ ar: 'Arabic',
49
+ ar_AR: 'Arabic',
50
+ 'ar-ar': 'Arabic',
51
+ ara: 'Arabic',
52
+ arq: 'Algerian Arabic',
53
+ ary: 'Moroccan Arabic',
54
+
55
+ // Assamese
56
+ as: 'Assamese',
57
+ asm: 'Assamese',
58
+
59
+ // Azerbaijani
60
+ az: 'Azerbaijani',
61
+ az_AZ: 'Azerbaijani',
62
+ 'az-az': 'Azerbaijani',
63
+ aze: 'Azerbaijani',
64
+
65
+ // Bashkir
66
+ ba: 'Bashkir',
67
+ bak: 'Bashkir',
68
+
69
+ // Belarusian
70
+ be: 'Belarusian',
71
+ be_BY: 'Belarusian',
72
+ 'be-by': 'Belarusian',
73
+ bel: 'Belarusian',
74
+
75
+ // Bulgarian
76
+ bg: 'Bulgarian',
77
+ bg_BG: 'Bulgarian',
78
+ 'bg-bg': 'Bulgarian',
79
+ bul: 'Bulgarian',
80
+
81
+ // Bengali
82
+ bn: 'Bengali',
83
+ bn_BD: 'Bengali (Bangladesh)',
84
+ 'bn-bd': 'Bengali (Bangladesh)',
85
+ bn_IN: 'Bengali (India)',
86
+ 'bn-in': 'Bengali (India)',
87
+ ben: 'Bengali',
88
+
89
+ // Tibetan
90
+ bo: 'Tibetan',
91
+ bod: 'Tibetan',
92
+ tib: 'Tibetan',
93
+
94
+ // Breton
95
+ br: 'Breton',
96
+ bre: 'Breton',
97
+
98
+ // Bosnian
99
+ bs: 'Bosnian',
100
+ bs_BA: 'Bosnian',
101
+ 'bs-ba': 'Bosnian',
102
+ bos: 'Bosnian',
103
+
104
+ // Catalan
105
+ ca: 'Catalan',
106
+ ca_ES: 'Catalan',
107
+ 'ca-es': 'Catalan',
108
+ cat: 'Catalan',
109
+
110
+ // Cherokee
111
+ chr: 'Cherokee',
112
+
113
+ // Corsican
114
+ co: 'Corsican',
115
+ cos: 'Corsican',
116
+
117
+ // Czech
118
+ cs: 'Czech',
119
+ cs_CZ: 'Czech',
120
+ 'cs-cz': 'Czech',
121
+ ces: 'Czech',
122
+ cze: 'Czech',
123
+
124
+ // Welsh
125
+ cy: 'Welsh',
126
+ cy_GB: 'Welsh',
127
+ 'cy-gb': 'Welsh',
128
+ cym: 'Welsh',
129
+ wel: 'Welsh',
130
+
131
+ // Danish
132
+ da: 'Danish',
133
+ da_DK: 'Danish',
134
+ 'da-dk': 'Danish',
135
+ dan: 'Danish',
136
+
137
+ // German
138
+ de: 'German',
139
+ de_DE: 'German',
140
+ 'de-de': 'German',
141
+ de_AT: 'German (Austria)',
142
+ 'de-at': 'German (Austria)',
143
+ de_CH: 'German (Switzerland)',
144
+ 'de-ch': 'German (Switzerland)',
145
+ deu: 'German',
146
+ ger: 'German',
147
+
148
+ // Greek
149
+ el: 'Greek',
150
+ el_GR: 'Greek',
151
+ 'el-gr': 'Greek',
152
+ ell: 'Greek',
153
+ gre: 'Greek',
154
+
155
+ // English
156
+ en: 'English',
157
+ en_US: 'English (US)',
158
+ 'en-us': 'English (US)',
159
+ en_GB: 'English (UK)',
160
+ 'en-gb': 'English (UK)',
161
+ en_AU: 'English (Australia)',
162
+ 'en-au': 'English (Australia)',
163
+ en_CA: 'English (Canada)',
164
+ 'en-ca': 'English (Canada)',
165
+ en_NZ: 'English (New Zealand)',
166
+ 'en-nz': 'English (New Zealand)',
167
+ en_ZA: 'English (South Africa)',
168
+ 'en-za': 'English (South Africa)',
169
+ eng: 'English',
170
+
171
+ // Esperanto
172
+ eo: 'Esperanto',
173
+ epo: 'Esperanto',
174
+
175
+ // Spanish
176
+ es: 'Spanish',
177
+ es_ES: 'Spanish (Spain)',
178
+ 'es-es': 'Spanish (Spain)',
179
+ es_MX: 'Spanish (Mexico)',
180
+ 'es-mx': 'Spanish (Mexico)',
181
+ es_AR: 'Spanish (Argentina)',
182
+ 'es-ar': 'Spanish (Argentina)',
183
+ es_CL: 'Spanish (Chile)',
184
+ 'es-cl': 'Spanish (Chile)',
185
+ es_CO: 'Spanish (Colombia)',
186
+ 'es-co': 'Spanish (Colombia)',
187
+ es_PE: 'Spanish (Peru)',
188
+ 'es-pe': 'Spanish (Peru)',
189
+ es_VE: 'Spanish (Venezuela)',
190
+ 'es-ve': 'Spanish (Venezuela)',
191
+ spa: 'Spanish',
192
+
193
+ // Estonian
194
+ et: 'Estonian',
195
+ et_EE: 'Estonian',
196
+ 'et-ee': 'Estonian',
197
+ est: 'Estonian',
198
+
199
+ // Basque
200
+ eu: 'Basque',
201
+ eu_ES: 'Basque',
202
+ 'eu-es': 'Basque',
203
+ eus: 'Basque',
204
+ baq: 'Basque',
205
+
206
+ // Persian/Farsi
207
+ fa: 'Persian',
208
+ fa_IR: 'Persian',
209
+ 'fa-ir': 'Persian',
210
+ fas: 'Persian',
211
+ per: 'Persian',
212
+
213
+ // Finnish
214
+ fi: 'Finnish',
215
+ fi_FI: 'Finnish',
216
+ 'fi-fi': 'Finnish',
217
+ fin: 'Finnish',
218
+
219
+ // French
220
+ fr: 'French',
221
+ fr_FR: 'French (France)',
222
+ 'fr-fr': 'French (France)',
223
+ fr_CA: 'French (Canada)',
224
+ 'fr-ca': 'French (Canada)',
225
+ fr_BE: 'French (Belgium)',
226
+ 'fr-be': 'French (Belgium)',
227
+ fr_CH: 'French (Switzerland)',
228
+ 'fr-ch': 'French (Switzerland)',
229
+ fra: 'French',
230
+ fre: 'French',
231
+
232
+ // Western Frisian
233
+ fy: 'Western Frisian',
234
+ fy_NL: 'Western Frisian',
235
+ 'fy-nl': 'Western Frisian',
236
+ fry: 'Western Frisian',
237
+
238
+ // Irish
239
+ ga: 'Irish',
240
+ ga_IE: 'Irish',
241
+ 'ga-ie': 'Irish',
242
+ gle: 'Irish',
243
+
244
+ // Scottish Gaelic
245
+ gd: 'Scottish Gaelic',
246
+ gd_GB: 'Scottish Gaelic',
247
+ 'gd-gb': 'Scottish Gaelic',
248
+ gla: 'Scottish Gaelic',
249
+
250
+ // Galician
251
+ gl: 'Galician',
252
+ gl_ES: 'Galician',
253
+ 'gl-es': 'Galician',
254
+ glg: 'Galician',
255
+
256
+ // Gujarati
257
+ gu: 'Gujarati',
258
+ gu_IN: 'Gujarati',
259
+ 'gu-in': 'Gujarati',
260
+ guj: 'Gujarati',
261
+
262
+ // Hebrew
263
+ he: 'Hebrew',
264
+ he_IL: 'Hebrew',
265
+ 'he-il': 'Hebrew',
266
+ heb: 'Hebrew',
267
+ iw: 'Hebrew', // Legacy code.
268
+
269
+ // Hindi
270
+ hi: 'Hindi',
271
+ hi_IN: 'Hindi',
272
+ 'hi-in': 'Hindi',
273
+ hin: 'Hindi',
274
+
275
+ // Croatian
276
+ hr: 'Croatian',
277
+ hr_HR: 'Croatian',
278
+ 'hr-hr': 'Croatian',
279
+ hrv: 'Croatian',
280
+
281
+ // Hungarian
282
+ hu: 'Hungarian',
283
+ hu_HU: 'Hungarian',
284
+ 'hu-hu': 'Hungarian',
285
+ hun: 'Hungarian',
286
+
287
+ // Armenian
288
+ hy: 'Armenian',
289
+ hy_AM: 'Armenian',
290
+ 'hy-am': 'Armenian',
291
+ hye: 'Armenian',
292
+ arm: 'Armenian',
293
+
294
+ // Indonesian
295
+ id: 'Indonesian',
296
+ id_ID: 'Indonesian',
297
+ 'id-id': 'Indonesian',
298
+ ind: 'Indonesian',
299
+
300
+ // Icelandic
301
+ is: 'Icelandic',
302
+ is_IS: 'Icelandic',
303
+ 'is-is': 'Icelandic',
304
+ isl: 'Icelandic',
305
+ ice: 'Icelandic',
306
+
307
+ // Italian
308
+ it: 'Italian',
309
+ it_IT: 'Italian',
310
+ 'it-it': 'Italian',
311
+ ita: 'Italian',
312
+
313
+ // Japanese
314
+ ja: 'Japanese',
315
+ ja_JP: 'Japanese',
316
+ 'ja-jp': 'Japanese',
317
+ jpn: 'Japanese',
318
+
319
+ // Georgian
320
+ ka: 'Georgian',
321
+ ka_GE: 'Georgian',
322
+ 'ka-ge': 'Georgian',
323
+ kat: 'Georgian',
324
+ geo: 'Georgian',
325
+
326
+ // Kazakh
327
+ kk: 'Kazakh',
328
+ kk_KZ: 'Kazakh',
329
+ 'kk-kz': 'Kazakh',
330
+ kaz: 'Kazakh',
331
+
332
+ // Khmer
333
+ km: 'Khmer',
334
+ km_KH: 'Khmer',
335
+ 'km-kh': 'Khmer',
336
+ khm: 'Khmer',
337
+
338
+ // Kannada
339
+ kn: 'Kannada',
340
+ kn_IN: 'Kannada',
341
+ 'kn-in': 'Kannada',
342
+ kan: 'Kannada',
343
+
344
+ // Korean
345
+ ko: 'Korean',
346
+ ko_KR: 'Korean',
347
+ 'ko-kr': 'Korean',
348
+ kor: 'Korean',
349
+
350
+ // Kurdish
351
+ ku: 'Kurdish',
352
+ kur: 'Kurdish',
353
+
354
+ // Kyrgyz
355
+ ky: 'Kyrgyz',
356
+ ky_KG: 'Kyrgyz',
357
+ 'ky-kg': 'Kyrgyz',
358
+ kir: 'Kyrgyz',
359
+
360
+ // Latin
361
+ la: 'Latin',
362
+ lat: 'Latin',
363
+
364
+ // Luxembourgish
365
+ lb: 'Luxembourgish',
366
+ lb_LU: 'Luxembourgish',
367
+ 'lb-lu': 'Luxembourgish',
368
+ ltz: 'Luxembourgish',
369
+
370
+ // Lao
371
+ lo: 'Lao',
372
+ lo_LA: 'Lao',
373
+ 'lo-la': 'Lao',
374
+ lao: 'Lao',
375
+
376
+ // Lithuanian
377
+ lt: 'Lithuanian',
378
+ lt_LT: 'Lithuanian',
379
+ 'lt-lt': 'Lithuanian',
380
+ lit: 'Lithuanian',
381
+
382
+ // Latvian
383
+ lv: 'Latvian',
384
+ lv_LV: 'Latvian',
385
+ 'lv-lv': 'Latvian',
386
+ lav: 'Latvian',
387
+
388
+ // Malagasy
389
+ mg: 'Malagasy',
390
+ mg_MG: 'Malagasy',
391
+ 'mg-mg': 'Malagasy',
392
+ mlg: 'Malagasy',
393
+
394
+ // Macedonian
395
+ mk: 'Macedonian',
396
+ mk_MK: 'Macedonian',
397
+ 'mk-mk': 'Macedonian',
398
+ mkd: 'Macedonian',
399
+ mac: 'Macedonian',
400
+
401
+ // Malayalam
402
+ ml: 'Malayalam',
403
+ ml_IN: 'Malayalam',
404
+ 'ml-in': 'Malayalam',
405
+ mal: 'Malayalam',
406
+
407
+ // Mongolian
408
+ mn: 'Mongolian',
409
+ mn_MN: 'Mongolian',
410
+ 'mn-mn': 'Mongolian',
411
+ mon: 'Mongolian',
412
+
413
+ // Marathi
414
+ mr: 'Marathi',
415
+ mr_IN: 'Marathi',
416
+ 'mr-in': 'Marathi',
417
+ mar: 'Marathi',
418
+
419
+ // Malay
420
+ ms: 'Malay',
421
+ ms_MY: 'Malay',
422
+ 'ms-my': 'Malay',
423
+ msa: 'Malay',
424
+ may: 'Malay',
425
+
426
+ // Maltese
427
+ mt: 'Maltese',
428
+ mt_MT: 'Maltese',
429
+ 'mt-mt': 'Maltese',
430
+ mlt: 'Maltese',
431
+
432
+ // Burmese
433
+ my: 'Burmese',
434
+ my_MM: 'Burmese',
435
+ 'my-mm': 'Burmese',
436
+ mya: 'Burmese',
437
+ bur: 'Burmese',
438
+
439
+ // Norwegian (Bokmål)
440
+ nb: 'Norwegian (Bokmål)',
441
+ nb_NO: 'Norwegian (Bokmål)',
442
+ 'nb-no': 'Norwegian (Bokmål)',
443
+ nob: 'Norwegian (Bokmål)',
444
+
445
+ // Nepali
446
+ ne: 'Nepali',
447
+ ne_NP: 'Nepali',
448
+ 'ne-np': 'Nepali',
449
+ nep: 'Nepali',
450
+
451
+ // Dutch
452
+ nl: 'Dutch',
453
+ nl_NL: 'Dutch',
454
+ 'nl-nl': 'Dutch',
455
+ nl_BE: 'Dutch (Belgium)',
456
+ 'nl-be': 'Dutch (Belgium)',
457
+ nld: 'Dutch',
458
+ dut: 'Dutch',
459
+
460
+ // Norwegian (Nynorsk)
461
+ nn: 'Norwegian (Nynorsk)',
462
+ nn_NO: 'Norwegian (Nynorsk)',
463
+ 'nn-no': 'Norwegian (Nynorsk)',
464
+ nno: 'Norwegian (Nynorsk)',
465
+
466
+ // Norwegian (generic)
467
+ no: 'Norwegian',
468
+ no_NO: 'Norwegian',
469
+ 'no-no': 'Norwegian',
470
+ nor: 'Norwegian',
471
+
472
+ // Occitan
473
+ oc: 'Occitan',
474
+ oci: 'Occitan',
475
+
476
+ // Oriya
477
+ or: 'Oriya',
478
+ or_IN: 'Oriya',
479
+ 'or-in': 'Oriya',
480
+ ori: 'Oriya',
481
+
482
+ // Punjabi
483
+ pa: 'Punjabi',
484
+ pa_IN: 'Punjabi',
485
+ 'pa-in': 'Punjabi',
486
+ pan: 'Punjabi',
487
+
488
+ // Polish
489
+ pl: 'Polish',
490
+ pl_PL: 'Polish',
491
+ 'pl-pl': 'Polish',
492
+ pol: 'Polish',
493
+
494
+ // Portuguese
495
+ pt: 'Portuguese',
496
+ pt_PT: 'Portuguese (Portugal)',
497
+ 'pt-pt': 'Portuguese (Portugal)',
498
+ pt_BR: 'Portuguese (Brazil)',
499
+ 'pt-br': 'Portuguese (Brazil)',
500
+ por: 'Portuguese',
501
+
502
+ // Romanian
503
+ ro: 'Romanian',
504
+ ro_RO: 'Romanian',
505
+ 'ro-ro': 'Romanian',
506
+ ron: 'Romanian',
507
+ rum: 'Romanian',
508
+
509
+ // Russian
510
+ ru: 'Russian',
511
+ ru_RU: 'Russian',
512
+ 'ru-ru': 'Russian',
513
+ rus: 'Russian',
514
+
515
+ // Sanskrit
516
+ sa: 'Sanskrit',
517
+ sa_IN: 'Sanskrit',
518
+ 'sa-in': 'Sanskrit',
519
+ san: 'Sanskrit',
520
+
521
+ // Sindhi
522
+ sd: 'Sindhi',
523
+ sd_PK: 'Sindhi',
524
+ 'sd-pk': 'Sindhi',
525
+ snd: 'Sindhi',
526
+
527
+ // Slovak
528
+ sk: 'Slovak',
529
+ sk_SK: 'Slovak',
530
+ 'sk-sk': 'Slovak',
531
+ slk: 'Slovak',
532
+ slo: 'Slovak',
533
+
534
+ // Slovenian
535
+ sl: 'Slovenian',
536
+ sl_SI: 'Slovenian',
537
+ 'sl-si': 'Slovenian',
538
+ slv: 'Slovenian',
539
+
540
+ // Albanian
541
+ sq: 'Albanian',
542
+ sq_AL: 'Albanian',
543
+ 'sq-al': 'Albanian',
544
+ sqi: 'Albanian',
545
+ alb: 'Albanian',
546
+
547
+ // Serbian
548
+ sr: 'Serbian',
549
+ sr_RS: 'Serbian',
550
+ 'sr-rs': 'Serbian',
551
+ srp: 'Serbian',
552
+
553
+ // Swedish
554
+ sv: 'Swedish',
555
+ sv_SE: 'Swedish',
556
+ 'sv-se': 'Swedish',
557
+ swe: 'Swedish',
558
+
559
+ // Swahili
560
+ sw: 'Swahili',
561
+ sw_KE: 'Swahili',
562
+ 'sw-ke': 'Swahili',
563
+ swa: 'Swahili',
564
+
565
+ // Tamil
566
+ ta: 'Tamil',
567
+ ta_IN: 'Tamil',
568
+ 'ta-in': 'Tamil',
569
+ ta_LK: 'Tamil (Sri Lanka)',
570
+ 'ta-lk': 'Tamil (Sri Lanka)',
571
+ tam: 'Tamil',
572
+
573
+ // Telugu
574
+ te: 'Telugu',
575
+ te_IN: 'Telugu',
576
+ 'te-in': 'Telugu',
577
+ tel: 'Telugu',
578
+
579
+ // Tajik
580
+ tg: 'Tajik',
581
+ tg_TJ: 'Tajik',
582
+ 'tg-tj': 'Tajik',
583
+ tgk: 'Tajik',
584
+
585
+ // Thai
586
+ th: 'Thai',
587
+ th_TH: 'Thai',
588
+ 'th-th': 'Thai',
589
+ tha: 'Thai',
590
+
591
+ // Turkish
592
+ tr: 'Turkish',
593
+ tr_TR: 'Turkish',
594
+ 'tr-tr': 'Turkish',
595
+ tur: 'Turkish',
596
+
597
+ // Ukrainian
598
+ uk: 'Ukrainian',
599
+ uk_UA: 'Ukrainian',
600
+ 'uk-ua': 'Ukrainian',
601
+ ukr: 'Ukrainian',
602
+
603
+ // Urdu
604
+ ur: 'Urdu',
605
+ ur_PK: 'Urdu',
606
+ 'ur-pk': 'Urdu',
607
+ urd: 'Urdu',
608
+
609
+ // Uzbek
610
+ uz: 'Uzbek',
611
+ uz_UZ: 'Uzbek',
612
+ 'uz-uz': 'Uzbek',
613
+ uzb: 'Uzbek',
614
+
615
+ // Vietnamese
616
+ vi: 'Vietnamese',
617
+ vi_VN: 'Vietnamese',
618
+ 'vi-vn': 'Vietnamese',
619
+ vie: 'Vietnamese',
620
+
621
+ // Yiddish
622
+ yi: 'Yiddish',
623
+ yid: 'Yiddish',
624
+
625
+ // Yoruba
626
+ yo: 'Yoruba',
627
+ yo_NG: 'Yoruba',
628
+ 'yo-ng': 'Yoruba',
629
+ yor: 'Yoruba',
630
+
631
+ // Chinese
632
+ zh: 'Chinese',
633
+ zh_CN: 'Chinese (Simplified)',
634
+ 'zh-cn': 'Chinese (Simplified)',
635
+ zh_TW: 'Chinese (Traditional)',
636
+ 'zh-tw': 'Chinese (Traditional)',
637
+ zh_HK: 'Chinese (Hong Kong)',
638
+ 'zh-hk': 'Chinese (Hong Kong)',
639
+ zh_SG: 'Chinese (Singapore)',
640
+ 'zh-sg': 'Chinese (Singapore)',
641
+ zho: 'Chinese',
642
+ chi: 'Chinese',
643
+
644
+ // Zulu
645
+ zu: 'Zulu',
646
+ zu_ZA: 'Zulu',
647
+ 'zu-za': 'Zulu',
648
+ zul: 'Zulu',
649
+
650
+ // Tamazight
651
+ zgh: 'Tamazight',
652
+
653
+ // Mingrelian
654
+ xmf: 'Mingrelian',
655
+ };
656
+
657
+ /**
658
+ * Default locale mappings for languages that don't have a specific region.
659
+ * Used when converting from language names or base codes to full locales.
660
+ *
661
+ * @since 1.0.0
662
+ *
663
+ * @type {Object.<string, string>}
664
+ */
665
+ const DEFAULT_LOCALE_MAPPING = {
666
+ af: 'af_ZA',
667
+ ar: 'ar_AR',
668
+ az: 'az_AZ',
669
+ be: 'be_BY',
670
+ bg: 'bg_BG',
671
+ bn: 'bn_BD',
672
+ bs: 'bs_BA',
673
+ ca: 'ca_ES',
674
+ cs: 'cs_CZ',
675
+ cy: 'cy_GB',
676
+ da: 'da_DK',
677
+ de: 'de_DE',
678
+ el: 'el_GR',
679
+ en: 'en_US',
680
+ es: 'es_ES',
681
+ et: 'et_EE',
682
+ eu: 'eu_ES',
683
+ fa: 'fa_IR',
684
+ fi: 'fi_FI',
685
+ fr: 'fr_FR',
686
+ fy: 'fy_NL',
687
+ ga: 'ga_IE',
688
+ gd: 'gd_GB',
689
+ gl: 'gl_ES',
690
+ gu: 'gu_IN',
691
+ he: 'he_IL',
692
+ hi: 'hi_IN',
693
+ hr: 'hr_HR',
694
+ hu: 'hu_HU',
695
+ hy: 'hy_AM',
696
+ id: 'id_ID',
697
+ is: 'is_IS',
698
+ it: 'it_IT',
699
+ ja: 'ja_JP',
700
+ ka: 'ka_GE',
701
+ kk: 'kk_KZ',
702
+ km: 'km_KH',
703
+ kn: 'kn_IN',
704
+ ko: 'ko_KR',
705
+ ky: 'ky_KG',
706
+ lb: 'lb_LU',
707
+ lo: 'lo_LA',
708
+ lt: 'lt_LT',
709
+ lv: 'lv_LV',
710
+ mg: 'mg_MG',
711
+ mk: 'mk_MK',
712
+ ml: 'ml_IN',
713
+ mn: 'mn_MN',
714
+ mr: 'mr_IN',
715
+ ms: 'ms_MY',
716
+ mt: 'mt_MT',
717
+ my: 'my_MM',
718
+ nb: 'nb_NO',
719
+ ne: 'ne_NP',
720
+ nl: 'nl_NL',
721
+ nn: 'nn_NO',
722
+ no: 'no_NO',
723
+ or: 'or_IN',
724
+ pa: 'pa_IN',
725
+ pl: 'pl_PL',
726
+ pt: 'pt_PT',
727
+ ro: 'ro_RO',
728
+ ru: 'ru_RU',
729
+ sa: 'sa_IN',
730
+ sd: 'sd_PK',
731
+ sk: 'sk_SK',
732
+ sl: 'sl_SI',
733
+ sq: 'sq_AL',
734
+ sr: 'sr_RS',
735
+ sv: 'sv_SE',
736
+ sw: 'sw_KE',
737
+ ta: 'ta_IN',
738
+ te: 'te_IN',
739
+ tg: 'tg_TJ',
740
+ th: 'th_TH',
741
+ tr: 'tr_TR',
742
+ uk: 'uk_UA',
743
+ ur: 'ur_PK',
744
+ uz: 'uz_UZ',
745
+ vi: 'vi_VN',
746
+ yo: 'yo_NG',
747
+ zh: 'zh_CN',
748
+ zu: 'zu_ZA',
749
+ };
750
+
751
+ /**
752
+ * Gets the English language name for a given locale code.
753
+ *
754
+ * Handles multiple locale formats and normalizes them:
755
+ * - WordPress format: ru_RU, zh_CN, fr_FR
756
+ * - BCP 47 format: ru-RU, zh-CN, fr-FR
757
+ * - ISO codes: ru, zh, fr
758
+ * - GlotPress slugs: ru-ru, zh-cn, fr-fr
759
+ *
760
+ * @since 1.0.0
761
+ *
762
+ * @param {string} localeCode - The locale code to look up.
763
+ *
764
+ * @return {string} English language name, or the original code if not found.
765
+ */
766
+ export function getLanguageName(localeCode) {
767
+ if (!localeCode || typeof localeCode !== 'string') {
768
+ return localeCode;
769
+ }
770
+
771
+ // Try exact match first.
772
+ const exactMatch = LANGUAGE_MAPPING[localeCode];
773
+
774
+ if (exactMatch) {
775
+ return exactMatch;
776
+ }
777
+
778
+ // Normalize and try common variations.
779
+ const normalizedCode = localeCode.toLowerCase();
780
+
781
+ // Try normalized version.
782
+ const normalizedMatch = LANGUAGE_MAPPING[normalizedCode];
783
+
784
+ if (normalizedMatch) {
785
+ return normalizedMatch;
786
+ }
787
+
788
+ // Try converting between underscore and dash formats.
789
+ const alternateFormat = normalizedCode.includes('_') ? normalizedCode.replace('_', '-') : normalizedCode.replace('-', '_');
790
+ const alternateMatch = LANGUAGE_MAPPING[alternateFormat];
791
+
792
+ if (alternateMatch) {
793
+ return alternateMatch;
794
+ }
795
+
796
+ // Try just the language part (before _ or -.).
797
+ const langOnly = normalizedCode.split(/[_-]/)[0];
798
+ const langOnlyMatch = LANGUAGE_MAPPING[langOnly];
799
+
800
+ if (langOnlyMatch) {
801
+ return langOnlyMatch;
802
+ }
803
+
804
+ // Return original code if no match found.
805
+ return localeCode;
806
+ }
807
+
808
+ /**
809
+ * Checks if a locale code is supported in our language mapping.
810
+ *
811
+ * @since 1.0.0
812
+ *
813
+ * @param {string} localeCode - The locale code to check.
814
+ *
815
+ * @return {boolean} True if the locale is supported.
816
+ */
817
+ export function isLocaleSupported(localeCode) {
818
+ return getLanguageName(localeCode) !== localeCode;
819
+ }
820
+
821
+ /**
822
+ * Gets all supported locale codes.
823
+ *
824
+ * @since 1.0.0
825
+ *
826
+ * @return {Array<string>} Array of supported locale codes.
827
+ */
828
+ export function getSupportedLocales() {
829
+ return Object.keys(LANGUAGE_MAPPING);
830
+ }
831
+
832
+ /**
833
+ * Gets WordPress-specific locale mappings.
834
+ *
835
+ * @since 1.0.0
836
+ *
837
+ * @return {Object} WordPress locale mapping object.
838
+ */
839
+ export function getWordPressLocaleMapping() {
840
+ const wpMapping = {};
841
+
842
+ for (const [code, name] of Object.entries(LANGUAGE_MAPPING)) {
843
+ if (code.includes('_')) {
844
+ wpMapping[code] = name;
845
+ }
846
+ }
847
+
848
+ return wpMapping;
849
+ }
850
+
851
+ /**
852
+ * Normalizes a user-provided language input to a standard locale code.
853
+ * Handles various input formats like "Russian", "ru", "ru_RU" and returns
854
+ * the most appropriate locale code.
855
+ *
856
+ * @since 1.0.0
857
+ *
858
+ * @param {string} userInput - User-provided language input.
859
+ *
860
+ * @return {string} Normalized locale code (e.g., "ru_RU" for "Russian").
861
+ */
862
+ export function normalizeLanguageInput(userInput) {
863
+ if (!userInput || typeof userInput !== 'string') {
864
+ return userInput;
865
+ }
866
+
867
+ const input = userInput.trim();
868
+
869
+ // If it's already a valid locale code, return it.
870
+ if (LANGUAGE_MAPPING[input]) {
871
+ return input;
872
+ }
873
+
874
+ // Try case-insensitive lookup.
875
+ const lowerInput = input.toLowerCase();
876
+
877
+ if (LANGUAGE_MAPPING[lowerInput]) {
878
+ return lowerInput;
879
+ }
880
+
881
+ // Try converting between underscore and dash formats.
882
+ const alternateFormat = lowerInput.includes('_') ? lowerInput.replace('_', '-') : lowerInput.replace('-', '_');
883
+
884
+ if (LANGUAGE_MAPPING[alternateFormat]) {
885
+ return alternateFormat;
886
+ }
887
+
888
+ // Try to find by language name (case-insensitive.).
889
+ const inputLower = input.toLowerCase();
890
+
891
+ for (const [code, name] of Object.entries(LANGUAGE_MAPPING)) {
892
+ if (name.toLowerCase() === inputLower) {
893
+ // Prefer full locale codes (with underscore) over base language codes.
894
+ const fullLocaleCode = Object.keys(LANGUAGE_MAPPING).find((key) => key.includes('_') && LANGUAGE_MAPPING[key] === name);
895
+
896
+ return fullLocaleCode || code;
897
+ }
898
+ }
899
+
900
+ // Try partial matches for language names.
901
+ for (const [code, name] of Object.entries(LANGUAGE_MAPPING)) {
902
+ if (name.toLowerCase().includes(inputLower) || inputLower.includes(name.toLowerCase())) {
903
+ const fullLocaleCode = Object.keys(LANGUAGE_MAPPING).find((key) => key.includes('_') && LANGUAGE_MAPPING[key] === name);
904
+
905
+ return fullLocaleCode || code;
906
+ }
907
+ }
908
+
909
+ // If no match found, try to construct a reasonable default.
910
+ // If it looks like a base language code, try to find a default locale.
911
+ if (/^[a-z]{2}$/i.test(input)) {
912
+ const defaultLocale = DEFAULT_LOCALE_MAPPING[input.toLowerCase()];
913
+
914
+ if (defaultLocale) {
915
+ return defaultLocale;
916
+ }
917
+ }
918
+
919
+ // If no match found, return the original input.
920
+ return input;
921
+ }
922
+
923
+ /**
924
+ * Converts a locale code to different format types.
925
+ *
926
+ * @since 1.0.0
927
+ *
928
+ * @param {string} localeCode - The locale code to convert.
929
+ * @param {string} format - The desired format: 'wp_locale', 'iso_639_1', 'iso_639_2', 'target_lang'.
930
+ *
931
+ * @return {string} Converted locale code.
932
+ */
933
+ export function convertLocaleFormat(localeCode, format = 'target_lang') {
934
+ if (!localeCode || typeof localeCode !== 'string') {
935
+ return localeCode;
936
+ }
937
+
938
+ // Normalize the input first.
939
+ const normalizedCode = normalizeLanguageInput(localeCode);
940
+
941
+ // ISO 639-2 mapping for 3-letter language codes.
942
+ const iso639TwoMap = {
943
+ ru: 'rus',
944
+ fr: 'fra',
945
+ en: 'eng',
946
+ de: 'deu',
947
+ es: 'spa',
948
+ it: 'ita',
949
+ pt: 'por',
950
+ zh: 'zho',
951
+ ja: 'jpn',
952
+ ko: 'kor',
953
+ ar: 'ara',
954
+ hi: 'hin',
955
+ th: 'tha',
956
+ vi: 'vie',
957
+ tr: 'tur',
958
+ pl: 'pol',
959
+ nl: 'nld',
960
+ sv: 'swe',
961
+ da: 'dan',
962
+ no: 'nor',
963
+ fi: 'fin',
964
+ hu: 'hun',
965
+ cs: 'ces',
966
+ sk: 'slk',
967
+ sl: 'slv',
968
+ hr: 'hrv',
969
+ sr: 'srp',
970
+ bg: 'bul',
971
+ ro: 'ron',
972
+ uk: 'ukr',
973
+ be: 'bel',
974
+ lt: 'lit',
975
+ lv: 'lav',
976
+ et: 'est',
977
+ mt: 'mlt',
978
+ ga: 'gle',
979
+ cy: 'cym',
980
+ is: 'isl',
981
+ mk: 'mkd',
982
+ sq: 'sqi',
983
+ eu: 'eus',
984
+ ca: 'cat',
985
+ gl: 'glg',
986
+ he: 'heb',
987
+ fa: 'fas',
988
+ ur: 'urd',
989
+ bn: 'ben',
990
+ ta: 'tam',
991
+ te: 'tel',
992
+ ml: 'mal',
993
+ kn: 'kan',
994
+ gu: 'guj',
995
+ pa: 'pan',
996
+ or: 'ori',
997
+ as: 'asm',
998
+ ne: 'nep',
999
+ si: 'sin',
1000
+ my: 'mya',
1001
+ km: 'khm',
1002
+ lo: 'lao',
1003
+ ka: 'kat',
1004
+ hy: 'hye',
1005
+ az: 'aze',
1006
+ kk: 'kaz',
1007
+ ky: 'kir',
1008
+ uz: 'uzb',
1009
+ tg: 'tgk',
1010
+ mn: 'mon',
1011
+ bo: 'bod',
1012
+ dz: 'dzo',
1013
+ am: 'amh',
1014
+ ti: 'tir',
1015
+ om: 'orm',
1016
+ so: 'som',
1017
+ sw: 'swa',
1018
+ rw: 'kin',
1019
+ rn: 'run',
1020
+ ny: 'nya',
1021
+ mg: 'mlg',
1022
+ zu: 'zul',
1023
+ xh: 'xho',
1024
+ af: 'afr',
1025
+ st: 'sot',
1026
+ tn: 'tsn',
1027
+ ss: 'ssw',
1028
+ ve: 'ven',
1029
+ ts: 'tso',
1030
+ nr: 'nbl',
1031
+ };
1032
+
1033
+ switch (format) {
1034
+ case 'wp_locale': {
1035
+ // WordPress format: ru_RU, fr_FR, en_US.
1036
+ // If we have a full locale, use it; otherwise try to find one.
1037
+ if (normalizedCode.includes('_')) {
1038
+ return normalizedCode;
1039
+ }
1040
+ // Try to find a full locale for this language.
1041
+ const wpLocale = Object.keys(LANGUAGE_MAPPING).find((key) => key.includes('_') && key.startsWith(normalizedCode + '_'));
1042
+
1043
+ return wpLocale || normalizedCode + '_' + normalizedCode.toUpperCase();
1044
+ }
1045
+
1046
+ case 'iso_639_1': {
1047
+ // ISO 639-1: ru, fr, en (2-letter language codes.)
1048
+ return normalizedCode.split(/[_-]/)[0];
1049
+ }
1050
+
1051
+ case 'iso_639_2': {
1052
+ // ISO 639-2: rus, fra, eng (3-letter language codes.)
1053
+ // This is a simplified mapping - in practice you'd need a full ISO 639-2 table.
1054
+ const langCode = normalizedCode.split(/[_-]/)[0];
1055
+
1056
+ return iso639TwoMap[langCode] || langCode;
1057
+ }
1058
+
1059
+ case 'target_lang':
1060
+ default:
1061
+ // Default format: keep as-is (ru_RU, fr_FR, etc.)
1062
+ return normalizedCode;
1063
+ }
1064
+ }
1065
+
1066
+ /**
1067
+ * Gets the appropriate locale code for PO file headers.
1068
+ * This should be a BCP-47/RFC 5646 compliant code.
1069
+ *
1070
+ * @since 1.0.0
1071
+ *
1072
+ * @param {string} localeCode - The locale code to convert.
1073
+ *
1074
+ * @return {string} BCP-47 compliant locale code for PO headers.
1075
+ */
1076
+ export function getPoHeaderLocale(localeCode) {
1077
+ const normalized = normalizeLanguageInput(localeCode);
1078
+
1079
+ // Convert underscore to dash for BCP-47 compliance.
1080
+ return normalized.replace(/_/g, '-');
1081
+ }
1082
+
1083
+ /**
1084
+ * Gets the appropriate locale code for file naming based on the specified format.
1085
+ *
1086
+ * @since 1.0.0
1087
+ *
1088
+ * @param {string} localeCode - The locale code to convert/
1089
+ * @param {string} format - The desired format: 'wp_locale', 'iso_639_1', 'iso_639_2', 'target_lang'
1090
+ *
1091
+ * @return {string} Locale code for file naming
1092
+ */
1093
+ export function getFileNamingLocale(localeCode, format = 'target_lang') {
1094
+ return convertLocaleFormat(localeCode, format);
1095
+ }
1096
+
1097
+ /**
1098
+ * Gets the appropriate language name for API translation requests.
1099
+ * Returns the English language name which is more descriptive for AI models.
1100
+ *
1101
+ * @since 1.0.0
1102
+ *
1103
+ * @param {string} localeCode - The locale code to convert.
1104
+ *
1105
+ * @return {string} English language name for API requests.
1106
+ */
1107
+ export function getApiTargetLanguage(localeCode) {
1108
+ // First normalize the input to get a proper locale code.
1109
+ const normalizedCode = normalizeLanguageInput(localeCode);
1110
+
1111
+ // Then get the language name for that normalized code.
1112
+ return getLanguageName(normalizedCode);
1113
+ }