generaltranslation 2.0.55 → 2.0.57
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/{cjs/codes → codes}/codes.js +71 -67
- package/dist/{cjs/codes → codes}/getLanguageDirection.js +5 -5
- package/dist/format/_format.js +62 -0
- package/dist/{cjs/index.d.ts → index.d.ts} +48 -27
- package/dist/index.js +243 -0
- package/dist/translation/_translate.js +109 -0
- package/dist/{mjs/translation/_bundleTranslation.d.ts → translation/_translateBundle.d.ts} +2 -9
- package/dist/translation/_translateBundle.js +95 -0
- package/dist/translation/_translateReact.js +107 -0
- package/dist/{cjs/translation/_updateRemoteDictionary.d.ts → translation/_updateProjectDictionary.d.ts} +1 -1
- package/dist/translation/_updateProjectDictionary.js +83 -0
- package/package.json +7 -7
- package/dist/cjs/index.js +0 -143
- package/dist/cjs/translation/_bundleTranslation.d.ts +0 -22
- package/dist/cjs/translation/_bundleTranslation.js +0 -42
- package/dist/cjs/translation/_intl.js +0 -52
- package/dist/cjs/translation/_translate.js +0 -51
- package/dist/cjs/translation/_translateReactChildren.js +0 -56
- package/dist/cjs/translation/_updateRemoteDictionary.js +0 -30
- 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 -305
- 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 -130
- package/dist/mjs/translation/_bundleTranslation.js +0 -39
- package/dist/mjs/translation/_intl.d.ts +0 -1
- package/dist/mjs/translation/_intl.js +0 -49
- package/dist/mjs/translation/_translate.d.ts +0 -1
- package/dist/mjs/translation/_translate.js +0 -48
- package/dist/mjs/translation/_translateReactChildren.d.ts +0 -1
- package/dist/mjs/translation/_translateReactChildren.js +0 -53
- package/dist/mjs/translation/_updateRemoteDictionary.d.ts +0 -17
- package/dist/mjs/translation/_updateRemoteDictionary.js +0 -27
- /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/translation/_intl.d.ts → format/_format.d.ts} +0 -0
- /package/dist/{cjs/translation → translation}/_translate.d.ts +0 -0
- /package/dist/{cjs/translation/_translateReactChildren.d.ts → translation/_translateReact.d.ts} +0 -0
@@ -10,28 +10,28 @@ exports._getLanguageObject = _getLanguageObject;
|
|
10
10
|
exports._isSameLanguage = _isSameLanguage;
|
11
11
|
// ----- IMPORTS ----- //
|
12
12
|
// Import modules for mapping ISO 639 codes to language names and vice versa
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
13
|
+
var CodeToLanguage_json_1 = __importDefault(require("./639-1/CodeToLanguage.json"));
|
14
|
+
var LanguageToCode_json_1 = __importDefault(require("./639-1/LanguageToCode.json"));
|
15
|
+
var CodeToLanguage = CodeToLanguage_json_1.default;
|
16
|
+
var LanguageToCode = LanguageToCode_json_1.default;
|
17
17
|
// Import modules for mapping ISO 639-3 codes (for languages without two-letter codes)
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
18
|
+
var CodeToLanguageTriletter_json_1 = __importDefault(require("./639-3/CodeToLanguageTriletter.json"));
|
19
|
+
var LanguageToCodeTriletter_json_1 = __importDefault(require("./639-3/LanguageToCodeTriletter.json"));
|
20
|
+
var CodeToLanguageTriletter = CodeToLanguageTriletter_json_1.default;
|
21
|
+
var LanguageToCodeTriletter = LanguageToCodeTriletter_json_1.default;
|
22
22
|
// Import module for mapping ISO 15924 script codes to script names
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
23
|
+
var ScriptToCode_json_1 = __importDefault(require("./15924/ScriptToCode.json"));
|
24
|
+
var CodeToScript_json_1 = __importDefault(require("./15924/CodeToScript.json"));
|
25
|
+
var ScriptToCode = ScriptToCode_json_1.default;
|
26
|
+
var CodeToScript = CodeToScript_json_1.default;
|
27
27
|
// Import module for mapping ISO 3166 region codes to region names
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
28
|
+
var RegionToCode_json_1 = __importDefault(require("./3166/RegionToCode.json"));
|
29
|
+
var CodeToRegion_json_1 = __importDefault(require("./3166/CodeToRegion.json"));
|
30
|
+
var RegionToCode = RegionToCode_json_1.default;
|
31
|
+
var CodeToRegion = CodeToRegion_json_1.default;
|
32
32
|
// Import predefined common regions
|
33
|
-
|
34
|
-
|
33
|
+
var Predefined_json_1 = __importDefault(require("./predefined/Predefined.json"));
|
34
|
+
var Predefined = Predefined_json_1.default;
|
35
35
|
// ----- VALIDITY CHECKS ----- //
|
36
36
|
/**
|
37
37
|
* Ensures correct capitalization and formatting of a language code.
|
@@ -42,17 +42,17 @@ const Predefined = Predefined_json_1.default;
|
|
42
42
|
function _standardizeLanguageCode(code) {
|
43
43
|
if (!_isValidLanguageCode(code))
|
44
44
|
return '';
|
45
|
-
|
46
|
-
|
45
|
+
var codeParts = code.split('-');
|
46
|
+
var result = "".concat(codeParts[0].toLowerCase());
|
47
47
|
if (codeParts[1]) {
|
48
48
|
if (codeParts[1].length === 4) {
|
49
|
-
result +=
|
49
|
+
result += "-".concat(_capitalize(codeParts[1]));
|
50
50
|
if (codeParts[2] && codeParts[2].length === 2) {
|
51
|
-
result +=
|
51
|
+
result += "-".concat(codeParts[2].toUpperCase());
|
52
52
|
}
|
53
53
|
}
|
54
54
|
else if (codeParts[1].length === 2) {
|
55
|
-
result +=
|
55
|
+
result += "-".concat(codeParts[1].toUpperCase());
|
56
56
|
}
|
57
57
|
}
|
58
58
|
return result;
|
@@ -66,7 +66,7 @@ function _standardizeLanguageCode(code) {
|
|
66
66
|
function _isValidLanguageCode(code) {
|
67
67
|
if (!code || typeof code !== 'string')
|
68
68
|
return false;
|
69
|
-
|
69
|
+
var codeParts = code.split('-');
|
70
70
|
if (!_mapCodeToLanguage(codeParts[0]))
|
71
71
|
return false;
|
72
72
|
if (codeParts[1]) {
|
@@ -91,7 +91,7 @@ function _isValidLanguageCode(code) {
|
|
91
91
|
* @param {string} code - The code to capitalize.
|
92
92
|
* @returns {string} The capitalized code.
|
93
93
|
*/
|
94
|
-
|
94
|
+
var _capitalize = function (code) {
|
95
95
|
if (code.length === 0)
|
96
96
|
return code;
|
97
97
|
return code.charAt(0).toUpperCase() + code.slice(1).toLowerCase();
|
@@ -102,12 +102,12 @@ const _capitalize = (code) => {
|
|
102
102
|
* @param {string} code - The ISO 639 code.
|
103
103
|
* @returns {string} The language name.
|
104
104
|
*/
|
105
|
-
|
106
|
-
code = code
|
107
|
-
if (code
|
105
|
+
var _mapCodeToLanguage = function (code) {
|
106
|
+
code = code === null || code === void 0 ? void 0 : code.toLowerCase();
|
107
|
+
if ((code === null || code === void 0 ? void 0 : code.length) === 2) {
|
108
108
|
return CodeToLanguage[code];
|
109
109
|
}
|
110
|
-
if (code
|
110
|
+
if ((code === null || code === void 0 ? void 0 : code.length) === 3) {
|
111
111
|
return CodeToLanguageTriletter[code];
|
112
112
|
}
|
113
113
|
return '';
|
@@ -118,8 +118,8 @@ const _mapCodeToLanguage = (code) => {
|
|
118
118
|
* @param {string} language - The language name.
|
119
119
|
* @returns {string} BCP 47 language tag.
|
120
120
|
*/
|
121
|
-
|
122
|
-
language = language
|
121
|
+
var _mapLanguageToCode = function (language) {
|
122
|
+
language = language === null || language === void 0 ? void 0 : language.toLowerCase();
|
123
123
|
return LanguageToCode[language] || LanguageToCodeTriletter[language] || '';
|
124
124
|
};
|
125
125
|
/**
|
@@ -127,7 +127,7 @@ const _mapLanguageToCode = (language) => {
|
|
127
127
|
* @param {string} code - The ISO 15924 code.
|
128
128
|
* @returns {string} The script name.
|
129
129
|
*/
|
130
|
-
|
130
|
+
var _mapCodeToScript = function (code) {
|
131
131
|
code = _capitalize(code);
|
132
132
|
return CodeToScript[code] || '';
|
133
133
|
};
|
@@ -136,8 +136,8 @@ const _mapCodeToScript = (code) => {
|
|
136
136
|
* @param {string} script - The script name.
|
137
137
|
* @returns {string} The ISO 15924 code.
|
138
138
|
*/
|
139
|
-
|
140
|
-
script = script
|
139
|
+
var _mapScriptToCode = function (script) {
|
140
|
+
script = script === null || script === void 0 ? void 0 : script.toLowerCase();
|
141
141
|
return ScriptToCode[script] || '';
|
142
142
|
};
|
143
143
|
/**
|
@@ -145,8 +145,8 @@ const _mapScriptToCode = (script) => {
|
|
145
145
|
* @param {string} code - The ISO 3166 code.
|
146
146
|
* @returns {string} The region name.
|
147
147
|
*/
|
148
|
-
|
149
|
-
code = code
|
148
|
+
var _mapCodeToRegion = function (code) {
|
149
|
+
code = code === null || code === void 0 ? void 0 : code.toUpperCase();
|
150
150
|
return CodeToRegion[code] || '';
|
151
151
|
};
|
152
152
|
/**
|
@@ -154,8 +154,8 @@ const _mapCodeToRegion = (code) => {
|
|
154
154
|
* @param {string} region - The region name.
|
155
155
|
* @returns {string} The ISO 3166 code.
|
156
156
|
*/
|
157
|
-
|
158
|
-
region = region
|
157
|
+
var _mapRegionToCode = function (region) {
|
158
|
+
region = region === null || region === void 0 ? void 0 : region.toLowerCase();
|
159
159
|
return RegionToCode[region] || '';
|
160
160
|
};
|
161
161
|
/**
|
@@ -169,11 +169,11 @@ function _getLanguageObject(codes) {
|
|
169
169
|
* @param {string} code - The language code.
|
170
170
|
* @returns {LanguageObject|null} The language object.
|
171
171
|
*/
|
172
|
-
|
172
|
+
var _handleGetLanguageObject = function (code) {
|
173
173
|
if (!_isValidLanguageCode(code))
|
174
174
|
return null;
|
175
|
-
|
176
|
-
|
175
|
+
var codeParts = code.split('-');
|
176
|
+
var languageObject = {
|
177
177
|
language: _mapCodeToLanguage(codeParts[0]),
|
178
178
|
};
|
179
179
|
if (codeParts[1]) {
|
@@ -196,7 +196,7 @@ const _handleGetLanguageObject = (code) => {
|
|
196
196
|
* @returns {string|string[]} The language name(s).
|
197
197
|
* @internal
|
198
198
|
*/
|
199
|
-
|
199
|
+
var _getLanguageName = function (codes) {
|
200
200
|
return Array.isArray(codes) ? codes.map(_handleGetLanguageName) : _handleGetLanguageName(codes);
|
201
201
|
};
|
202
202
|
exports._getLanguageName = _getLanguageName;
|
@@ -205,20 +205,20 @@ exports._getLanguageName = _getLanguageName;
|
|
205
205
|
* @param {string} code - The language code.
|
206
206
|
* @returns {string} The language name.
|
207
207
|
*/
|
208
|
-
|
208
|
+
var _handleGetLanguageName = function (code) {
|
209
209
|
if (!_isValidLanguageCode(code))
|
210
210
|
return '';
|
211
211
|
if (Predefined[code])
|
212
212
|
return Predefined[code];
|
213
|
-
|
213
|
+
var languageObject = _handleGetLanguageObject(code);
|
214
214
|
if (!languageObject)
|
215
215
|
return '';
|
216
|
-
|
216
|
+
var result = languageObject.language;
|
217
217
|
if (languageObject.script) {
|
218
|
-
result +=
|
218
|
+
result += ", ".concat(languageObject.script);
|
219
219
|
}
|
220
220
|
if (languageObject.region) {
|
221
|
-
result +=
|
221
|
+
result += ", ".concat(languageObject.region);
|
222
222
|
}
|
223
223
|
return result;
|
224
224
|
};
|
@@ -229,7 +229,7 @@ const _handleGetLanguageName = (code) => {
|
|
229
229
|
* @returns {string|string[]} The language code(s).
|
230
230
|
* @internal
|
231
231
|
*/
|
232
|
-
|
232
|
+
var _getLanguageCode = function (languages) {
|
233
233
|
return Array.isArray(languages) ? languages.map(_handleGetLanguageCode) : _handleGetLanguageCode(languages);
|
234
234
|
};
|
235
235
|
exports._getLanguageCode = _getLanguageCode;
|
@@ -238,7 +238,7 @@ exports._getLanguageCode = _getLanguageCode;
|
|
238
238
|
* @param {string|LanguageObject} language - The language name or object.
|
239
239
|
* @returns {string} The language code.
|
240
240
|
*/
|
241
|
-
|
241
|
+
var _handleGetLanguageCode = function (language) {
|
242
242
|
if (typeof language === 'string')
|
243
243
|
return _handleGetLanguageCodeFromString(language);
|
244
244
|
return _handleGetLanguageCodeFromObject(language);
|
@@ -248,24 +248,24 @@ const _handleGetLanguageCode = (language) => {
|
|
248
248
|
* @param {string} language - The language name.
|
249
249
|
* @returns {string} The language code.
|
250
250
|
*/
|
251
|
-
|
252
|
-
|
253
|
-
|
251
|
+
var _handleGetLanguageCodeFromString = function (language) {
|
252
|
+
var subtagStrings = language.split(',').map(function (string) { return string.trim(); });
|
253
|
+
var code = _mapLanguageToCode(subtagStrings[0]);
|
254
254
|
if (code) {
|
255
255
|
if (subtagStrings.length === 3) {
|
256
|
-
code +=
|
257
|
-
code +=
|
256
|
+
code += "-".concat(_mapScriptToCode(subtagStrings[1]));
|
257
|
+
code += "-".concat(_mapRegionToCode(subtagStrings[2]));
|
258
258
|
}
|
259
259
|
else if (subtagStrings.length === 2) {
|
260
|
-
|
260
|
+
var tag = _mapScriptToCode(subtagStrings[1]);
|
261
261
|
if (!tag)
|
262
262
|
tag = _mapRegionToCode(subtagStrings[1]);
|
263
263
|
if (tag)
|
264
|
-
code +=
|
264
|
+
code += "-".concat(tag);
|
265
265
|
}
|
266
266
|
}
|
267
267
|
if (!code) {
|
268
|
-
for (
|
268
|
+
for (var key in Predefined) {
|
269
269
|
if (Predefined[key] === language) {
|
270
270
|
return key;
|
271
271
|
}
|
@@ -278,34 +278,38 @@ const _handleGetLanguageCodeFromString = (language) => {
|
|
278
278
|
* @param {LanguageObject} languageObject - The language object.
|
279
279
|
* @returns {string} The language code.
|
280
280
|
*/
|
281
|
-
|
282
|
-
if (!languageObject
|
281
|
+
var _handleGetLanguageCodeFromObject = function (languageObject) {
|
282
|
+
if (!(languageObject === null || languageObject === void 0 ? void 0 : languageObject.language))
|
283
283
|
return '';
|
284
|
-
|
284
|
+
var code = languageObject.language.toLowerCase();
|
285
285
|
if (languageObject.script) {
|
286
|
-
code +=
|
286
|
+
code += "-".concat(_capitalize(languageObject.script));
|
287
287
|
}
|
288
288
|
if (languageObject.region) {
|
289
|
-
code +=
|
289
|
+
code += "-".concat(languageObject.region.toUpperCase());
|
290
290
|
}
|
291
291
|
return _isValidLanguageCode(code) ? code : '';
|
292
292
|
};
|
293
293
|
/**
|
294
294
|
* @internal
|
295
295
|
*/
|
296
|
-
function _isSameLanguage(
|
296
|
+
function _isSameLanguage() {
|
297
|
+
var codes = [];
|
298
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
299
|
+
codes[_i] = arguments[_i];
|
300
|
+
}
|
297
301
|
// Flatten the array in case the codes are provided as an array
|
298
302
|
if (codes.length === 1 && Array.isArray(codes[0])) {
|
299
303
|
codes = codes[0];
|
300
304
|
}
|
301
305
|
if (codes.length < 2)
|
302
306
|
return false;
|
303
|
-
|
304
|
-
for (
|
307
|
+
var language = null;
|
308
|
+
for (var i = 0; i < codes.length; i++) {
|
305
309
|
if (typeof codes[i] !== 'string')
|
306
310
|
return false;
|
307
|
-
|
308
|
-
|
311
|
+
var languageCode = codes[i].split('-')[0];
|
312
|
+
var currentLanguage = _mapCodeToLanguage(languageCode);
|
309
313
|
if (language === null) {
|
310
314
|
language = currentLanguage;
|
311
315
|
}
|
@@ -27,7 +27,7 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
27
27
|
*
|
28
28
|
* @type {string[]}
|
29
29
|
*/
|
30
|
-
|
30
|
+
var rtlLanguages = [
|
31
31
|
'ae', /* Avestan */
|
32
32
|
'ar', /* 'العربية', Arabic */
|
33
33
|
'arc', /* Aramaic */
|
@@ -50,7 +50,7 @@ const rtlLanguages = [
|
|
50
50
|
'yi' /* 'ייִדיש', Yiddish */
|
51
51
|
];
|
52
52
|
/* ----- END YAHOO COPYRIGHT ----- */
|
53
|
-
|
53
|
+
var codes_js_1 = require("./codes.js");
|
54
54
|
/**
|
55
55
|
* Get the text direction for a given language code.
|
56
56
|
*
|
@@ -59,9 +59,9 @@ const codes_js_1 = require("./codes.js");
|
|
59
59
|
* @internal
|
60
60
|
*/
|
61
61
|
function _getLanguageDirection(code) {
|
62
|
-
return rtlLanguages.some(language
|
63
|
-
|
64
|
-
|
62
|
+
return rtlLanguages.some(function (language) {
|
63
|
+
var lo = (0, codes_js_1._getLanguageObject)(language);
|
64
|
+
var clo = (0, codes_js_1._getLanguageObject)(code);
|
65
65
|
if (!lo || !clo)
|
66
66
|
return false;
|
67
67
|
if (lo.script && clo.script && lo.script !== clo.script)
|
@@ -0,0 +1,62 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
3
|
+
__assign = Object.assign || function(t) {
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
5
|
+
s = arguments[i];
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
7
|
+
t[p] = s[p];
|
8
|
+
}
|
9
|
+
return t;
|
10
|
+
};
|
11
|
+
return __assign.apply(this, arguments);
|
12
|
+
};
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
14
|
+
exports._num = _num;
|
15
|
+
exports._datetime = _datetime;
|
16
|
+
exports._currency = _currency;
|
17
|
+
/**
|
18
|
+
* Formats a number according to the specified languages and options.
|
19
|
+
*
|
20
|
+
* @param {Object} params - The parameters for the number formatting.
|
21
|
+
* @param {number} params.value - The number to format.
|
22
|
+
* @param {string | string[]} [params.languages=['en']] - The languages to use for formatting.
|
23
|
+
* @param {Intl.NumberFormatOptions} [params.options={}] - Additional options for number formatting.
|
24
|
+
*
|
25
|
+
* @returns {string} The formatted number.
|
26
|
+
* @internal
|
27
|
+
*/
|
28
|
+
function _num(_a) {
|
29
|
+
var value = _a.value, _b = _a.languages, languages = _b === void 0 ? ['en'] : _b, _c = _a.options, options = _c === void 0 ? {} : _c;
|
30
|
+
return new Intl.NumberFormat(languages, __assign({ numberingSystem: 'latn' }, options)).format(value);
|
31
|
+
}
|
32
|
+
/**
|
33
|
+
* Formats a date according to the specified languages and options.
|
34
|
+
*
|
35
|
+
* @param {Object} params - The parameters for the date formatting.
|
36
|
+
* @param {Date} params.value - The date to format.
|
37
|
+
* @param {string | string[]} [params.languages=['en']] - The languages to use for formatting.
|
38
|
+
* @param {Intl.DateTimeFormatOptions} [params.options={}] - Additional options for date formatting.
|
39
|
+
*
|
40
|
+
* @returns {string} The formatted date.
|
41
|
+
* @internal
|
42
|
+
*/
|
43
|
+
function _datetime(_a) {
|
44
|
+
var value = _a.value, _b = _a.languages, languages = _b === void 0 ? ['en'] : _b, _c = _a.options, options = _c === void 0 ? {} : _c;
|
45
|
+
return new Intl.DateTimeFormat(languages, __assign({ calendar: "gregory", numberingSystem: "latn" }, options)).format(value);
|
46
|
+
}
|
47
|
+
/**
|
48
|
+
* Formats a currency value according to the specified languages, currency, and options.
|
49
|
+
*
|
50
|
+
* @param {Object} params - The parameters for the currency formatting.
|
51
|
+
* @param {number} params.value - The currency value to format.
|
52
|
+
* @param {string} params.currency - The currency code (e.g., 'USD').
|
53
|
+
* @param {string | string[]} [params.languages=['en']] - The languages to use for formatting.
|
54
|
+
* @param {Intl.NumberFormatOptions} [params.options={}] - Additional options for currency formatting.
|
55
|
+
*
|
56
|
+
* @returns {string} The formatted currency value.
|
57
|
+
* @internal
|
58
|
+
*/
|
59
|
+
function _currency(_a) {
|
60
|
+
var value = _a.value, _b = _a.languages, languages = _b === void 0 ? ['en'] : _b, _c = _a.currency, currency = _c === void 0 ? 'USD' : _c, _d = _a.options, options = _d === void 0 ? {} : _d;
|
61
|
+
return new Intl.NumberFormat(languages, __assign({ style: 'currency', currency: currency, numberingSystem: 'latn' }, options)).format(value);
|
62
|
+
}
|
@@ -1,6 +1,7 @@
|
|
1
1
|
import { LanguageObject } from './codes/codes';
|
2
|
-
import { Request } from './translation/
|
3
|
-
import { Update } from './translation/
|
2
|
+
import { Request } from './translation/_translateBundle';
|
3
|
+
import { Update } from './translation/_updateProjectDictionary';
|
4
|
+
import { _num, _datetime, _currency } from './format/_format';
|
4
5
|
/**
|
5
6
|
* Type representing the constructor parameters for the GT class.
|
6
7
|
*/
|
@@ -29,30 +30,20 @@ declare class GT {
|
|
29
30
|
*/
|
30
31
|
constructor({ apiKey, defaultLanguage, projectID, baseURL }?: GTConstructorParams);
|
31
32
|
/**
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
33
|
+
* Translates a string into a target language.
|
34
|
+
* If `metadata.store` is provided, the translation is cached for use in a public project.
|
35
|
+
*
|
36
|
+
* @param {string} content - The string to be translated.
|
37
|
+
* @param {string} targetLanguage - The target language code (e.g., 'en', 'fr') for the translation.
|
38
|
+
* @param {{ context?: string, store?: boolean, [key: string]: any }} [metadata] - Additional metadata for the translation request.
|
39
|
+
* @param {string} [metadata.context] - Contextual information to assist with the translation.
|
40
|
+
* @param {boolean} [metadata.store] - Whether to cache the translation for use in a public project.
|
41
|
+
*
|
42
|
+
* @returns {Promise<{ translation: string, error?: Error | unknown }>} - A promise that resolves to the translated content, or an error if the translation fails.
|
43
|
+
*/
|
38
44
|
translate(content: string, targetLanguage: string, metadata?: {
|
39
|
-
notes?: string;
|
40
|
-
[key: string]: any;
|
41
|
-
}): Promise<{
|
42
|
-
translation: string;
|
43
|
-
error?: Error | unknown;
|
44
|
-
}>;
|
45
|
-
/**
|
46
|
-
* Translates a string and caches for use in a public project.
|
47
|
-
* @param {string} content - A string to translate.
|
48
|
-
* @param {string} targetLanguage - The target language for the translation.
|
49
|
-
* @param {string} projectID - The ID of the project.
|
50
|
-
* @param {dictionaryName?: string, context?: string, [key: string]: any }} metadata - Additional metadata for the translation request.
|
51
|
-
* @returns {Promise<{ translation: string, error?: Error | unknown }>} The translated content with optional error information.
|
52
|
-
*/
|
53
|
-
intl(content: string, targetLanguage: string, projectID?: string, metadata?: {
|
54
|
-
dictionaryName?: string;
|
55
45
|
context?: string;
|
46
|
+
store?: boolean;
|
56
47
|
[key: string]: any;
|
57
48
|
}): Promise<{
|
58
49
|
translation: string;
|
@@ -68,7 +59,9 @@ declare class GT {
|
|
68
59
|
*
|
69
60
|
* @returns {Promise<any>} - A promise that resolves to the translated content.
|
70
61
|
*/
|
71
|
-
|
62
|
+
translateReact(content: any, targetLanguage: string, metadata?: {
|
63
|
+
context?: string;
|
64
|
+
store?: boolean;
|
72
65
|
[key: string]: any;
|
73
66
|
}): Promise<{
|
74
67
|
translation: any | null;
|
@@ -79,7 +72,7 @@ declare class GT {
|
|
79
72
|
* @param requests - Array of requests to be processed and sent.
|
80
73
|
* @returns A promise that resolves to an array of processed results.
|
81
74
|
*/
|
82
|
-
|
75
|
+
translateBundle(requests: Request[]): Promise<Array<any | null>>;
|
83
76
|
/**
|
84
77
|
* Pushes updates to a remotely cached translation dictionary.
|
85
78
|
* @param {Update[]} updates - Array of updates with optional targetLanguage.
|
@@ -88,7 +81,7 @@ declare class GT {
|
|
88
81
|
* @param {boolean} [replace=false] - Whether to replace the existing dictionary. Defaults to false.
|
89
82
|
* @returns {Promise<string[]>} A promise that resolves to an array of strings indicating the languages which have been updated.
|
90
83
|
*/
|
91
|
-
|
84
|
+
updateProjectDictionary(updates: Update[], languages?: string[], projectID?: string, replace?: boolean): Promise<string[]>;
|
92
85
|
}
|
93
86
|
export default GT;
|
94
87
|
/**
|
@@ -151,3 +144,31 @@ export declare function getLanguageName(codes: string[]): string[];
|
|
151
144
|
* @returns {boolean} True if all BCP 47 codes represent the same language, false otherwise.
|
152
145
|
*/
|
153
146
|
export declare function isSameLanguage(...codes: string[]): boolean;
|
147
|
+
/**
|
148
|
+
* Formats a number according to the specified languages and options.
|
149
|
+
* @param {Object} params - The parameters for the number formatting.
|
150
|
+
* @param {number} params.value - The number to format.
|
151
|
+
* @param {string | string[]} [params.languages=['en']] - The languages to use for formatting.
|
152
|
+
* @param {Intl.NumberFormatOptions} [params.options={}] - Additional options for number formatting.
|
153
|
+
* @returns {string} The formatted number.
|
154
|
+
*/
|
155
|
+
export declare const num: typeof _num;
|
156
|
+
/**
|
157
|
+
* Formats a date according to the specified languages and options.
|
158
|
+
* @param {Object} params - The parameters for the date formatting.
|
159
|
+
* @param {Date} params.value - The date to format.
|
160
|
+
* @param {string | string[]} [params.languages=['en']] - The languages to use for formatting.
|
161
|
+
* @param {Intl.DateTimeFormatOptions} [params.options={}] - Additional options for date formatting.
|
162
|
+
* @returns {string} The formatted date.
|
163
|
+
*/
|
164
|
+
export declare const datetime: typeof _datetime;
|
165
|
+
/**
|
166
|
+
* Formats a currency value according to the specified languages, currency, and options.
|
167
|
+
* @param {Object} params - The parameters for the currency formatting.
|
168
|
+
* @param {number} params.value - The currency value to format.
|
169
|
+
* @param {string} params.currency - The currency code (e.g., 'USD').
|
170
|
+
* @param {string | string[]} [params.languages=['en']] - The languages to use for formatting.
|
171
|
+
* @param {Intl.NumberFormatOptions} [params.options={}] - Additional options for currency formatting.
|
172
|
+
* @returns {string} The formatted currency value.
|
173
|
+
*/
|
174
|
+
export declare const currency: typeof _currency;
|