@adminforth/i18n 1.7.1 → 1.8.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.
- package/dist/index.js +15 -8
- package/index.ts +17 -8
- package/package.json +2 -1
package/dist/index.js
CHANGED
|
@@ -9,12 +9,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
};
|
|
10
10
|
import { AdminForthPlugin, Filters, suggestIfTypo, AdminForthDataTypes, RAMLock } from "adminforth";
|
|
11
11
|
import iso6391 from 'iso-639-1';
|
|
12
|
-
import { iso31661Alpha2ToAlpha3 } from 'iso-3166';
|
|
13
12
|
import path from 'path';
|
|
14
13
|
import fs from 'fs-extra';
|
|
15
14
|
import chokidar from 'chokidar';
|
|
16
15
|
import { AsyncQueue } from '@sapphire/async-queue';
|
|
17
16
|
import getFlagEmoji from 'country-flag-svg';
|
|
17
|
+
import { parse } from 'bcp-47';
|
|
18
18
|
const processFrontendMessagesQueue = new AsyncQueue();
|
|
19
19
|
const SLAVIC_PLURAL_EXAMPLES = {
|
|
20
20
|
uk: 'яблук | Яблуко | Яблука | Яблук', // zero | singular | 2-4 | 5+
|
|
@@ -38,6 +38,8 @@ const countryISO31661ByLangISO6391 = {
|
|
|
38
38
|
ja: 'jp', // Japanese → Japan
|
|
39
39
|
uk: 'ua', // Ukrainian → Ukraine
|
|
40
40
|
ur: 'pk', // Urdu → Pakistan
|
|
41
|
+
sr: 'rs', // Serbian → Serbia
|
|
42
|
+
da: 'dk' // Danish → Denmark
|
|
41
43
|
};
|
|
42
44
|
function getCountryCodeFromLangCode(lang) {
|
|
43
45
|
const [langCode, region] = String(lang).split('-');
|
|
@@ -50,15 +52,19 @@ function getPrimaryLanguageCode(langCode) {
|
|
|
50
52
|
return String(langCode).split('-')[0];
|
|
51
53
|
}
|
|
52
54
|
function isValidSupportedLanguageTag(langCode) {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
55
|
+
try {
|
|
56
|
+
const schema = parse(String(langCode), {
|
|
57
|
+
normalize: true,
|
|
58
|
+
warning: (reason, code, offset) => {
|
|
59
|
+
console.warn(`Warning in validating language tag ${langCode}: reason=${reason}, code=${code}, offset=${offset}`);
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
const isValid = schema && schema.language && schema.language.length === 2;
|
|
63
|
+
return !!isValid;
|
|
56
64
|
}
|
|
57
|
-
|
|
58
|
-
return
|
|
65
|
+
catch (e) {
|
|
66
|
+
return false;
|
|
59
67
|
}
|
|
60
|
-
const regionUpper = region.toUpperCase();
|
|
61
|
-
return /^[A-Z]{2}$/.test(regionUpper) && (regionUpper in iso31661Alpha2ToAlpha3);
|
|
62
68
|
}
|
|
63
69
|
class CachingAdapterMemory {
|
|
64
70
|
constructor() {
|
|
@@ -793,6 +799,7 @@ export default class I18nPlugin extends AdminForthPlugin {
|
|
|
793
799
|
const flagEmoji = typeof getFlagEmoji === 'function'
|
|
794
800
|
? getFlagEmoji
|
|
795
801
|
: getFlagEmoji.default;
|
|
802
|
+
console.log('🪲languagesList for lang:', lang, 'country code:', getCountryCodeFromLangCode(lang));
|
|
796
803
|
return {
|
|
797
804
|
code: lang,
|
|
798
805
|
nameOnNative: iso6391.getNativeName(getPrimaryLanguageCode(lang)),
|
package/index.ts
CHANGED
|
@@ -8,7 +8,7 @@ import fs from 'fs-extra';
|
|
|
8
8
|
import chokidar from 'chokidar';
|
|
9
9
|
import { AsyncQueue } from '@sapphire/async-queue';
|
|
10
10
|
import getFlagEmoji from 'country-flag-svg';
|
|
11
|
-
|
|
11
|
+
import { parse } from 'bcp-47'
|
|
12
12
|
|
|
13
13
|
const processFrontendMessagesQueue = new AsyncQueue();
|
|
14
14
|
|
|
@@ -35,6 +35,8 @@ const countryISO31661ByLangISO6391 = {
|
|
|
35
35
|
ja: 'jp', // Japanese → Japan
|
|
36
36
|
uk: 'ua', // Ukrainian → Ukraine
|
|
37
37
|
ur: 'pk', // Urdu → Pakistan
|
|
38
|
+
sr: 'rs', // Serbian → Serbia
|
|
39
|
+
da: 'dk' // Danish → Denmark
|
|
38
40
|
};
|
|
39
41
|
|
|
40
42
|
function getCountryCodeFromLangCode(lang: SupportedLanguage) {
|
|
@@ -50,15 +52,20 @@ function getPrimaryLanguageCode(langCode: SupportedLanguage): string {
|
|
|
50
52
|
}
|
|
51
53
|
|
|
52
54
|
function isValidSupportedLanguageTag(langCode: SupportedLanguage): boolean {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
+
try {
|
|
56
|
+
const schema = parse(String(langCode),
|
|
57
|
+
{
|
|
58
|
+
normalize: true,
|
|
59
|
+
warning: (reason, code, offset) => {
|
|
60
|
+
console.warn(`Warning in validating language tag ${langCode}: reason=${reason}, code=${code}, offset=${offset}`);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
);
|
|
64
|
+
const isValid = schema && schema.language && schema.language.length === 2;
|
|
65
|
+
return !!isValid;
|
|
66
|
+
} catch (e) {
|
|
55
67
|
return false;
|
|
56
68
|
}
|
|
57
|
-
if (!region) {
|
|
58
|
-
return true;
|
|
59
|
-
}
|
|
60
|
-
const regionUpper = region.toUpperCase();
|
|
61
|
-
return /^[A-Z]{2}$/.test(regionUpper) && (regionUpper in iso31661Alpha2ToAlpha3);
|
|
62
69
|
}
|
|
63
70
|
|
|
64
71
|
|
|
@@ -930,6 +937,8 @@ export default class I18nPlugin extends AdminForthPlugin {
|
|
|
930
937
|
typeof getFlagEmoji === 'function'
|
|
931
938
|
? getFlagEmoji
|
|
932
939
|
: getFlagEmoji.default;
|
|
940
|
+
|
|
941
|
+
console.log('🪲languagesList for lang:', lang, 'country code:', getCountryCodeFromLangCode(lang));
|
|
933
942
|
|
|
934
943
|
return {
|
|
935
944
|
code: lang,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adminforth/i18n",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.8.1",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"type": "module",
|
|
@@ -30,6 +30,7 @@
|
|
|
30
30
|
"dependencies": {
|
|
31
31
|
"@aws-sdk/client-ses": "^3.654.0",
|
|
32
32
|
"@sapphire/async-queue": "^1.5.5",
|
|
33
|
+
"bcp-47": "^2.1.0",
|
|
33
34
|
"chokidar": "^4.0.1",
|
|
34
35
|
"country-flag-svg": "^1.0.19",
|
|
35
36
|
"fs-extra": "^11.3.2",
|