generaltranslation 2.0.54 → 2.0.56
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/{cjs/codes → codes}/codes.js +66 -63
- package/dist/{cjs/codes → codes}/getLanguageDirection.js +6 -6
- package/dist/index.js +228 -0
- package/dist/translation/_bundleTranslation.js +95 -0
- package/dist/translation/_intl.js +107 -0
- package/dist/translation/_translate.js +105 -0
- package/dist/translation/_translateReactChildren.js +107 -0
- package/dist/translation/_updateRemoteDictionary.js +83 -0
- package/package.json +7 -7
- package/dist/cjs/index.js +0 -162
- package/dist/cjs/translation/_bundleTranslation.js +0 -54
- package/dist/cjs/translation/_intl.js +0 -63
- package/dist/cjs/translation/_translate.js +0 -62
- package/dist/cjs/translation/_translateReactChildren.js +0 -67
- package/dist/cjs/translation/_updateRemoteDictionary.js +0 -41
- package/dist/mjs/codes/15924/CodeToScript.json +0 -215
- package/dist/mjs/codes/15924/ScriptToCode.json +0 -215
- package/dist/mjs/codes/3166/CodeToRegion.json +0 -296
- package/dist/mjs/codes/3166/RegionToCode.json +0 -296
- package/dist/mjs/codes/639-1/CodeToLanguage.json +0 -185
- package/dist/mjs/codes/639-1/LanguageToCode.json +0 -227
- package/dist/mjs/codes/639-3/CodeToLanguageTriletter.json +0 -186
- package/dist/mjs/codes/639-3/LanguageToCodeTriletter.json +0 -228
- package/dist/mjs/codes/codes.d.ts +0 -8
- package/dist/mjs/codes/codes.js +0 -306
- package/dist/mjs/codes/getLanguageDirection.d.ts +0 -1
- package/dist/mjs/codes/getLanguageDirection.js +0 -68
- package/dist/mjs/codes/predefined/Predefined.json +0 -28
- package/dist/mjs/index.d.ts +0 -153
- package/dist/mjs/index.js +0 -149
- package/dist/mjs/translation/_bundleTranslation.d.ts +0 -22
- package/dist/mjs/translation/_bundleTranslation.js +0 -51
- package/dist/mjs/translation/_intl.d.ts +0 -1
- package/dist/mjs/translation/_intl.js +0 -60
- package/dist/mjs/translation/_translate.d.ts +0 -1
- package/dist/mjs/translation/_translate.js +0 -59
- package/dist/mjs/translation/_translateReactChildren.d.ts +0 -1
- package/dist/mjs/translation/_translateReactChildren.js +0 -64
- package/dist/mjs/translation/_updateRemoteDictionary.d.ts +0 -17
- package/dist/mjs/translation/_updateRemoteDictionary.js +0 -38
- /package/dist/{cjs/codes → codes}/15924/CodeToScript.json +0 -0
- /package/dist/{cjs/codes → codes}/15924/ScriptToCode.json +0 -0
- /package/dist/{cjs/codes → codes}/3166/CodeToRegion.json +0 -0
- /package/dist/{cjs/codes → codes}/3166/RegionToCode.json +0 -0
- /package/dist/{cjs/codes → codes}/639-1/CodeToLanguage.json +0 -0
- /package/dist/{cjs/codes → codes}/639-1/LanguageToCode.json +0 -0
- /package/dist/{cjs/codes → codes}/639-3/CodeToLanguageTriletter.json +0 -0
- /package/dist/{cjs/codes → codes}/639-3/LanguageToCodeTriletter.json +0 -0
- /package/dist/{cjs/codes → codes}/codes.d.ts +0 -0
- /package/dist/{cjs/codes → codes}/getLanguageDirection.d.ts +0 -0
- /package/dist/{cjs/codes → codes}/predefined/Predefined.json +0 -0
- /package/dist/{cjs/index.d.ts → index.d.ts} +0 -0
- /package/dist/{cjs/translation → translation}/_bundleTranslation.d.ts +0 -0
- /package/dist/{cjs/translation → translation}/_intl.d.ts +0 -0
- /package/dist/{cjs/translation → translation}/_translate.d.ts +0 -0
- /package/dist/{cjs/translation → translation}/_translateReactChildren.d.ts +0 -0
- /package/dist/{cjs/translation → translation}/_updateRemoteDictionary.d.ts +0 -0
@@ -1,228 +0,0 @@
|
|
1
|
-
{
|
2
|
-
"abkhazian": "abk",
|
3
|
-
"afar": "aar",
|
4
|
-
"afrikaans": "afr",
|
5
|
-
"akan": "aka",
|
6
|
-
"albanian": "sqi",
|
7
|
-
"amharic": "amh",
|
8
|
-
"ancient greek": "grc",
|
9
|
-
"arabic": "ara",
|
10
|
-
"aragonese": "arg",
|
11
|
-
"armenian": "hye",
|
12
|
-
"assamese": "asm",
|
13
|
-
"avaric": "ava",
|
14
|
-
"avestan": "ave",
|
15
|
-
"aymara": "aym",
|
16
|
-
"azerbaijani": "aze",
|
17
|
-
"bambara": "bam",
|
18
|
-
"bashkir": "bak",
|
19
|
-
"basque": "eus",
|
20
|
-
"belarusian": "bel",
|
21
|
-
"bengali": "ben",
|
22
|
-
"bislama": "bis",
|
23
|
-
"bosnian": "bos",
|
24
|
-
"breton": "bre",
|
25
|
-
"bulgarian": "bul",
|
26
|
-
"burmese": "mya",
|
27
|
-
"catalan": "cat",
|
28
|
-
"valencian": "cat",
|
29
|
-
"chamorro": "cha",
|
30
|
-
"chechen": "che",
|
31
|
-
"chichewa": "nya",
|
32
|
-
"chewa": "nya",
|
33
|
-
"nyanja": "nya",
|
34
|
-
"chinese": "zho",
|
35
|
-
"mandarin": "zho",
|
36
|
-
"church slavonic": "chu",
|
37
|
-
"old slavonic": "chu",
|
38
|
-
"old church slavonic": "chu",
|
39
|
-
"slavonic": "chu",
|
40
|
-
"chuvash": "chv",
|
41
|
-
"cornish": "cor",
|
42
|
-
"corsican": "cos",
|
43
|
-
"cree": "cre",
|
44
|
-
"croatian": "hrv",
|
45
|
-
"czech": "ces",
|
46
|
-
"danish": "dan",
|
47
|
-
"divehi": "div",
|
48
|
-
"dhivehi": "div",
|
49
|
-
"maldivian": "div",
|
50
|
-
"dutch": "nld",
|
51
|
-
"flemish": "nld",
|
52
|
-
"dzongkha": "dzo",
|
53
|
-
"english": "eng",
|
54
|
-
"esperanto": "epo",
|
55
|
-
"estonian": "est",
|
56
|
-
"ewe": "ewe",
|
57
|
-
"faroese": "fao",
|
58
|
-
"fijian": "fij",
|
59
|
-
"finnish": "fin",
|
60
|
-
"french": "fra",
|
61
|
-
"western frisian": "fry",
|
62
|
-
"frisian": "fry",
|
63
|
-
"fulah": "ful",
|
64
|
-
"gaelic": "gla",
|
65
|
-
"scottish gaelic": "gla",
|
66
|
-
"galician": "glg",
|
67
|
-
"ganda": "lug",
|
68
|
-
"georgian": "kat",
|
69
|
-
"german": "deu",
|
70
|
-
"greek": "ell",
|
71
|
-
"modern greek": "ell",
|
72
|
-
"kalaallisut": "kal",
|
73
|
-
"greenlandic": "kal",
|
74
|
-
"guarani": "grn",
|
75
|
-
"gujarati": "guj",
|
76
|
-
"haitian": "hat",
|
77
|
-
"haitian creole": "hat",
|
78
|
-
"hausa": "hau",
|
79
|
-
"hebrew": "heb",
|
80
|
-
"herero": "her",
|
81
|
-
"hindi": "hin",
|
82
|
-
"hiri motu": "hmo",
|
83
|
-
"hungarian": "hun",
|
84
|
-
"icelandic": "isl",
|
85
|
-
"ido": "ido",
|
86
|
-
"igbo": "ibo",
|
87
|
-
"indonesian": "ind",
|
88
|
-
"interlingua": "ina",
|
89
|
-
"interlingue": "ile",
|
90
|
-
"occidental": "ile",
|
91
|
-
"inuktitut": "iku",
|
92
|
-
"inupiaq": "ipk",
|
93
|
-
"irish": "gle",
|
94
|
-
"italian": "ita",
|
95
|
-
"japanese": "jpn",
|
96
|
-
"javanese": "jav",
|
97
|
-
"kannada": "kan",
|
98
|
-
"kanuri": "kau",
|
99
|
-
"kashmiri": "kas",
|
100
|
-
"kazakh": "kaz",
|
101
|
-
"central khmer": "khm",
|
102
|
-
"kikuyu": "kik",
|
103
|
-
"gikuyu": "kik",
|
104
|
-
"kinyarwanda": "kin",
|
105
|
-
"kirghiz": "kir",
|
106
|
-
"kyrgyz": "kir",
|
107
|
-
"komi": "kom",
|
108
|
-
"kongo": "kon",
|
109
|
-
"korean": "kor",
|
110
|
-
"kuanyama": "kua",
|
111
|
-
"kwanyama": "kua",
|
112
|
-
"kurdish": "kur",
|
113
|
-
"lao": "lao",
|
114
|
-
"latin": "lat",
|
115
|
-
"latvian": "lav",
|
116
|
-
"limburgan": "lim",
|
117
|
-
"limburger": "lim",
|
118
|
-
"limburgish": "lim",
|
119
|
-
"lingala": "lin",
|
120
|
-
"lithuanian": "lit",
|
121
|
-
"luba-katanga": "lub",
|
122
|
-
"luxembourgish": "ltz",
|
123
|
-
"letzeburgesch": "ltz",
|
124
|
-
"macedonian": "mkd",
|
125
|
-
"malagasy": "mlg",
|
126
|
-
"malay": "msa",
|
127
|
-
"malayalam": "mal",
|
128
|
-
"maltese": "mlt",
|
129
|
-
"manx": "glv",
|
130
|
-
"maori": "mri",
|
131
|
-
"marathi": "mar",
|
132
|
-
"marshallese": "mah",
|
133
|
-
"mongolian": "mon",
|
134
|
-
"nauru": "nau",
|
135
|
-
"navajo": "nav",
|
136
|
-
"navaho": "nav",
|
137
|
-
"north ndebele": "nde",
|
138
|
-
"south ndebele": "nbl",
|
139
|
-
"northern ndebele": "nde",
|
140
|
-
"southern ndebele": "nbl",
|
141
|
-
"ndonga": "ndo",
|
142
|
-
"nepali": "nep",
|
143
|
-
"norwegian": "nor",
|
144
|
-
"norwegian bokmål": "nob",
|
145
|
-
"norwegian nynorsk": "nno",
|
146
|
-
"sichuan yi": "iii",
|
147
|
-
"nuosu": "iii",
|
148
|
-
"occitan": "oci",
|
149
|
-
"ojibwa": "oji",
|
150
|
-
"ojibwe": "oji",
|
151
|
-
"oriya": "ori",
|
152
|
-
"odia": "ori",
|
153
|
-
"oromo": "orm",
|
154
|
-
"ossetian": "oss",
|
155
|
-
"ossetic": "oss",
|
156
|
-
"pali": "pli",
|
157
|
-
"pashto": "pus",
|
158
|
-
"pushto": "pus",
|
159
|
-
"persian": "fas",
|
160
|
-
"polish": "pol",
|
161
|
-
"portuguese": "por",
|
162
|
-
"punjabi": "pan",
|
163
|
-
"panjabi": "pan",
|
164
|
-
"quechua": "que",
|
165
|
-
"romanian": "ron",
|
166
|
-
"moldavian": "ron",
|
167
|
-
"moldovan": "ron",
|
168
|
-
"romansh": "roh",
|
169
|
-
"rundi": "run",
|
170
|
-
"kirundi": "run",
|
171
|
-
"russian": "rus",
|
172
|
-
"northern sami": "sme",
|
173
|
-
"sami": "sme",
|
174
|
-
"samoan": "smo",
|
175
|
-
"sango": "sag",
|
176
|
-
"sanskrit": "san",
|
177
|
-
"sardinian": "srd",
|
178
|
-
"serbian": "srp",
|
179
|
-
"shona": "sna",
|
180
|
-
"sindhi": "snd",
|
181
|
-
"sinhala": "sin",
|
182
|
-
"sinhalese": "sin",
|
183
|
-
"slovak": "slk",
|
184
|
-
"slovenian": "slv",
|
185
|
-
"slovene": "slv",
|
186
|
-
"somali": "som",
|
187
|
-
"southern sotho": "sot",
|
188
|
-
"sotho": "sot",
|
189
|
-
"spanish": "spa",
|
190
|
-
"castilian": "spa",
|
191
|
-
"sundanese": "sun",
|
192
|
-
"swahili": "swa",
|
193
|
-
"swati": "ssw",
|
194
|
-
"swedish": "swe",
|
195
|
-
"tagalog": "tgl",
|
196
|
-
"tahitian": "tah",
|
197
|
-
"tajik": "tgk",
|
198
|
-
"tamil": "tam",
|
199
|
-
"tatar": "tat",
|
200
|
-
"telugu": "tel",
|
201
|
-
"thai": "tha",
|
202
|
-
"tibetan": "bod",
|
203
|
-
"tigrinya": "tir",
|
204
|
-
"tonga": "ton",
|
205
|
-
"tongan": "ton",
|
206
|
-
"tsonga": "tso",
|
207
|
-
"tswana": "tsn",
|
208
|
-
"turkish": "tur",
|
209
|
-
"turkmen": "tuk",
|
210
|
-
"twi": "twi",
|
211
|
-
"uighur": "uig",
|
212
|
-
"uyghur": "uig",
|
213
|
-
"ukrainian": "ukr",
|
214
|
-
"urdu": "urd",
|
215
|
-
"uzbek": "uzb",
|
216
|
-
"venda": "ven",
|
217
|
-
"vietnamese": "vie",
|
218
|
-
"volapük": "vol",
|
219
|
-
"walloon": "wln",
|
220
|
-
"welsh": "cym",
|
221
|
-
"wolof": "wol",
|
222
|
-
"xhosa": "xho",
|
223
|
-
"yiddish": "yid",
|
224
|
-
"yoruba": "yor",
|
225
|
-
"zhuang": "zha",
|
226
|
-
"chuang": "zha",
|
227
|
-
"zulu": "zul"
|
228
|
-
}
|
package/dist/mjs/codes/codes.js
DELETED
@@ -1,306 +0,0 @@
|
|
1
|
-
// ----- IMPORTS ----- //
|
2
|
-
// Import modules for mapping ISO 639 codes to language names and vice versa
|
3
|
-
import CodeToLanguageJSON from './639-1/CodeToLanguage.json';
|
4
|
-
import LanguageToCodeJSON from './639-1/LanguageToCode.json';
|
5
|
-
const CodeToLanguage = CodeToLanguageJSON;
|
6
|
-
const LanguageToCode = LanguageToCodeJSON;
|
7
|
-
// Import modules for mapping ISO 639-3 codes (for languages without two-letter codes)
|
8
|
-
import CodeToLanguageTriletterJSON from './639-3/CodeToLanguageTriletter.json';
|
9
|
-
import LanguageToCodeTriletterJSON from './639-3/LanguageToCodeTriletter.json';
|
10
|
-
const CodeToLanguageTriletter = CodeToLanguageTriletterJSON;
|
11
|
-
const LanguageToCodeTriletter = LanguageToCodeTriletterJSON;
|
12
|
-
// Import module for mapping ISO 15924 script codes to script names
|
13
|
-
import ScriptToCodeJSON from './15924/ScriptToCode.json';
|
14
|
-
import CodeToScriptJSON from './15924/CodeToScript.json';
|
15
|
-
const ScriptToCode = ScriptToCodeJSON;
|
16
|
-
const CodeToScript = CodeToScriptJSON;
|
17
|
-
// Import module for mapping ISO 3166 region codes to region names
|
18
|
-
import RegionToCodeJSON from './3166/RegionToCode.json';
|
19
|
-
import CodeToRegionJSON from './3166/CodeToRegion.json';
|
20
|
-
const RegionToCode = RegionToCodeJSON;
|
21
|
-
const CodeToRegion = CodeToRegionJSON;
|
22
|
-
// Import predefined common regions
|
23
|
-
import PredefinedJSON from './predefined/Predefined.json';
|
24
|
-
import { isValidLanguageCode } from 'generaltranslation';
|
25
|
-
const Predefined = PredefinedJSON;
|
26
|
-
// ----- VALIDITY CHECKS ----- //
|
27
|
-
/**
|
28
|
-
* Ensures correct capitalization and formatting of a language code.
|
29
|
-
* @param {string} code - The language-country-script code to standardize.
|
30
|
-
* @returns {string} A BCP 47 language tag.
|
31
|
-
* @internal
|
32
|
-
*/
|
33
|
-
export function _standardizeLanguageCode(code) {
|
34
|
-
if (!isValidLanguageCode(code))
|
35
|
-
return '';
|
36
|
-
const codeParts = code.split('-');
|
37
|
-
let result = `${codeParts[0].toLowerCase()}`;
|
38
|
-
if (codeParts[1]) {
|
39
|
-
if (codeParts[1].length === 4) {
|
40
|
-
result += `-${_capitalize(codeParts[1])}`;
|
41
|
-
if (codeParts[2] && codeParts[2].length === 2) {
|
42
|
-
result += `-${codeParts[2].toUpperCase()}`;
|
43
|
-
}
|
44
|
-
}
|
45
|
-
else if (codeParts[1].length === 2) {
|
46
|
-
result += `-${codeParts[1].toUpperCase()}`;
|
47
|
-
}
|
48
|
-
}
|
49
|
-
return result;
|
50
|
-
}
|
51
|
-
/**
|
52
|
-
* Check if a given language-country-script code is valid.
|
53
|
-
* @param {string} code - The language-country-script code to validate.
|
54
|
-
* @returns {boolean} - Returns true if valid, false otherwise.
|
55
|
-
* @internal
|
56
|
-
*/
|
57
|
-
export function _isValidLanguageCode(code) {
|
58
|
-
if (!code || typeof code !== 'string')
|
59
|
-
return false;
|
60
|
-
const codeParts = code.split('-');
|
61
|
-
if (!_mapCodeToLanguage(codeParts[0]))
|
62
|
-
return false;
|
63
|
-
if (codeParts[1]) {
|
64
|
-
if (codeParts[1].length === 4) {
|
65
|
-
if (!_mapCodeToScript(codeParts[1]))
|
66
|
-
return false;
|
67
|
-
if (codeParts[2] && codeParts[2].length === 2) {
|
68
|
-
if (!_mapCodeToRegion(codeParts[2]))
|
69
|
-
return false;
|
70
|
-
}
|
71
|
-
}
|
72
|
-
else if (codeParts[1].length === 2) {
|
73
|
-
if (!_mapCodeToRegion(codeParts[1]))
|
74
|
-
return false;
|
75
|
-
}
|
76
|
-
}
|
77
|
-
return true;
|
78
|
-
}
|
79
|
-
// ----- FORMATTING HELPER FUNCTIONS ----- //
|
80
|
-
/**
|
81
|
-
* Capitalizes the first letter of a code and converts the rest to lowercase.
|
82
|
-
* @param {string} code - The code to capitalize.
|
83
|
-
* @returns {string} The capitalized code.
|
84
|
-
*/
|
85
|
-
const _capitalize = (code) => {
|
86
|
-
if (code.length === 0)
|
87
|
-
return code;
|
88
|
-
return code.charAt(0).toUpperCase() + code.slice(1).toLowerCase();
|
89
|
-
};
|
90
|
-
// ----- MAPPING FUNCTIONS ----- //
|
91
|
-
/**
|
92
|
-
* Returns the name of a language from an ISO 639 code.
|
93
|
-
* @param {string} code - The ISO 639 code.
|
94
|
-
* @returns {string} The language name.
|
95
|
-
*/
|
96
|
-
const _mapCodeToLanguage = (code) => {
|
97
|
-
code = code === null || code === void 0 ? void 0 : code.toLowerCase();
|
98
|
-
if ((code === null || code === void 0 ? void 0 : code.length) === 2) {
|
99
|
-
return CodeToLanguage[code];
|
100
|
-
}
|
101
|
-
if ((code === null || code === void 0 ? void 0 : code.length) === 3) {
|
102
|
-
return CodeToLanguageTriletter[code];
|
103
|
-
}
|
104
|
-
return '';
|
105
|
-
};
|
106
|
-
/**
|
107
|
-
* Returns a BCP 47 language tag from a language name.
|
108
|
-
* Preferentially returns two-letter codes.
|
109
|
-
* @param {string} language - The language name.
|
110
|
-
* @returns {string} BCP 47 language tag.
|
111
|
-
*/
|
112
|
-
const _mapLanguageToCode = (language) => {
|
113
|
-
language = language === null || language === void 0 ? void 0 : language.toLowerCase();
|
114
|
-
return LanguageToCode[language] || LanguageToCodeTriletter[language] || '';
|
115
|
-
};
|
116
|
-
/**
|
117
|
-
* Returns the name of a script from an ISO 15924 code.
|
118
|
-
* @param {string} code - The ISO 15924 code.
|
119
|
-
* @returns {string} The script name.
|
120
|
-
*/
|
121
|
-
const _mapCodeToScript = (code) => {
|
122
|
-
code = _capitalize(code);
|
123
|
-
return CodeToScript[code] || '';
|
124
|
-
};
|
125
|
-
/**
|
126
|
-
* Returns an ISO 15924 code from a script name.
|
127
|
-
* @param {string} script - The script name.
|
128
|
-
* @returns {string} The ISO 15924 code.
|
129
|
-
*/
|
130
|
-
const _mapScriptToCode = (script) => {
|
131
|
-
script = script === null || script === void 0 ? void 0 : script.toLowerCase();
|
132
|
-
return ScriptToCode[script] || '';
|
133
|
-
};
|
134
|
-
/**
|
135
|
-
* Returns the name of a region from an ISO 3166 code.
|
136
|
-
* @param {string} code - The ISO 3166 code.
|
137
|
-
* @returns {string} The region name.
|
138
|
-
*/
|
139
|
-
const _mapCodeToRegion = (code) => {
|
140
|
-
code = code === null || code === void 0 ? void 0 : code.toUpperCase();
|
141
|
-
return CodeToRegion[code] || '';
|
142
|
-
};
|
143
|
-
/**
|
144
|
-
* Returns an ISO 3166 code from a region name.
|
145
|
-
* @param {string} region - The region name.
|
146
|
-
* @returns {string} The ISO 3166 code.
|
147
|
-
*/
|
148
|
-
const _mapRegionToCode = (region) => {
|
149
|
-
region = region === null || region === void 0 ? void 0 : region.toLowerCase();
|
150
|
-
return RegionToCode[region] || '';
|
151
|
-
};
|
152
|
-
/**
|
153
|
-
* @internal
|
154
|
-
*/
|
155
|
-
export function _getLanguageObject(codes) {
|
156
|
-
return Array.isArray(codes) ? codes.map(_handleGetLanguageObject) : _handleGetLanguageObject(codes);
|
157
|
-
}
|
158
|
-
/**
|
159
|
-
* Helper function to create a language object from a code.
|
160
|
-
* @param {string} code - The language code.
|
161
|
-
* @returns {LanguageObject|null} The language object.
|
162
|
-
*/
|
163
|
-
const _handleGetLanguageObject = (code) => {
|
164
|
-
if (!isValidLanguageCode(code))
|
165
|
-
return null;
|
166
|
-
const codeParts = code.split('-');
|
167
|
-
let languageObject = {
|
168
|
-
language: _mapCodeToLanguage(codeParts[0]),
|
169
|
-
};
|
170
|
-
if (codeParts[1]) {
|
171
|
-
if (codeParts[1].length === 4) {
|
172
|
-
languageObject.script = _mapCodeToScript(codeParts[1]);
|
173
|
-
if (codeParts[2] && codeParts[2].length === 2) {
|
174
|
-
languageObject.region = _mapCodeToRegion(codeParts[2]);
|
175
|
-
}
|
176
|
-
}
|
177
|
-
else if (codeParts[1].length === 2) {
|
178
|
-
languageObject.region = _mapCodeToRegion(codeParts[1]);
|
179
|
-
}
|
180
|
-
}
|
181
|
-
return languageObject;
|
182
|
-
};
|
183
|
-
// ----- LANGUAGE NAMES FROM CODES ----- //
|
184
|
-
/**
|
185
|
-
* Returns the language name(s) from an array of codes or a single code.
|
186
|
-
* @param {string|string[]} codes - The code or array of codes.
|
187
|
-
* @returns {string|string[]} The language name(s).
|
188
|
-
* @internal
|
189
|
-
*/
|
190
|
-
export const _getLanguageName = (codes) => {
|
191
|
-
return Array.isArray(codes) ? codes.map(_handleGetLanguageName) : _handleGetLanguageName(codes);
|
192
|
-
};
|
193
|
-
/**
|
194
|
-
* Helper function to get the language name from a code.
|
195
|
-
* @param {string} code - The language code.
|
196
|
-
* @returns {string} The language name.
|
197
|
-
*/
|
198
|
-
const _handleGetLanguageName = (code) => {
|
199
|
-
if (!_isValidLanguageCode(code))
|
200
|
-
return '';
|
201
|
-
if (Predefined[code])
|
202
|
-
return Predefined[code];
|
203
|
-
const languageObject = _handleGetLanguageObject(code);
|
204
|
-
if (!languageObject)
|
205
|
-
return '';
|
206
|
-
let result = languageObject.language;
|
207
|
-
if (languageObject.script) {
|
208
|
-
result += `, ${languageObject.script}`;
|
209
|
-
}
|
210
|
-
if (languageObject.region) {
|
211
|
-
result += `, ${languageObject.region}`;
|
212
|
-
}
|
213
|
-
return result;
|
214
|
-
};
|
215
|
-
// ----- LANGUAGE CODES FROM NAMES ----- //
|
216
|
-
/**
|
217
|
-
* Returns the language code(s) from an array of language names or a single name.
|
218
|
-
* @param {string|string[]} languages - The language name or array of language names.
|
219
|
-
* @returns {string|string[]} The language code(s).
|
220
|
-
* @internal
|
221
|
-
*/
|
222
|
-
export const _getLanguageCode = (languages) => {
|
223
|
-
return Array.isArray(languages) ? languages.map(_handleGetLanguageCode) : _handleGetLanguageCode(languages);
|
224
|
-
};
|
225
|
-
/**
|
226
|
-
* Helper function to get the language code from a language name.
|
227
|
-
* @param {string|LanguageObject} language - The language name or object.
|
228
|
-
* @returns {string} The language code.
|
229
|
-
*/
|
230
|
-
const _handleGetLanguageCode = (language) => {
|
231
|
-
if (typeof language === 'string')
|
232
|
-
return _handleGetLanguageCodeFromString(language);
|
233
|
-
return _handleGetLanguageCodeFromObject(language);
|
234
|
-
};
|
235
|
-
/**
|
236
|
-
* Helper function to get the language code from a language name string.
|
237
|
-
* @param {string} language - The language name.
|
238
|
-
* @returns {string} The language code.
|
239
|
-
*/
|
240
|
-
const _handleGetLanguageCodeFromString = (language) => {
|
241
|
-
const subtagStrings = language.split(',').map(string => string.trim());
|
242
|
-
let code = _mapLanguageToCode(subtagStrings[0]);
|
243
|
-
if (code) {
|
244
|
-
if (subtagStrings.length === 3) {
|
245
|
-
code += `-${_mapScriptToCode(subtagStrings[1])}`;
|
246
|
-
code += `-${_mapRegionToCode(subtagStrings[2])}`;
|
247
|
-
}
|
248
|
-
else if (subtagStrings.length === 2) {
|
249
|
-
let tag = _mapScriptToCode(subtagStrings[1]);
|
250
|
-
if (!tag)
|
251
|
-
tag = _mapRegionToCode(subtagStrings[1]);
|
252
|
-
if (tag)
|
253
|
-
code += `-${tag}`;
|
254
|
-
}
|
255
|
-
}
|
256
|
-
if (!code) {
|
257
|
-
for (const key in Predefined) {
|
258
|
-
if (Predefined[key] === language) {
|
259
|
-
return key;
|
260
|
-
}
|
261
|
-
}
|
262
|
-
}
|
263
|
-
return code;
|
264
|
-
};
|
265
|
-
/**
|
266
|
-
* Helper function to get the language code from a language object.
|
267
|
-
* @param {LanguageObject} languageObject - The language object.
|
268
|
-
* @returns {string} The language code.
|
269
|
-
*/
|
270
|
-
const _handleGetLanguageCodeFromObject = (languageObject) => {
|
271
|
-
if (!(languageObject === null || languageObject === void 0 ? void 0 : languageObject.language))
|
272
|
-
return '';
|
273
|
-
let code = languageObject.language.toLowerCase();
|
274
|
-
if (languageObject.script) {
|
275
|
-
code += `-${_capitalize(languageObject.script)}`;
|
276
|
-
}
|
277
|
-
if (languageObject.region) {
|
278
|
-
code += `-${languageObject.region.toUpperCase()}`;
|
279
|
-
}
|
280
|
-
return _isValidLanguageCode(code) ? code : '';
|
281
|
-
};
|
282
|
-
/**
|
283
|
-
* @internal
|
284
|
-
*/
|
285
|
-
export function _isSameLanguage(...codes) {
|
286
|
-
// Flatten the array in case the codes are provided as an array
|
287
|
-
if (codes.length === 1 && Array.isArray(codes[0])) {
|
288
|
-
codes = codes[0];
|
289
|
-
}
|
290
|
-
if (codes.length < 2)
|
291
|
-
return false;
|
292
|
-
let language = null;
|
293
|
-
for (let i = 0; i < codes.length; i++) {
|
294
|
-
if (typeof codes[i] !== 'string')
|
295
|
-
return false;
|
296
|
-
const languageCode = codes[i].split('-')[0];
|
297
|
-
const currentLanguage = _mapCodeToLanguage(languageCode);
|
298
|
-
if (language === null) {
|
299
|
-
language = currentLanguage;
|
300
|
-
}
|
301
|
-
else if (language !== currentLanguage) {
|
302
|
-
return false;
|
303
|
-
}
|
304
|
-
}
|
305
|
-
return true;
|
306
|
-
}
|
@@ -1 +0,0 @@
|
|
1
|
-
export {};
|
@@ -1,68 +0,0 @@
|
|
1
|
-
/* ----- BEGIN YAHOO COPYRIGHT ----- */
|
2
|
-
/*
|
3
|
-
|
4
|
-
Copyright 2015 Yahoo Inc. All rights reserved.
|
5
|
-
|
6
|
-
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
7
|
-
|
8
|
-
* Redistributions of source code must retain the above copyright
|
9
|
-
notice, this list of conditions and the following disclaimer.
|
10
|
-
|
11
|
-
* Redistributions in binary form must reproduce the above copyright
|
12
|
-
notice, this list of conditions and the following disclaimer in the
|
13
|
-
documentation and/or other materials provided with the distribution.
|
14
|
-
|
15
|
-
* Neither the name of the Yahoo Inc. nor the
|
16
|
-
names of its contributors may be used to endorse or promote products
|
17
|
-
derived from this software without specific prior written permission.
|
18
|
-
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL YAHOO! INC. BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
19
|
-
|
20
|
-
*/
|
21
|
-
/**
|
22
|
-
* List of languages that are written from right to left.
|
23
|
-
* Each entry contains the language code and the language name.
|
24
|
-
*
|
25
|
-
* @type {string[]}
|
26
|
-
*/
|
27
|
-
const rtlLanguages = [
|
28
|
-
'ae', /* Avestan */
|
29
|
-
'ar', /* 'العربية', Arabic */
|
30
|
-
'arc', /* Aramaic */
|
31
|
-
'bcc', /* 'بلوچی مکرانی', Southern Balochi */
|
32
|
-
'bqi', /* 'بختياري', Bakthiari */
|
33
|
-
'ckb', /* 'Soranî / کوردی', Sorani */
|
34
|
-
'dv', /* Dhivehi */
|
35
|
-
'fa', /* 'فارسی', Persian */
|
36
|
-
'glk', /* 'گیلکی', Gilaki */
|
37
|
-
'he', /* 'עברית', Hebrew */
|
38
|
-
'ku', /* 'Kurdî / كوردی', Kurdish */
|
39
|
-
'mzn', /* 'مازِرونی', Mazanderani */
|
40
|
-
'nqo', /* N'Ko */
|
41
|
-
'pnb', /* 'پنجابی', Western Punjabi */
|
42
|
-
'prs', /* 'دری', Darī */
|
43
|
-
'ps', /* 'پښتو', Pashto, */
|
44
|
-
'sd', /* 'سنڌي', Sindhi */
|
45
|
-
'ug', /* 'Uyghurche / ئۇيغۇرچە', Uyghur */
|
46
|
-
'ur', /* 'اردو', Urdu */
|
47
|
-
'yi' /* 'ייִדיש', Yiddish */
|
48
|
-
];
|
49
|
-
/* ----- END YAHOO COPYRIGHT ----- */
|
50
|
-
import { _getLanguageObject, _isSameLanguage } from "./codes";
|
51
|
-
/**
|
52
|
-
* Get the text direction for a given language code.
|
53
|
-
*
|
54
|
-
* @param {string} code - The language code to check.
|
55
|
-
* @returns {string} - 'rtl' if the language is right-to-left, otherwise 'ltr'.
|
56
|
-
* @internal
|
57
|
-
*/
|
58
|
-
export default function _getLanguageDirection(code) {
|
59
|
-
return rtlLanguages.some(language => {
|
60
|
-
const lo = _getLanguageObject(language);
|
61
|
-
const clo = _getLanguageObject(code);
|
62
|
-
if (!lo || !clo)
|
63
|
-
return false;
|
64
|
-
if (lo.script && clo.script && lo.script !== clo.script)
|
65
|
-
return false;
|
66
|
-
return _isSameLanguage(code, language);
|
67
|
-
}) ? 'rtl' : 'ltr';
|
68
|
-
}
|
@@ -1,28 +0,0 @@
|
|
1
|
-
{
|
2
|
-
"en-US": "English",
|
3
|
-
"en-GB": "British English",
|
4
|
-
"en-CA": "Canadian English",
|
5
|
-
"en-AU": "Australian English",
|
6
|
-
"es-ES": "Spanish",
|
7
|
-
"es-MX": "Mexican Spanish",
|
8
|
-
"es-AR": "Argentinian Spanish",
|
9
|
-
"es-CO": "Colombian Spanish",
|
10
|
-
"fr-FR": "French",
|
11
|
-
"fr-CA": "Canadian French",
|
12
|
-
"fr-BE": "Belgian French",
|
13
|
-
"fr-CH": "Swiss French",
|
14
|
-
"zh-CN": "Mandarin Chinese",
|
15
|
-
"zh-TW": "Traditional Chinese",
|
16
|
-
"zh-HK": "Hong Kong Chinese",
|
17
|
-
"pt-PT": "Portuguese",
|
18
|
-
"pt-BR": "Brazilian Portuguese",
|
19
|
-
"de-DE": "German",
|
20
|
-
"de-AT": "Austrian German",
|
21
|
-
"de-CH": "Swiss German",
|
22
|
-
"ar-SA": "Saudi Arabic",
|
23
|
-
"ar-EG": "Egyptian Arabic",
|
24
|
-
"ar-AE": "Emirati Arabic",
|
25
|
-
"ar-MA": "Moroccan Arabic",
|
26
|
-
"nl-BE": "Belgian Dutch",
|
27
|
-
"it-CH": "Swiss Italian"
|
28
|
-
}
|