generaltranslation 1.3.3 → 2.0.1

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.
@@ -1,4 +1,4 @@
1
- const CodeToScript = {
1
+ {
2
2
  "Adlm": "Adlam",
3
3
  "Afak": "Afaka",
4
4
  "Aghb": "Caucasian Albanian",
@@ -213,4 +213,3 @@ const CodeToScript = {
213
213
  "Yiii": "Yi",
214
214
  "Zanb": "Zanabazar Square"
215
215
  }
216
- module.exports = CodeToScript;
@@ -1,4 +1,4 @@
1
- const ScriptToCode = {
1
+ {
2
2
  "adlam": "Adlm",
3
3
  "afaka": "Afak",
4
4
  "caucasian albanian": "Aghb",
@@ -213,4 +213,3 @@ const ScriptToCode = {
213
213
  "yi": "Yiii",
214
214
  "zanabazar square": "Zanb"
215
215
  }
216
- module.exports = ScriptToCode;
@@ -0,0 +1,296 @@
1
+ {
2
+ "AC": "Ascension Island",
3
+ "AD": "Andorra",
4
+ "AE": "United Arab Emirates",
5
+ "AF": "Afghanistan",
6
+ "AG": "Antigua and Barbuda",
7
+ "AI": "Anguilla",
8
+ "AL": "Albania",
9
+ "AM": "Armenia",
10
+ "AN": "Netherlands Antilles",
11
+ "AO": "Angola",
12
+ "AQ": "Antarctica",
13
+ "AR": "Argentina",
14
+ "AS": "American Samoa",
15
+ "AT": "Austria",
16
+ "AU": "Australia",
17
+ "AW": "Aruba",
18
+ "AX": "Åland Islands",
19
+ "AZ": "Azerbaijan",
20
+ "BA": "Bosnia and Herzegovina",
21
+ "BB": "Barbados",
22
+ "BD": "Bangladesh",
23
+ "BE": "Belgium",
24
+ "BF": "Burkina Faso",
25
+ "BG": "Bulgaria",
26
+ "BH": "Bahrain",
27
+ "BI": "Burundi",
28
+ "BJ": "Benin",
29
+ "BL": "Saint Barthélemy",
30
+ "BM": "Bermuda",
31
+ "BN": "Brunei Darussalam",
32
+ "BO": "Bolivia",
33
+ "BQ": "Bonaire, Sint Eustatius and Saba",
34
+ "BR": "Brazil",
35
+ "BS": "Bahamas",
36
+ "BT": "Bhutan",
37
+ "BV": "Bouvet Island",
38
+ "BW": "Botswana",
39
+ "BY": "Belarus",
40
+ "BZ": "Belize",
41
+ "CA": "Canada",
42
+ "CC": "Cocos (Keeling) Islands",
43
+ "CD": "The Democratic Republic of the Congo",
44
+ "CF": "Central African Republic",
45
+ "CG": "Congo",
46
+ "CH": "Switzerland",
47
+ "CI": "Côte d'Ivoire",
48
+ "CK": "Cook Islands",
49
+ "CL": "Chile",
50
+ "CM": "Cameroon",
51
+ "CN": "China",
52
+ "CO": "Colombia",
53
+ "CP": "Clipperton Island",
54
+ "CQ": "Sark",
55
+ "CR": "Costa Rica",
56
+ "CS": "Serbia and Montenegro",
57
+ "CU": "Cuba",
58
+ "CV": "Cabo Verde",
59
+ "CW": "Curaçao",
60
+ "CX": "Christmas Island",
61
+ "CY": "Cyprus",
62
+ "CZ": "Czechia",
63
+ "DE": "Germany",
64
+ "DG": "Diego Garcia",
65
+ "DJ": "Djibouti",
66
+ "DK": "Denmark",
67
+ "DM": "Dominica",
68
+ "DO": "Dominican Republic",
69
+ "DZ": "Algeria",
70
+ "EA": "Ceuta, Melilla",
71
+ "EC": "Ecuador",
72
+ "EE": "Estonia",
73
+ "EG": "Egypt",
74
+ "EH": "Western Sahara",
75
+ "ER": "Eritrea",
76
+ "ES": "Spain",
77
+ "ET": "Ethiopia",
78
+ "EU": "European Union",
79
+ "EZ": "Eurozone",
80
+ "FI": "Finland",
81
+ "FJ": "Fiji",
82
+ "FK": "Falkland Islands (Malvinas)",
83
+ "FM": "Federated States of Micronesia",
84
+ "FO": "Faroe Islands",
85
+ "FR": "France",
86
+ "GA": "Gabon",
87
+ "GB": "United Kingdom",
88
+ "GD": "Grenada",
89
+ "GE": "Georgia",
90
+ "GF": "French Guiana",
91
+ "GG": "Guernsey",
92
+ "GH": "Ghana",
93
+ "GI": "Gibraltar",
94
+ "GL": "Greenland",
95
+ "GM": "Gambia",
96
+ "GN": "Guinea",
97
+ "GP": "Guadeloupe",
98
+ "GQ": "Equatorial Guinea",
99
+ "GR": "Greece",
100
+ "GS": "South Georgia and the South Sandwich Islands",
101
+ "GT": "Guatemala",
102
+ "GU": "Guam",
103
+ "GW": "Guinea-Bissau",
104
+ "GY": "Guyana",
105
+ "HK": "Hong Kong",
106
+ "HM": "Heard Island and McDonald Islands",
107
+ "HN": "Honduras",
108
+ "HR": "Croatia",
109
+ "HT": "Haiti",
110
+ "HU": "Hungary",
111
+ "IC": "Canary Islands",
112
+ "ID": "Indonesia",
113
+ "IE": "Ireland",
114
+ "IL": "Israel",
115
+ "IM": "Isle of Man",
116
+ "IN": "India",
117
+ "IO": "British Indian Ocean Territory",
118
+ "IQ": "Iraq",
119
+ "IR": "Islamic Republic of Iran",
120
+ "IS": "Iceland",
121
+ "IT": "Italy",
122
+ "JE": "Jersey",
123
+ "JM": "Jamaica",
124
+ "JO": "Jordan",
125
+ "JP": "Japan",
126
+ "KE": "Kenya",
127
+ "KG": "Kyrgyzstan",
128
+ "KH": "Cambodia",
129
+ "KI": "Kiribati",
130
+ "KM": "Comoros",
131
+ "KN": "Saint Kitts and Nevis",
132
+ "KP": "Democratic People's Republic of Korea",
133
+ "KR": "Republic of Korea",
134
+ "KW": "Kuwait",
135
+ "KY": "Cayman Islands",
136
+ "KZ": "Kazakhstan",
137
+ "LA": "Lao People's Democratic Republic",
138
+ "LB": "Lebanon",
139
+ "LC": "Saint Lucia",
140
+ "LI": "Liechtenstein",
141
+ "LK": "Sri Lanka",
142
+ "LR": "Liberia",
143
+ "LS": "Lesotho",
144
+ "LT": "Lithuania",
145
+ "LU": "Luxembourg",
146
+ "LV": "Latvia",
147
+ "LY": "Libya",
148
+ "MA": "Morocco",
149
+ "MC": "Monaco",
150
+ "MD": "Moldova",
151
+ "ME": "Montenegro",
152
+ "MF": "Saint Martin (French part)",
153
+ "MG": "Madagascar",
154
+ "MH": "Marshall Islands",
155
+ "MK": "North Macedonia",
156
+ "ML": "Mali",
157
+ "MM": "Myanmar",
158
+ "MN": "Mongolia",
159
+ "MO": "Macao",
160
+ "MP": "Northern Mariana Islands",
161
+ "MQ": "Martinique",
162
+ "MR": "Mauritania",
163
+ "MS": "Montserrat",
164
+ "MT": "Malta",
165
+ "MU": "Mauritius",
166
+ "MV": "Maldives",
167
+ "MW": "Malawi",
168
+ "MX": "Mexico",
169
+ "MY": "Malaysia",
170
+ "MZ": "Mozambique",
171
+ "NA": "Namibia",
172
+ "NC": "New Caledonia",
173
+ "NE": "Niger",
174
+ "NF": "Norfolk Island",
175
+ "NG": "Nigeria",
176
+ "NI": "Nicaragua",
177
+ "NL": "Netherlands",
178
+ "NO": "Norway",
179
+ "NP": "Nepal",
180
+ "NR": "Nauru",
181
+ "NU": "Niue",
182
+ "NZ": "New Zealand",
183
+ "OM": "Oman",
184
+ "PA": "Panama",
185
+ "PE": "Peru",
186
+ "PF": "French Polynesia",
187
+ "PG": "Papua New Guinea",
188
+ "PH": "Philippines",
189
+ "PK": "Pakistan",
190
+ "PL": "Poland",
191
+ "PM": "Saint Pierre and Miquelon",
192
+ "PN": "Pitcairn",
193
+ "PR": "Puerto Rico",
194
+ "PS": "State of Palestine",
195
+ "PT": "Portugal",
196
+ "PW": "Palau",
197
+ "PY": "Paraguay",
198
+ "QA": "Qatar",
199
+ "RE": "Réunion",
200
+ "RO": "Romania",
201
+ "RS": "Serbia",
202
+ "RU": "Russian Federation",
203
+ "RW": "Rwanda",
204
+ "SA": "Saudi Arabia",
205
+ "SB": "Solomon Islands",
206
+ "SC": "Seychelles",
207
+ "SD": "Sudan",
208
+ "SE": "Sweden",
209
+ "SG": "Singapore",
210
+ "SH": "Saint Helena, Ascension and Tristan da Cunha",
211
+ "SI": "Slovenia",
212
+ "SJ": "Svalbard and Jan Mayen",
213
+ "SK": "Slovakia",
214
+ "SL": "Sierra Leone",
215
+ "SM": "San Marino",
216
+ "SN": "Senegal",
217
+ "SO": "Somalia",
218
+ "SR": "Suriname",
219
+ "SS": "South Sudan",
220
+ "ST": "Sao Tome and Principe",
221
+ "SV": "El Salvador",
222
+ "SX": "Sint Maarten (Dutch part)",
223
+ "SY": "Syrian Arab Republic",
224
+ "SZ": "Eswatini",
225
+ "TA": "Tristan da Cunha",
226
+ "TC": "Turks and Caicos Islands",
227
+ "TD": "Chad",
228
+ "TF": "French Southern Territories",
229
+ "TG": "Togo",
230
+ "TH": "Thailand",
231
+ "TJ": "Tajikistan",
232
+ "TK": "Tokelau",
233
+ "TL": "Timor-Leste",
234
+ "TM": "Turkmenistan",
235
+ "TN": "Tunisia",
236
+ "TO": "Tonga",
237
+ "TR": "Türkiye",
238
+ "TT": "Trinidad and Tobago",
239
+ "TV": "Tuvalu",
240
+ "TW": "Taiwan, Province of China",
241
+ "TZ": "United Republic of Tanzania",
242
+ "UA": "Ukraine",
243
+ "UG": "Uganda",
244
+ "UM": "United States Minor Outlying Islands",
245
+ "UN": "United Nations",
246
+ "US": "United States",
247
+ "UY": "Uruguay",
248
+ "UZ": "Uzbekistan",
249
+ "VA": "Holy See (Vatican City State)",
250
+ "VC": "Saint Vincent and the Grenadines",
251
+ "VE": "Venezuela",
252
+ "VG": "British Virgin Islands",
253
+ "VI": "U.S. Virgin Islands",
254
+ "VN": "Viet Nam",
255
+ "VU": "Vanuatu",
256
+ "WF": "Wallis and Futuna",
257
+ "WS": "Samoa",
258
+ "YD": "Democratic Yemen",
259
+ "YE": "Yemen",
260
+ "YT": "Mayotte",
261
+ "YU": "Yugoslavia",
262
+ "ZA": "South Africa",
263
+ "ZM": "Zambia",
264
+ "ZW": "Zimbabwe",
265
+ "001": "World",
266
+ "002": "Africa",
267
+ "003": "North America",
268
+ "005": "South America",
269
+ "009": "Oceania",
270
+ "011": "Western Africa",
271
+ "013": "Central America",
272
+ "014": "Eastern Africa",
273
+ "015": "Northern Africa",
274
+ "017": "Middle Africa",
275
+ "018": "Southern Africa",
276
+ "019": "Americas",
277
+ "021": "Northern America",
278
+ "029": "Caribbean",
279
+ "030": "Eastern Asia",
280
+ "034": "Southern Asia",
281
+ "035": "South-Eastern Asia",
282
+ "039": "Southern Europe",
283
+ "053": "Australia and New Zealand",
284
+ "054": "Melanesia",
285
+ "057": "Micronesia",
286
+ "061": "Polynesia",
287
+ "142": "Asia",
288
+ "143": "Central Asia",
289
+ "145": "Western Asia",
290
+ "150": "Europe",
291
+ "151": "Eastern Europe",
292
+ "154": "Northern Europe",
293
+ "155": "Western Europe",
294
+ "202": "Sub-Saharan Africa",
295
+ "419": "Latin America and the Caribbean"
296
+ }
@@ -1,4 +1,4 @@
1
- const RegionToCode = {
1
+ {
2
2
  "ascension island": "AC",
3
3
  "andorra": "AD",
4
4
  "united arab emirates": "AE",
@@ -293,6 +293,4 @@ const RegionToCode = {
293
293
  "western europe": "155",
294
294
  "sub-saharan africa": "202",
295
295
  "latin america and the caribbean": "419"
296
- };
297
- module.exports = RegionToCode;
298
-
296
+ }
@@ -1,4 +1,4 @@
1
- const CodeToLanguage = {
1
+ {
2
2
  "ab": "Abkhazian",
3
3
  "aa": "Afar",
4
4
  "af": "Afrikaans",
@@ -183,4 +183,3 @@ const CodeToLanguage = {
183
183
  "za": "Zhuang",
184
184
  "zu": "Zulu"
185
185
  }
186
- module.exports = CodeToLanguage;
@@ -1,4 +1,4 @@
1
- const LanguageToCode = {
1
+ {
2
2
  "abkhazian": "ab",
3
3
  "afar": "aa",
4
4
  "afrikaans": "af",
@@ -225,4 +225,3 @@ const LanguageToCode = {
225
225
  "chuang": "za",
226
226
  "zulu": "zu"
227
227
  }
228
- module.exports = LanguageToCode;
@@ -1,4 +1,4 @@
1
- const CodeToLanguageTriletter = {
1
+ {
2
2
  "abk": "Abkhazian",
3
3
  "aar": "Afar",
4
4
  "afr": "Afrikaans",
@@ -184,4 +184,3 @@ const CodeToLanguageTriletter = {
184
184
  "zha": "Zhuang",
185
185
  "zul": "Zulu"
186
186
  }
187
- module.exports = CodeToLanguageTriletter;
@@ -1,4 +1,4 @@
1
- const LanguageToCodeTriletter = {
1
+ {
2
2
  "abkhazian": "abk",
3
3
  "afar": "aar",
4
4
  "afrikaans": "afr",
@@ -226,4 +226,3 @@ const LanguageToCodeTriletter = {
226
226
  "chuang": "zha",
227
227
  "zulu": "zul"
228
228
  }
229
- module.exports = LanguageToCodeTriletter;
@@ -1,122 +1,119 @@
1
+ "use strict";
1
2
  // ----- IMPORTS ----- //
2
-
3
+ var __importDefault = (this && this.__importDefault) || function (mod) {
4
+ return (mod && mod.__esModule) ? mod : { "default": mod };
5
+ };
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports._getLanguageCode = exports._getLanguageName = void 0;
8
+ exports._getLanguageObject = _getLanguageObject;
9
+ exports._isSameLanguage = _isSameLanguage;
3
10
  // Import modules for mapping ISO 639 codes to language names and vice versa
4
- const CodeToLanguage = require('./639-1/CodeToLanguage.js');
5
- const LanguageToCode = require('./639-1/LanguageToCode.js');
6
-
11
+ const CodeToLanguage_json_1 = __importDefault(require("./639-1/CodeToLanguage.json"));
12
+ const LanguageToCode_json_1 = __importDefault(require("./639-1/LanguageToCode.json"));
13
+ const CodeToLanguage = CodeToLanguage_json_1.default;
14
+ const LanguageToCode = LanguageToCode_json_1.default;
7
15
  // Import modules for mapping ISO 639-3 codes (for languages without two-letter codes)
8
- const CodeToLanguageTriletter = require('./639-3/CodeToLanguageTriletter.js');
9
- const LanguageToCodeTriletter = require('./639-3/LanguageToCodeTriletter.js');
10
-
16
+ const CodeToLanguageTriletter_json_1 = __importDefault(require("./639-3/CodeToLanguageTriletter.json"));
17
+ const LanguageToCodeTriletter_json_1 = __importDefault(require("./639-3/LanguageToCodeTriletter.json"));
18
+ const CodeToLanguageTriletter = CodeToLanguageTriletter_json_1.default;
19
+ const LanguageToCodeTriletter = LanguageToCodeTriletter_json_1.default;
11
20
  // Import module for mapping ISO 15924 script codes to script names
12
- const ScriptToCode = require('./15924/ScriptToCode.js');
13
- const CodeToScript = require('./15924/CodeToScript.js');
14
-
21
+ const ScriptToCode_json_1 = __importDefault(require("./15924/ScriptToCode.json"));
22
+ const CodeToScript_json_1 = __importDefault(require("./15924/CodeToScript.json"));
23
+ const ScriptToCode = ScriptToCode_json_1.default;
24
+ const CodeToScript = CodeToScript_json_1.default;
15
25
  // Import module for mapping ISO 3166 region codes to region names
16
- const RegionToCode = require('./3166/RegionToCode.js');
17
- const CodeToRegion = require('./3166/CodeToRegion.js');
18
-
26
+ const RegionToCode_json_1 = __importDefault(require("./3166/RegionToCode.json"));
27
+ const CodeToRegion_json_1 = __importDefault(require("./3166/CodeToRegion.json"));
28
+ const RegionToCode = RegionToCode_json_1.default;
29
+ const CodeToRegion = CodeToRegion_json_1.default;
19
30
  // Import predefined common regions
20
- const Predefined = require('./predefined/Predefined.js')
21
-
31
+ const Predefined_json_1 = __importDefault(require("./predefined/Predefined.json"));
32
+ const Predefined = Predefined_json_1.default;
22
33
  // ----- FORMATTING HELPER FUNCTIONS ----- //
23
-
24
34
  /**
25
35
  * Capitalizes the first letter of a code and converts the rest to lowercase.
26
36
  * @param {string} code - The code to capitalize.
27
37
  * @returns {string} The capitalized code.
28
38
  */
29
39
  const _capitalize = (code) => {
30
- if (code.length === 0) return code;
40
+ if (code.length === 0)
41
+ return code;
31
42
  return code.charAt(0).toUpperCase() + code.slice(1).toLowerCase();
32
- }
33
-
43
+ };
34
44
  // ----- MAPPING FUNCTIONS ----- //
35
-
36
45
  /**
37
46
  * Returns the name of a language from an ISO 639 code.
38
47
  * @param {string} code - The ISO 639 code.
39
48
  * @returns {string} The language name.
40
49
  */
41
- const _mapCodeToLanguage = code => {
42
- code = code?.toLowerCase();
43
- if (code?.length === 2) {
50
+ const _mapCodeToLanguage = (code) => {
51
+ code = code === null || code === void 0 ? void 0 : code.toLowerCase();
52
+ if ((code === null || code === void 0 ? void 0 : code.length) === 2) {
44
53
  return CodeToLanguage[code];
45
- }
46
- if (code?.length === 3) {
54
+ }
55
+ if ((code === null || code === void 0 ? void 0 : code.length) === 3) {
47
56
  return CodeToLanguageTriletter[code];
48
57
  }
49
58
  return '';
50
- }
51
-
59
+ };
52
60
  /**
53
61
  * Returns an ISO 639 code from a language name.
54
62
  * Preferentially returns two-letter codes.
55
63
  * @param {string} language - The language name.
56
64
  * @returns {string} The ISO 639 code.
57
65
  */
58
- const _mapLanguageToCode = language => {
59
- language = language?.toLowerCase();
66
+ const _mapLanguageToCode = (language) => {
67
+ language = language === null || language === void 0 ? void 0 : language.toLowerCase();
60
68
  return LanguageToCode[language] || LanguageToCodeTriletter[language] || '';
61
- }
62
-
69
+ };
63
70
  /**
64
71
  * Returns the name of a script from an ISO 15924 code.
65
72
  * @param {string} code - The ISO 15924 code.
66
73
  * @returns {string} The script name.
67
74
  */
68
- const _mapCodeToScript = code => {
75
+ const _mapCodeToScript = (code) => {
69
76
  code = _capitalize(code);
70
77
  return CodeToScript[code] || '';
71
- }
72
-
78
+ };
73
79
  /**
74
80
  * Returns an ISO 15924 code from a script name.
75
81
  * @param {string} script - The script name.
76
82
  * @returns {string} The ISO 15924 code.
77
83
  */
78
- const _mapScriptToCode = script => {
79
- script = script?.toLowerCase();
84
+ const _mapScriptToCode = (script) => {
85
+ script = script === null || script === void 0 ? void 0 : script.toLowerCase();
80
86
  return ScriptToCode[script] || '';
81
- }
87
+ };
82
88
  /**
83
89
  * Returns the name of a region from an ISO 3166 code.
84
90
  * @param {string} code - The ISO 3166 code.
85
91
  * @returns {string} The region name.
86
92
  */
87
- const _mapCodeToRegion = code => {
88
- code = code?.toUpperCase();
93
+ const _mapCodeToRegion = (code) => {
94
+ code = code === null || code === void 0 ? void 0 : code.toUpperCase();
89
95
  return CodeToRegion[code] || '';
90
- }
91
-
96
+ };
92
97
  /**
93
98
  * Returns an ISO 3166 code from a region name.
94
99
  * @param {string} region - The region name.
95
100
  * @returns {string} The ISO 3166 code.
96
101
  */
97
- const _mapRegionToCode = region => {
98
- region = region?.toLowerCase();
102
+ const _mapRegionToCode = (region) => {
103
+ region = region === null || region === void 0 ? void 0 : region.toLowerCase();
99
104
  return RegionToCode[region] || '';
100
- }
101
-
102
- // ----- LANGUAGE OBJECTS FROM CODES ----- //
103
-
104
- /**
105
- * Returns a language object from an array of codes or a single code.
106
- * @param {string|string[]} codes - The code or array of codes.
107
- * @returns {Object|Object[]} The language object(s).
108
- */
109
- const _getLanguageObject = codes => {
105
+ };
106
+ function _getLanguageObject(codes) {
110
107
  return Array.isArray(codes) ? codes.map(_handleGetLanguageObject) : _handleGetLanguageObject(codes);
111
108
  }
112
-
113
109
  /**
114
110
  * Helper function to create a language object from a code.
115
111
  * @param {string} code - The language code.
116
- * @returns {Object|null} The language object.
112
+ * @returns {LanguageObject|null} The language object.
117
113
  */
118
- const _handleGetLanguageObject = code => {
119
- if (!code) return null;
114
+ const _handleGetLanguageObject = (code) => {
115
+ if (!code)
116
+ return null;
120
117
  let languageObject = {
121
118
  language: '',
122
119
  script: '',
@@ -134,25 +131,24 @@ const _handleGetLanguageObject = code => {
134
131
  else if (subtags.length === 2) { // either language-script or language-region
135
132
  if (_isScriptCode(subtags[1])) {
136
133
  languageObject.script = _mapCodeToScript(subtags[1]);
137
- } else {
134
+ }
135
+ else {
138
136
  languageObject.region = _mapCodeToRegion(subtags[1]);
139
137
  }
140
138
  }
141
139
  return languageObject.language ? languageObject : null;
142
- }
143
-
140
+ };
144
141
  /**
145
142
  * Helper function to determine if a code is a script code.
146
143
  * @param {string} code - The code to check.
147
144
  * @returns {boolean} True if the code is a script code, false otherwise.
148
145
  */
149
- const _isScriptCode = (code) => { // if not assume region
150
- if (code.length !== 4) return false;
146
+ const _isScriptCode = (code) => {
147
+ if (code.length !== 4)
148
+ return false;
151
149
  return true;
152
- }
153
-
150
+ };
154
151
  // ----- LANGUAGE NAMES FROM CODES ----- //
155
-
156
152
  /**
157
153
  * Returns the language name(s) from an array of codes or a single code.
158
154
  * @param {string|string[]} codes - The code or array of codes.
@@ -160,66 +156,69 @@ const _isScriptCode = (code) => { // if not assume region
160
156
  */
161
157
  const _getLanguageName = (codes) => {
162
158
  return Array.isArray(codes) ? codes.map(_handleGetLanguageName) : _handleGetLanguageName(codes);
163
- }
164
-
159
+ };
160
+ exports._getLanguageName = _getLanguageName;
165
161
  /**
166
162
  * Helper function to get the language name from a code.
167
163
  * @param {string} code - The language code.
168
164
  * @returns {string} The language name.
169
165
  */
170
- const _handleGetLanguageName = code => {
171
- if (!code) return '';
172
- if (Predefined[code]) return Predefined[code];
166
+ const _handleGetLanguageName = (code) => {
167
+ if (!code)
168
+ return '';
169
+ if (Predefined[code])
170
+ return Predefined[code];
173
171
  const languageObject = _getLanguageObject(code);
174
- if (!languageObject) return '';
172
+ if (!languageObject)
173
+ return '';
175
174
  let result = languageObject.language;
176
175
  if (languageObject.script) {
177
- result += `, ${languageObject.script}`
176
+ result += `, ${languageObject.script}`;
178
177
  }
179
178
  if (languageObject.region) {
180
- result += `, ${languageObject.region}`
179
+ result += `, ${languageObject.region}`;
181
180
  }
182
181
  return result;
183
- }
184
-
182
+ };
185
183
  // ----- LANGUAGE CODES FROM NAMES ----- //
186
-
187
184
  /**
188
185
  * Returns the language code(s) from an array of language names or a single name.
189
186
  * @param {string|string[]} languages - The language name or array of language names.
190
187
  * @returns {string|string[]} The language code(s).
191
188
  */
192
- const _getLanguageCode = languages => {
189
+ const _getLanguageCode = (languages) => {
193
190
  return Array.isArray(languages) ? languages.map(_handleGetLanguageCode) : _handleGetLanguageCode(languages);
194
- }
195
-
191
+ };
192
+ exports._getLanguageCode = _getLanguageCode;
196
193
  /**
197
194
  * Helper function to get the language code from a language name.
198
195
  * @param {string|Object} language - The language name or object.
199
196
  * @returns {string} The language code.
200
197
  */
201
- const _handleGetLanguageCode = language => {
202
- if (typeof language === 'string') return _handleGetLanguageCodeFromString(language);
198
+ const _handleGetLanguageCode = (language) => {
199
+ if (typeof language === 'string')
200
+ return _handleGetLanguageCodeFromString(language);
203
201
  return _handleGetLanguageCodeFromObject(language);
204
- }
205
-
202
+ };
206
203
  /**
207
204
  * Helper function to get the language code from a language name string.
208
205
  * @param {string} language - The language name.
209
206
  * @returns {string} The language code.
210
207
  */
211
- const _handleGetLanguageCodeFromString = language => {
208
+ const _handleGetLanguageCodeFromString = (language) => {
212
209
  const subtagStrings = language.split(',').map(string => string.trim());
213
210
  let code = _mapLanguageToCode(subtagStrings[0]);
214
211
  if (code) {
215
212
  if (subtagStrings.length === 3) {
216
- code += `-${_mapScriptToCode(subtagStrings[1])}`
217
- code += `-${_mapRegionToCode(subtagStrings[2])}`
213
+ code += `-${_mapScriptToCode(subtagStrings[1])}`;
214
+ code += `-${_mapRegionToCode(subtagStrings[2])}`;
218
215
  }
219
216
  else if (subtagStrings.length === 2) {
220
217
  let tag = _mapScriptToCode(subtagStrings[1]);
221
- if (!tag) tag = _mapRegionToCode(subtagStrings[1]);
222
- if (tag) code += `-${tag}`;
218
+ if (!tag)
219
+ tag = _mapRegionToCode(subtagStrings[1]);
220
+ if (tag)
221
+ code += `-${tag}`;
223
222
  }
224
223
  }
225
224
  if (!code) {
@@ -230,63 +229,43 @@ const _handleGetLanguageCodeFromString = language => {
230
229
  }
231
230
  }
232
231
  return code;
233
- }
234
-
232
+ };
235
233
  /**
236
234
  * Helper function to get the language code from a language object.
237
- * @param {Object} languageObject - The language object.
235
+ * @param {LanguageObject} languageObject - The language object.
238
236
  * @returns {string} The language code.
239
237
  */
240
- const _handleGetLanguageCodeFromObject = languageObject => {
241
- if (!languageObject?.language) return '';
238
+ const _handleGetLanguageCodeFromObject = (languageObject) => {
239
+ if (!(languageObject === null || languageObject === void 0 ? void 0 : languageObject.language))
240
+ return '';
242
241
  let code = languageObject.language.toLowerCase();
243
242
  if (languageObject.script) {
244
- code += `-${_capitalize(languageObject.script)}`
243
+ code += `-${_capitalize(languageObject.script)}`;
245
244
  }
246
245
  if (languageObject.region) {
247
- code += `-${languageObject.region.toUpperCase()}`
246
+ code += `-${languageObject.region.toUpperCase()}`;
248
247
  }
249
248
  return code;
250
- }
251
-
252
- // ----- COMPARISON FUNCTION ----- //
253
-
254
- /**
255
- * Determines if all provided language codes represent the same language.
256
- * Can take either an array of codes or a plain set of parameters.
257
- * @param {...(string|string[])} codes - The language codes, either as separate arguments or as an array.
258
- * @returns {boolean} True if all codes represent the same language, false otherwise.
259
- */
260
- const _isSameLanguage = (...codes) => {
249
+ };
250
+ function _isSameLanguage(...codes) {
261
251
  // Flatten the array in case the codes are provided as an array
262
252
  if (codes.length === 1 && Array.isArray(codes[0])) {
263
253
  codes = codes[0];
264
254
  }
265
-
266
- if (codes.length < 2) return false;
267
-
255
+ if (codes.length < 2)
256
+ return false;
268
257
  let language = null;
269
258
  for (let i = 0; i < codes.length; i++) {
270
- if (typeof codes[i] !== 'string') return false;
271
-
259
+ if (typeof codes[i] !== 'string')
260
+ return false;
272
261
  const languageCode = codes[i].split('-')[0];
273
262
  const currentLanguage = _mapCodeToLanguage(languageCode);
274
-
275
263
  if (language === null) {
276
264
  language = currentLanguage;
277
- } else if (language !== currentLanguage) {
265
+ }
266
+ else if (language !== currentLanguage) {
278
267
  return false;
279
268
  }
280
269
  }
281
270
  return true;
282
271
  }
283
-
284
- // ----- EXPORTS ----- //
285
-
286
- // Export functions for external use
287
- module.exports = {
288
- _getLanguageObject,
289
- _getLanguageName,
290
- _getLanguageCode,
291
- _isSameLanguage
292
- };
@@ -1,4 +1,4 @@
1
- const Predefined = {
1
+ {
2
2
  "en-US": "English",
3
3
  "en-GB": "British English",
4
4
  "en-CA": "Canadian English",
@@ -25,5 +25,4 @@ const Predefined = {
25
25
  "ar-MA": "Moroccan Arabic",
26
26
  "nl-BE": "Belgian Dutch",
27
27
  "it-CH": "Swiss Italian"
28
- };
29
- module.exports = Predefined;
28
+ }
package/dist/index.js ADDED
@@ -0,0 +1,74 @@
1
+ "use strict";
2
+ // `generaltranslation` language toolkit
3
+ // © 2024, General Translation, Inc.
4
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
5
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
6
+ return new (P || (P = Promise))(function (resolve, reject) {
7
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
8
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
9
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
10
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
11
+ });
12
+ };
13
+ var __importDefault = (this && this.__importDefault) || function (mod) {
14
+ return (mod && mod.__esModule) ? mod : { "default": mod };
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.isSameLanguage = exports.getLanguageName = exports.getLanguageCode = exports.getLanguageObject = void 0;
18
+ // ----- IMPORTS ----- //
19
+ const codes_1 = require("./codes/codes");
20
+ const _translateReactChildren_1 = __importDefault(require("./translation/_translateReactChildren"));
21
+ // TO DO
22
+ // - Translation API
23
+ // - Times/dates?
24
+ // - Currency conversion?
25
+ // ----- CORE CLASS ----- //
26
+ const getDefaultFromEnv = (VARIABLE) => {
27
+ if (typeof process !== 'undefined' && process.env) {
28
+ return process.env[VARIABLE] || '';
29
+ }
30
+ return '';
31
+ };
32
+ /**
33
+ * GT is the core driver for the General Translation library.
34
+ */
35
+ class GT {
36
+ /**
37
+ * Constructs an instance of the GT class.
38
+ *
39
+ * @param {GTConstructorParams} [params] - The parameters for initializing the GT instance.
40
+ * @param {string} [params.apiKey=''] - The API key for accessing the translation service.
41
+ * @param {string} [params.defaultLanguage='en'] - The default language for translations.
42
+ * @param {string} [params.projectID=''] - The project ID for the translation service.
43
+ * @param {string} [params.baseURL='https://prod.gtx.dev'] - The base URL for the translation service.
44
+ */
45
+ constructor({ apiKey = '', defaultLanguage = 'en', projectID = '', baseURL = 'https://prod.gtx.dev' } = {}) {
46
+ this.apiKey = apiKey || getDefaultFromEnv('GT_API_KEY');
47
+ this.projectID = projectID || getDefaultFromEnv('GT_PROJECT_ID');
48
+ this.defaultLanguage = defaultLanguage.toLowerCase();
49
+ this.baseURL = baseURL;
50
+ }
51
+ /**
52
+ * Translates the content of React children elements.
53
+ *
54
+ * @param {Object} params - The parameters for the translation.
55
+ * @param {any} params.content - The React children content to be translated.
56
+ * @param {string} params.targetLanguage - The target language for the translation.
57
+ * @param {Object} params.metadata - Additional metadata for the translation process.
58
+ *
59
+ * @returns {Promise<any>} - A promise that resolves to the translated content.
60
+ */
61
+ translateReactChildren(_a) {
62
+ return __awaiter(this, arguments, void 0, function* ({ content, targetLanguage, metadata = {} }) {
63
+ return yield _translateReactChildren_1.default.call(this, content, targetLanguage, metadata);
64
+ });
65
+ }
66
+ }
67
+ // ----- EXPORTS ----- //
68
+ // Export the class
69
+ exports.default = GT;
70
+ // Export the functions
71
+ exports.getLanguageObject = codes_1._getLanguageObject;
72
+ exports.getLanguageCode = codes_1._getLanguageCode;
73
+ exports.getLanguageName = codes_1._getLanguageName;
74
+ exports.isSameLanguage = codes_1._isSameLanguage;
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.default = _translateReactChildren;
13
+ /**
14
+ * Translates the given content into the target language using a specified API.
15
+ *
16
+ * @param {Object} this - An object containing baseURL and apiKey for the API.
17
+ * @param {any} content - The content to be translated. This can be of any type.
18
+ * @param {string} targetLanguage - The target language code (e.g., 'en', 'fr') for the translation.
19
+ * @param {Object} metadata - Additional metadata to be sent with the translation request.
20
+ *
21
+ * @returns {Promise<Object | null>} - A promise that resolves to the translated content as an object, or null if an error occurs.
22
+ *
23
+ * @throws {Error} - Throws an error if the response from the API is not ok (status code not in the range 200-299).
24
+ *
25
+ **/
26
+ function _translateReactChildren(content, targetLanguage, metadata) {
27
+ return __awaiter(this, void 0, void 0, function* () {
28
+ try {
29
+ const response = yield fetch(`${this.baseURL}`, {
30
+ method: 'POST',
31
+ headers: {
32
+ 'Content-Type': 'application/json',
33
+ 'gtx-api-key': this.apiKey,
34
+ },
35
+ body: JSON.stringify({
36
+ content: content,
37
+ targetLanguage: targetLanguage,
38
+ metadata: metadata
39
+ })
40
+ });
41
+ if (!response.ok) {
42
+ throw new Error(`${response.status}: ${yield response.text()}`);
43
+ }
44
+ return yield response.json();
45
+ }
46
+ catch (error) {
47
+ console.error(error);
48
+ return null;
49
+ }
50
+ });
51
+ }
package/package.json CHANGED
@@ -1,14 +1,15 @@
1
1
  {
2
2
  "name": "generaltranslation",
3
- "version": "1.3.3",
3
+ "version": "2.0.1",
4
4
  "description": "A language toolkit for AI developers",
5
- "main": "index.js",
5
+ "main": "dist/index.js",
6
6
  "scripts": {
7
- "test": "echo \"Error: no test specified\" && exit 1"
7
+ "test": "echo \"Error: no test specified\" && exit 1",
8
+ "build": "tsc"
8
9
  },
9
10
  "repository": {
10
11
  "type": "git",
11
- "url": "git+https://github.com/General-Translation/js-toolkit.git"
12
+ "url": "git+https://github.com/General-Translation/generaltranslation.git"
12
13
  },
13
14
  "keywords": [
14
15
  "LLM",
@@ -20,7 +21,11 @@
20
21
  "author": "General Translation, Inc.",
21
22
  "license": "ISC",
22
23
  "bugs": {
23
- "url": "https://github.com/General-Translation/js-toolkit/issues"
24
+ "url": "https://github.com/General-Translation/generaltranslation/issues"
24
25
  },
25
- "homepage": "https://github.com/General-Translation/js-toolkit#readme"
26
+ "homepage": "https://github.com/General-Translation/generaltranslation#readme",
27
+ "devDependencies": {
28
+ "@types/node": "^20.14.9",
29
+ "typescript": "^5.5.2"
30
+ }
26
31
  }
@@ -1,299 +0,0 @@
1
- const CodeToRegion = {
2
- "AC": "Ascension Island",
3
- "AD": "Andorra",
4
- "AE": "United Arab Emirates",
5
- "AF": "Afghanistan",
6
- "AG": "Antigua and Barbuda",
7
- "AI": "Anguilla",
8
- "AL": "Albania",
9
- "AM": "Armenia",
10
- "AN": "Netherlands Antilles",
11
- "AO": "Angola",
12
- "AQ": "Antarctica",
13
- "AR": "Argentina",
14
- "AS": "American Samoa",
15
- "AT": "Austria",
16
- "AU": "Australia",
17
- "AW": "Aruba",
18
- "AX": "Åland Islands",
19
- "AZ": "Azerbaijan",
20
- "BA": "Bosnia and Herzegovina",
21
- "BB": "Barbados",
22
- "BD": "Bangladesh",
23
- "BE": "Belgium",
24
- "BF": "Burkina Faso",
25
- "BG": "Bulgaria",
26
- "BH": "Bahrain",
27
- "BI": "Burundi",
28
- "BJ": "Benin",
29
- "BL": "Saint Barthélemy",
30
- "BM": "Bermuda",
31
- "BN": "Brunei Darussalam",
32
- "BO": "Bolivia",
33
- "BQ": "Bonaire, Sint Eustatius and Saba",
34
- "BR": "Brazil",
35
- "BS": "Bahamas",
36
- "BT": "Bhutan",
37
- "BV": "Bouvet Island",
38
- "BW": "Botswana",
39
- "BY": "Belarus",
40
- "BZ": "Belize",
41
- "CA": "Canada",
42
- "CC": "Cocos (Keeling) Islands",
43
- "CD": "The Democratic Republic of the Congo",
44
- "CF": "Central African Republic",
45
- "CG": "Congo",
46
- "CH": "Switzerland",
47
- "CI": "Côte d'Ivoire",
48
- "CK": "Cook Islands",
49
- "CL": "Chile",
50
- "CM": "Cameroon",
51
- "CN": "China",
52
- "CO": "Colombia",
53
- "CP": "Clipperton Island",
54
- "CQ": "Sark",
55
- "CR": "Costa Rica",
56
- "CS": "Serbia and Montenegro",
57
- "CU": "Cuba",
58
- "CV": "Cabo Verde",
59
- "CW": "Curaçao",
60
- "CX": "Christmas Island",
61
- "CY": "Cyprus",
62
- "CZ": "Czechia",
63
- "DE": "Germany",
64
- "DG": "Diego Garcia",
65
- "DJ": "Djibouti",
66
- "DK": "Denmark",
67
- "DM": "Dominica",
68
- "DO": "Dominican Republic",
69
- "DZ": "Algeria",
70
- "EA": "Ceuta, Melilla",
71
- "EC": "Ecuador",
72
- "EE": "Estonia",
73
- "EG": "Egypt",
74
- "EH": "Western Sahara",
75
- "ER": "Eritrea",
76
- "ES": "Spain",
77
- "ET": "Ethiopia",
78
- "EU": "European Union",
79
- "EZ": "Eurozone",
80
- "FI": "Finland",
81
- "FJ": "Fiji",
82
- "FK": "Falkland Islands (Malvinas)",
83
- "FM": "Federated States of Micronesia",
84
- "FO": "Faroe Islands",
85
- "FR": "France",
86
- "GA": "Gabon",
87
- "GB": "United Kingdom",
88
- "GD": "Grenada",
89
- "GE": "Georgia",
90
- "GF": "French Guiana",
91
- "GG": "Guernsey",
92
- "GH": "Ghana",
93
- "GI": "Gibraltar",
94
- "GL": "Greenland",
95
- "GM": "Gambia",
96
- "GN": "Guinea",
97
- "GP": "Guadeloupe",
98
- "GQ": "Equatorial Guinea",
99
- "GR": "Greece",
100
- "GS": "South Georgia and the South Sandwich Islands",
101
- "GT": "Guatemala",
102
- "GU": "Guam",
103
- "GW": "Guinea-Bissau",
104
- "GY": "Guyana",
105
- "HK": "Hong Kong",
106
- "HM": "Heard Island and McDonald Islands",
107
- "HN": "Honduras",
108
- "HR": "Croatia",
109
- "HT": "Haiti",
110
- "HU": "Hungary",
111
- "IC": "Canary Islands",
112
- "ID": "Indonesia",
113
- "IE": "Ireland",
114
- "IL": "Israel",
115
- "IM": "Isle of Man",
116
- "IN": "India",
117
- "IO": "British Indian Ocean Territory",
118
- "IQ": "Iraq",
119
- "IR": "Islamic Republic of Iran",
120
- "IS": "Iceland",
121
- "IT": "Italy",
122
- "JE": "Jersey",
123
- "JM": "Jamaica",
124
- "JO": "Jordan",
125
- "JP": "Japan",
126
- "KE": "Kenya",
127
- "KG": "Kyrgyzstan",
128
- "KH": "Cambodia",
129
- "KI": "Kiribati",
130
- "KM": "Comoros",
131
- "KN": "Saint Kitts and Nevis",
132
- "KP": "Democratic People's Republic of Korea",
133
- "KR": "Republic of Korea",
134
- "KW": "Kuwait",
135
- "KY": "Cayman Islands",
136
- "KZ": "Kazakhstan",
137
- "LA": "Lao People's Democratic Republic",
138
- "LB": "Lebanon",
139
- "LC": "Saint Lucia",
140
- "LI": "Liechtenstein",
141
- "LK": "Sri Lanka",
142
- "LR": "Liberia",
143
- "LS": "Lesotho",
144
- "LT": "Lithuania",
145
- "LU": "Luxembourg",
146
- "LV": "Latvia",
147
- "LY": "Libya",
148
- "MA": "Morocco",
149
- "MC": "Monaco",
150
- "MD": "Moldova",
151
- "ME": "Montenegro",
152
- "MF": "Saint Martin (French part)",
153
- "MG": "Madagascar",
154
- "MH": "Marshall Islands",
155
- "MK": "North Macedonia",
156
- "ML": "Mali",
157
- "MM": "Myanmar",
158
- "MN": "Mongolia",
159
- "MO": "Macao",
160
- "MP": "Northern Mariana Islands",
161
- "MQ": "Martinique",
162
- "MR": "Mauritania",
163
- "MS": "Montserrat",
164
- "MT": "Malta",
165
- "MU": "Mauritius",
166
- "MV": "Maldives",
167
- "MW": "Malawi",
168
- "MX": "Mexico",
169
- "MY": "Malaysia",
170
- "MZ": "Mozambique",
171
- "NA": "Namibia",
172
- "NC": "New Caledonia",
173
- "NE": "Niger",
174
- "NF": "Norfolk Island",
175
- "NG": "Nigeria",
176
- "NI": "Nicaragua",
177
- "NL": "Netherlands",
178
- "NO": "Norway",
179
- "NP": "Nepal",
180
- "NR": "Nauru",
181
- "NU": "Niue",
182
- "NZ": "New Zealand",
183
- "OM": "Oman",
184
- "PA": "Panama",
185
- "PE": "Peru",
186
- "PF": "French Polynesia",
187
- "PG": "Papua New Guinea",
188
- "PH": "Philippines",
189
- "PK": "Pakistan",
190
- "PL": "Poland",
191
- "PM": "Saint Pierre and Miquelon",
192
- "PN": "Pitcairn",
193
- "PR": "Puerto Rico",
194
- "PS": "State of Palestine",
195
- "PT": "Portugal",
196
- "PW": "Palau",
197
- "PY": "Paraguay",
198
- "QA": "Qatar",
199
- "RE": "Réunion",
200
- "RO": "Romania",
201
- "RS": "Serbia",
202
- "RU": "Russian Federation",
203
- "RW": "Rwanda",
204
- "SA": "Saudi Arabia",
205
- "SB": "Solomon Islands",
206
- "SC": "Seychelles",
207
- "SD": "Sudan",
208
- "SE": "Sweden",
209
- "SG": "Singapore",
210
- "SH": "Saint Helena, Ascension and Tristan da Cunha",
211
- "SI": "Slovenia",
212
- "SJ": "Svalbard and Jan Mayen",
213
- "SK": "Slovakia",
214
- "SL": "Sierra Leone",
215
- "SM": "San Marino",
216
- "SN": "Senegal",
217
- "SO": "Somalia",
218
- "SR": "Suriname",
219
- "SS": "South Sudan",
220
- "ST": "Sao Tome and Principe",
221
- "SV": "El Salvador",
222
- "SX": "Sint Maarten (Dutch part)",
223
- "SY": "Syrian Arab Republic",
224
- "SZ": "Eswatini",
225
- "TA": "Tristan da Cunha",
226
- "TC": "Turks and Caicos Islands",
227
- "TD": "Chad",
228
- "TF": "French Southern Territories",
229
- "TG": "Togo",
230
- "TH": "Thailand",
231
- "TJ": "Tajikistan",
232
- "TK": "Tokelau",
233
- "TL": "Timor-Leste",
234
- "TM": "Turkmenistan",
235
- "TN": "Tunisia",
236
-
237
-
238
- "TO": "Tonga",
239
- "TR": "Türkiye",
240
- "TT": "Trinidad and Tobago",
241
- "TV": "Tuvalu",
242
- "TW": "Taiwan, Province of China",
243
- "TZ": "United Republic of Tanzania",
244
- "UA": "Ukraine",
245
- "UG": "Uganda",
246
- "UM": "United States Minor Outlying Islands",
247
- "UN": "United Nations",
248
- "US": "United States",
249
- "UY": "Uruguay",
250
- "UZ": "Uzbekistan",
251
- "VA": "Holy See (Vatican City State)",
252
- "VC": "Saint Vincent and the Grenadines",
253
- "VE": "Venezuela",
254
- "VG": "British Virgin Islands",
255
- "VI": "U.S. Virgin Islands",
256
- "VN": "Viet Nam",
257
- "VU": "Vanuatu",
258
- "WF": "Wallis and Futuna",
259
- "WS": "Samoa",
260
- "YD": "Democratic Yemen",
261
- "YE": "Yemen",
262
- "YT": "Mayotte",
263
- "YU": "Yugoslavia",
264
- "ZA": "South Africa",
265
- "ZM": "Zambia",
266
- "ZW": "Zimbabwe",
267
- "001": "World",
268
- "002": "Africa",
269
- "003": "North America",
270
- "005": "South America",
271
- "009": "Oceania",
272
- "011": "Western Africa",
273
- "013": "Central America",
274
- "014": "Eastern Africa",
275
- "015": "Northern Africa",
276
- "017": "Middle Africa",
277
- "018": "Southern Africa",
278
- "019": "Americas",
279
- "021": "Northern America",
280
- "029": "Caribbean",
281
- "030": "Eastern Asia",
282
- "034": "Southern Asia",
283
- "035": "South-Eastern Asia",
284
- "039": "Southern Europe",
285
- "053": "Australia and New Zealand",
286
- "054": "Melanesia",
287
- "057": "Micronesia",
288
- "061": "Polynesia",
289
- "142": "Asia",
290
- "143": "Central Asia",
291
- "145": "Western Asia",
292
- "150": "Europe",
293
- "151": "Eastern Europe",
294
- "154": "Northern Europe",
295
- "155": "Western Europe",
296
- "202": "Sub-Saharan Africa",
297
- "419": "Latin America and the Caribbean"
298
- }
299
- module.exports = CodeToRegion;
package/index.js DELETED
@@ -1,84 +0,0 @@
1
- // `generaltranslation` language toolkit
2
- // © 2024, General Translation, Inc.
3
-
4
- // ----- IMPORTS ----- //
5
-
6
- const { _getLanguageObject, _getLanguageCode, _getLanguageName, _isSameLanguage } = require('./codes/codes.js');
7
-
8
- // TO DO
9
- // - Translation API
10
- // - Times/dates?
11
- // - Currency conversion?
12
-
13
- // ----- CORE CLASS ----- //
14
-
15
- const getDefaultFromEnv = (VARIABLE) => {
16
- if (typeof process !== 'undefined') {
17
- if (process?.env?.[VARIABLE]) {
18
- return process.env[VARIABLE];
19
- }
20
- }
21
- return '';
22
- }
23
-
24
- class GT {
25
-
26
- constructor({
27
- apiKey = '',
28
- defaultLanguage = 'en',
29
- projectID = '',
30
- baseURL = 'https://prod.gtx.dev'
31
- } = {}) {
32
- this.apiKey = apiKey || getDefaultFromEnv('GT_API_KEY');
33
- this.projectID = projectID || getDefaultFromEnv('GT_PROJECT_ID');
34
- this.defaultLanguage = defaultLanguage?.toLowerCase();
35
- this.baseURL = baseURL;
36
- }
37
-
38
- /**
39
- * Asynchronously translates the given React content to the specified target language.
40
- *
41
- *
42
- * @param {Object} params - The parameters for the translation.
43
- * @param {Object|Array} params.content - The React children content to be translated.
44
- * @param {string} params.targetLanguage - The target language for translation.
45
- * @param {...any} metadata - Additional metadata that might be needed for the translation process.
46
- *
47
- * @returns {Promise<Object|Array>} - A promise that resolves to the translated React children content.
48
- */
49
- async translateReactChildren({ content, targetLanguage, ...metadata }) {
50
- try {
51
- const response = await fetch(`${this.baseURL}`, {
52
- method: 'POST',
53
- headers: {
54
- 'Content-Type': 'application/json',
55
- 'gtx-api-key': this.apiKey,
56
- },
57
- body: JSON.stringify({
58
- content: content,
59
- targetLanguage: targetLanguage,
60
- metadata: { ...metadata }
61
- })
62
- });
63
- if (!response.ok) {
64
- throw new Error(`${response.status}: ${await response.text()}`)
65
- }
66
- return await response.json();
67
- } catch (error) {
68
- console.error(error)
69
- return null;
70
- }
71
- }
72
-
73
- }
74
-
75
- // ----- SECONDARY EXPORTS ----- //
76
-
77
- // Export the class
78
- module.exports = GT;
79
-
80
- // Export the functions
81
- module.exports.getLanguageObject = _getLanguageObject;
82
- module.exports.getLanguageCode = _getLanguageCode;
83
- module.exports.getLanguageName = _getLanguageName;
84
- module.exports.isSameLanguage= _isSameLanguage;