@adminforth/i18n 1.0.23-next.2 → 1.0.23-next.3
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/Changelog.md +4 -0
- package/dist/index.js +16 -2
- package/index.ts +21 -5
- package/package.json +1 -1
package/Changelog.md
CHANGED
|
@@ -13,6 +13,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
13
13
|
|
|
14
14
|
### Added
|
|
15
15
|
- support for pluralization in Backend `tr` function
|
|
16
|
+
- add handy languagesList function to get all languages for translation of side apps
|
|
17
|
+
|
|
18
|
+
### Fixed
|
|
19
|
+
- invalidation of indvidual tr messages when translation using LLM adapter
|
|
16
20
|
|
|
17
21
|
## [1.0.22]
|
|
18
22
|
|
package/dist/index.js
CHANGED
|
@@ -30,6 +30,19 @@ const SLAVIC_PLURAL_EXAMPLES = {
|
|
|
30
30
|
be: 'яблыкаў | яблык | яблыкі | яблыкаў', // zero | singular | 2-4 | 5+
|
|
31
31
|
ru: 'яблок | яблоко | яблока | яблок', // zero | singular | 2-4 | 5+
|
|
32
32
|
};
|
|
33
|
+
const countryISO31661ByLangISO6391 = {
|
|
34
|
+
en: 'us', // English → United States
|
|
35
|
+
zh: 'cn', // Chinese → China
|
|
36
|
+
hi: 'in', // Hindi → India
|
|
37
|
+
ar: 'sa', // Arabic → Saudi Arabia
|
|
38
|
+
ko: 'kr', // Korean → South Korea
|
|
39
|
+
ja: 'jp', // Japanese → Japan
|
|
40
|
+
uk: 'ua', // Ukrainian → Ukraine
|
|
41
|
+
ur: 'pk', // Urdu → Pakistan
|
|
42
|
+
};
|
|
43
|
+
function getCountryCodeFromLangCode(langCode) {
|
|
44
|
+
return countryISO31661ByLangISO6391[langCode] || langCode;
|
|
45
|
+
}
|
|
33
46
|
class CachingAdapterMemory {
|
|
34
47
|
constructor() {
|
|
35
48
|
this.cache = {};
|
|
@@ -425,6 +438,7 @@ ${JSON.stringify(strings.reduce((acc, s) => {
|
|
|
425
438
|
updateStrings[translation[this.primaryKeyFieldName]] = {
|
|
426
439
|
updates: {},
|
|
427
440
|
translatedStr,
|
|
441
|
+
enStr,
|
|
428
442
|
category: translation[this.options.categoryFieldName],
|
|
429
443
|
strId: translation[this.primaryKeyFieldName],
|
|
430
444
|
};
|
|
@@ -482,7 +496,7 @@ ${JSON.stringify(strings.reduce((acc, s) => {
|
|
|
482
496
|
})));
|
|
483
497
|
for (const lang of langsInvolved) {
|
|
484
498
|
yield this.cache.clear(`${this.resourceConfig.resourceId}:frontend:${lang}`);
|
|
485
|
-
for (const
|
|
499
|
+
for (const { enStr, category } of Object.values(updateStrings)) {
|
|
486
500
|
yield this.cache.clear(`${this.resourceConfig.resourceId}:${category}:${lang}:${enStr}`);
|
|
487
501
|
}
|
|
488
502
|
}
|
|
@@ -681,7 +695,7 @@ ${JSON.stringify(strings.reduce((acc, s) => {
|
|
|
681
695
|
code: lang,
|
|
682
696
|
nameOnNative: iso6391.getNativeName(lang),
|
|
683
697
|
nameEnglish: iso6391.getName(lang),
|
|
684
|
-
emojiFlag: lang.toUpperCase().replace(/./g, char => String.fromCodePoint(char.charCodeAt(0) + 127397)),
|
|
698
|
+
emojiFlag: getCountryCodeFromLangCode(lang).toUpperCase().replace(/./g, char => String.fromCodePoint(char.charCodeAt(0) + 127397)),
|
|
685
699
|
};
|
|
686
700
|
});
|
|
687
701
|
});
|
package/index.ts
CHANGED
|
@@ -6,8 +6,6 @@ import path from 'path';
|
|
|
6
6
|
import fs from 'fs-extra';
|
|
7
7
|
import chokidar from 'chokidar';
|
|
8
8
|
import { AsyncQueue } from '@sapphire/async-queue';
|
|
9
|
-
|
|
10
|
-
|
|
11
9
|
console.log = (...args) => {
|
|
12
10
|
process.stdout.write(args.join(" ") + "\n");
|
|
13
11
|
};
|
|
@@ -28,6 +26,22 @@ const SLAVIC_PLURAL_EXAMPLES = {
|
|
|
28
26
|
ru: 'яблок | яблоко | яблока | яблок', // zero | singular | 2-4 | 5+
|
|
29
27
|
};
|
|
30
28
|
|
|
29
|
+
const countryISO31661ByLangISO6391 = {
|
|
30
|
+
en: 'us', // English → United States
|
|
31
|
+
zh: 'cn', // Chinese → China
|
|
32
|
+
hi: 'in', // Hindi → India
|
|
33
|
+
ar: 'sa', // Arabic → Saudi Arabia
|
|
34
|
+
ko: 'kr', // Korean → South Korea
|
|
35
|
+
ja: 'jp', // Japanese → Japan
|
|
36
|
+
uk: 'ua', // Ukrainian → Ukraine
|
|
37
|
+
ur: 'pk', // Urdu → Pakistan
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
function getCountryCodeFromLangCode(langCode) {
|
|
41
|
+
return countryISO31661ByLangISO6391[langCode] || langCode;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
|
|
31
45
|
interface ICachingAdapter {
|
|
32
46
|
get(key: string): Promise<any>;
|
|
33
47
|
set(key: string, value: any): Promise<void>;
|
|
@@ -406,7 +420,7 @@ export default class I18nPlugin extends AdminForthPlugin {
|
|
|
406
420
|
strings: { en_string: string, category: string }[],
|
|
407
421
|
plurals=false,
|
|
408
422
|
translations: any[],
|
|
409
|
-
updateStrings: Record<string, { updates: any, category: string, strId: string, translatedStr: string }> = {}
|
|
423
|
+
updateStrings: Record<string, { updates: any, category: string, strId: string, enStr: string, translatedStr: string }> = {}
|
|
410
424
|
): Promise<string[]> {
|
|
411
425
|
const maxKeysInOneReq = 10;
|
|
412
426
|
if (strings.length === 0) {
|
|
@@ -486,6 +500,7 @@ JSON.stringify(strings.reduce((acc: object, s: { en_string: string }): object =>
|
|
|
486
500
|
updateStrings[translation[this.primaryKeyFieldName]] = {
|
|
487
501
|
updates: {},
|
|
488
502
|
translatedStr,
|
|
503
|
+
enStr,
|
|
489
504
|
category: translation[this.options.categoryFieldName],
|
|
490
505
|
strId: translation[this.primaryKeyFieldName],
|
|
491
506
|
};
|
|
@@ -541,6 +556,7 @@ JSON.stringify(strings.reduce((acc: object, s: { en_string: string }): object =>
|
|
|
541
556
|
updates: any,
|
|
542
557
|
category: string,
|
|
543
558
|
strId: string,
|
|
559
|
+
enStr: string,
|
|
544
560
|
translatedStr: string
|
|
545
561
|
}> = {};
|
|
546
562
|
|
|
@@ -585,7 +601,7 @@ JSON.stringify(strings.reduce((acc: object, s: { en_string: string }): object =>
|
|
|
585
601
|
|
|
586
602
|
for (const lang of langsInvolved) {
|
|
587
603
|
await this.cache.clear(`${this.resourceConfig.resourceId}:frontend:${lang}`);
|
|
588
|
-
for (const
|
|
604
|
+
for (const { enStr, category } of Object.values(updateStrings)) {
|
|
589
605
|
await this.cache.clear(`${this.resourceConfig.resourceId}:${category}:${lang}:${enStr}`);
|
|
590
606
|
}
|
|
591
607
|
}
|
|
@@ -807,7 +823,7 @@ JSON.stringify(strings.reduce((acc: object, s: { en_string: string }): object =>
|
|
|
807
823
|
code: lang as LanguageCode,
|
|
808
824
|
nameOnNative: iso6391.getNativeName(lang),
|
|
809
825
|
nameEnglish: iso6391.getName(lang),
|
|
810
|
-
emojiFlag: lang.toUpperCase().replace(/./g, char => String.fromCodePoint(char.charCodeAt(0) + 127397)),
|
|
826
|
+
emojiFlag: getCountryCodeFromLangCode(lang).toUpperCase().replace(/./g, char => String.fromCodePoint(char.charCodeAt(0) + 127397)),
|
|
811
827
|
};
|
|
812
828
|
});
|
|
813
829
|
}
|