generaltranslation 2.0.65 → 2.0.66
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/codes/determineLanguage.d.ts +1 -0
- package/dist/codes/determineLanguage.js +30 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.js +23 -0
- package/package.json +1 -1
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
@@ -0,0 +1,30 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.default = _determineLanguage;
|
4
|
+
var codes_1 = require("./codes");
|
5
|
+
/**
|
6
|
+
* Given a list of language and a list of approved language, sorted in preference order
|
7
|
+
* Determines which language of the given languages is the best match in the approvedLanguages, prioritizing exact matches and falling back to dialects of the same language
|
8
|
+
* @internal
|
9
|
+
*/
|
10
|
+
function _determineLanguage(languages, approvedLanguages) {
|
11
|
+
if (typeof languages === 'string')
|
12
|
+
languages = [languages];
|
13
|
+
if (!approvedLanguages)
|
14
|
+
return languages[0];
|
15
|
+
var _loop_1 = function (language) {
|
16
|
+
var exactMatch = approvedLanguages.find(function (approvedLanguage) { return approvedLanguage === language; });
|
17
|
+
if (exactMatch)
|
18
|
+
return { value: exactMatch };
|
19
|
+
var sameLanguage = approvedLanguages.find(function (approvedLanguage) { return (0, codes_1._isSameLanguage)(approvedLanguage, language); });
|
20
|
+
if (sameLanguage)
|
21
|
+
return { value: sameLanguage };
|
22
|
+
};
|
23
|
+
for (var _i = 0, languages_1 = languages; _i < languages_1.length; _i++) {
|
24
|
+
var language = languages_1[_i];
|
25
|
+
var state_1 = _loop_1(language);
|
26
|
+
if (typeof state_1 === "object")
|
27
|
+
return state_1.value;
|
28
|
+
}
|
29
|
+
return undefined;
|
30
|
+
}
|
package/dist/index.d.ts
CHANGED
@@ -200,3 +200,22 @@ export declare function splitStringToContent(string: string): Content;
|
|
200
200
|
export declare function renderContentToString<V extends Record<string, any>>(content: Content, languages?: string | string[], variables?: V, variableOptions?: {
|
201
201
|
[key in keyof V]?: Intl.NumberFormatOptions | Intl.DateTimeFormatOptions;
|
202
202
|
}): string;
|
203
|
+
/**
|
204
|
+
* Determines the best matching language from the approved languages list based on a provided
|
205
|
+
* list of preferred languages. The function prioritizes exact matches, but will also consider
|
206
|
+
* dialects of the same language if an exact match is not available.
|
207
|
+
*
|
208
|
+
* It also respects the order of preference in both the provided languages list and the
|
209
|
+
* approved languages list. A dialect match of a higher-preference language is considered better
|
210
|
+
* than an exact match of a lower-preference language.
|
211
|
+
*
|
212
|
+
* For example, if the `languages` list is ['en', 'fr'], and the `approvedLanguages` list is
|
213
|
+
* ['fr', 'en-GB'], it will prefer 'en-GB' over 'fr', even though 'fr' has an exact
|
214
|
+
* dialect match, because 'en' appears earlier in the `languages` list.
|
215
|
+
*
|
216
|
+
* @param {string | string[]} languages - A single language or an array of languages sorted in preference order.
|
217
|
+
* @param {string[]} approvedLanguages - An array of approved languages, also sorted by preference.
|
218
|
+
*
|
219
|
+
* @returns {string | undefined} - The best matching language from the approvedLanguages list, or undefined if no match is found.
|
220
|
+
*/
|
221
|
+
export declare function determineLanguage(languages: string | string[], approvedLanguages: string[]): string | undefined;
|
package/dist/index.js
CHANGED
@@ -62,6 +62,7 @@ exports.formatDateTime = formatDateTime;
|
|
62
62
|
exports.formatCurrency = formatCurrency;
|
63
63
|
exports.splitStringToContent = splitStringToContent;
|
64
64
|
exports.renderContentToString = renderContentToString;
|
65
|
+
exports.determineLanguage = determineLanguage;
|
65
66
|
// ----- IMPORTS ----- //
|
66
67
|
var codes_1 = require("./codes/codes");
|
67
68
|
var getLanguageDirection_1 = __importDefault(require("./codes/getLanguageDirection"));
|
@@ -71,6 +72,7 @@ var _translateReact_1 = __importDefault(require("./translation/react/_translateR
|
|
71
72
|
var _updateProjectDictionary_1 = __importDefault(require("./translation/dictionaries/_updateProjectDictionary"));
|
72
73
|
var _format_1 = require("./formatting/_format");
|
73
74
|
var _string_content_1 = require("./formatting/_string_content");
|
75
|
+
var determineLanguage_1 = __importDefault(require("./codes/determineLanguage"));
|
74
76
|
// ----- CORE CLASS ----- //
|
75
77
|
var getDefaultFromEnv = function (VARIABLE) {
|
76
78
|
if (typeof process !== 'undefined' && process.env) {
|
@@ -278,3 +280,24 @@ function splitStringToContent(string) {
|
|
278
280
|
function renderContentToString(content, languages, variables, variableOptions) {
|
279
281
|
return (0, _string_content_1._renderContentToString)(content, languages, variables, variableOptions);
|
280
282
|
}
|
283
|
+
/**
|
284
|
+
* Determines the best matching language from the approved languages list based on a provided
|
285
|
+
* list of preferred languages. The function prioritizes exact matches, but will also consider
|
286
|
+
* dialects of the same language if an exact match is not available.
|
287
|
+
*
|
288
|
+
* It also respects the order of preference in both the provided languages list and the
|
289
|
+
* approved languages list. A dialect match of a higher-preference language is considered better
|
290
|
+
* than an exact match of a lower-preference language.
|
291
|
+
*
|
292
|
+
* For example, if the `languages` list is ['en', 'fr'], and the `approvedLanguages` list is
|
293
|
+
* ['fr', 'en-GB'], it will prefer 'en-GB' over 'fr', even though 'fr' has an exact
|
294
|
+
* dialect match, because 'en' appears earlier in the `languages` list.
|
295
|
+
*
|
296
|
+
* @param {string | string[]} languages - A single language or an array of languages sorted in preference order.
|
297
|
+
* @param {string[]} approvedLanguages - An array of approved languages, also sorted by preference.
|
298
|
+
*
|
299
|
+
* @returns {string | undefined} - The best matching language from the approvedLanguages list, or undefined if no match is found.
|
300
|
+
*/
|
301
|
+
function determineLanguage(languages, approvedLanguages) {
|
302
|
+
return (0, determineLanguage_1.default)(languages, approvedLanguages);
|
303
|
+
}
|