@adminforth/i18n 1.0.17-next.0 → 1.0.18-next.2
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 +10 -8
- package/index.ts +11 -9
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -349,14 +349,15 @@ export default class I18N extends AdminForthPlugin {
|
|
|
349
349
|
const updateStrings = {};
|
|
350
350
|
const translateToLang = (langIsoCode_1, strings_1, ...args_1) => __awaiter(this, [langIsoCode_1, strings_1, ...args_1], void 0, function* (langIsoCode, strings, plurals = false) {
|
|
351
351
|
if (strings.length === 0) {
|
|
352
|
-
return
|
|
352
|
+
return [];
|
|
353
353
|
}
|
|
354
354
|
if (strings.length > maxKeysInOneReq) {
|
|
355
|
-
let totalTranslated =
|
|
355
|
+
let totalTranslated = [];
|
|
356
356
|
for (let i = 0; i < strings.length; i += maxKeysInOneReq) {
|
|
357
357
|
const slicedStrings = strings.slice(i, i + maxKeysInOneReq);
|
|
358
358
|
process.env.HEAVY_DEBUG && console.log('🪲🔪slicedStrings len', slicedStrings.length);
|
|
359
|
-
|
|
359
|
+
const madeKeys = yield translateToLang(langIsoCode, slicedStrings, plurals);
|
|
360
|
+
totalTranslated = totalTranslated.concat(madeKeys);
|
|
360
361
|
}
|
|
361
362
|
return totalTranslated;
|
|
362
363
|
}
|
|
@@ -412,16 +413,17 @@ ${JSON.stringify(strings.reduce((acc, s) => {
|
|
|
412
413
|
updateStrings[translation[this.primaryKeyFieldName]].updates[this.trFieldNames[lang]] = translatedStr;
|
|
413
414
|
}
|
|
414
415
|
}
|
|
415
|
-
return Object.keys(updateStrings)
|
|
416
|
+
return Object.keys(updateStrings);
|
|
416
417
|
});
|
|
417
418
|
const langsInvolved = new Set(Object.keys(needToTranslateByLang));
|
|
418
|
-
let totalTranslated =
|
|
419
|
+
let totalTranslated = [];
|
|
419
420
|
yield Promise.all(Object.entries(needToTranslateByLang).map((_b) => __awaiter(this, [_b], void 0, function* ([lang, strings]) {
|
|
420
421
|
// first translate without plurals
|
|
421
422
|
const stringsWithoutPlurals = strings.filter(s => !s.en_string.includes('|'));
|
|
422
|
-
|
|
423
|
+
const noPluralKeys = yield translateToLang(lang, stringsWithoutPlurals, false);
|
|
423
424
|
const stringsWithPlurals = strings.filter(s => s.en_string.includes('|'));
|
|
424
|
-
|
|
425
|
+
const pluralKeys = yield translateToLang(lang, stringsWithPlurals, true);
|
|
426
|
+
totalTranslated = totalTranslated.concat(noPluralKeys, pluralKeys);
|
|
425
427
|
})));
|
|
426
428
|
yield Promise.all(Object.entries(updateStrings).map((_c) => __awaiter(this, [_c], void 0, function* ([_, { updates, strId }]) {
|
|
427
429
|
// because this will translate all languages, we can set completedLangs to all languages
|
|
@@ -434,7 +436,7 @@ ${JSON.stringify(strings.reduce((acc, s) => {
|
|
|
434
436
|
this.cache.clear(`${this.resourceConfig.resourceId}:${category}:${lang}:${enStr}`);
|
|
435
437
|
}
|
|
436
438
|
}
|
|
437
|
-
return totalTranslated;
|
|
439
|
+
return new Set(totalTranslated).size;
|
|
438
440
|
});
|
|
439
441
|
}
|
|
440
442
|
processExtractedMessages(adminforth, filePath) {
|
package/index.ts
CHANGED
|
@@ -406,17 +406,18 @@ export default class I18N extends AdminForthPlugin {
|
|
|
406
406
|
translatedStr: string
|
|
407
407
|
}> = {};
|
|
408
408
|
|
|
409
|
-
const translateToLang = async (langIsoCode: LanguageCode, strings: { en_string: string, category: string }[], plurals=false): Promise<
|
|
409
|
+
const translateToLang = async (langIsoCode: LanguageCode, strings: { en_string: string, category: string }[], plurals=false): Promise<string[]> => {
|
|
410
410
|
if (strings.length === 0) {
|
|
411
|
-
return
|
|
411
|
+
return [];
|
|
412
412
|
}
|
|
413
413
|
|
|
414
414
|
if (strings.length > maxKeysInOneReq) {
|
|
415
|
-
let totalTranslated =
|
|
415
|
+
let totalTranslated = [];
|
|
416
416
|
for (let i = 0; i < strings.length; i += maxKeysInOneReq) {
|
|
417
417
|
const slicedStrings = strings.slice(i, i + maxKeysInOneReq);
|
|
418
418
|
process.env.HEAVY_DEBUG && console.log('🪲🔪slicedStrings len', slicedStrings.length);
|
|
419
|
-
|
|
419
|
+
const madeKeys = await translateToLang(langIsoCode, slicedStrings, plurals);
|
|
420
|
+
totalTranslated = totalTranslated.concat(madeKeys);
|
|
420
421
|
}
|
|
421
422
|
return totalTranslated;
|
|
422
423
|
}
|
|
@@ -490,19 +491,20 @@ ${
|
|
|
490
491
|
}
|
|
491
492
|
}
|
|
492
493
|
|
|
493
|
-
return Object.keys(updateStrings)
|
|
494
|
+
return Object.keys(updateStrings);
|
|
494
495
|
}
|
|
495
496
|
|
|
496
497
|
const langsInvolved = new Set(Object.keys(needToTranslateByLang));
|
|
497
498
|
|
|
498
|
-
let totalTranslated =
|
|
499
|
+
let totalTranslated = [];
|
|
499
500
|
await Promise.all(Object.entries(needToTranslateByLang).map(async ([lang, strings]: [LanguageCode, { en_string: string, category: string }[]]) => {
|
|
500
501
|
// first translate without plurals
|
|
501
502
|
const stringsWithoutPlurals = strings.filter(s => !s.en_string.includes('|'));
|
|
502
|
-
|
|
503
|
+
const noPluralKeys = await translateToLang(lang, stringsWithoutPlurals, false);
|
|
503
504
|
|
|
504
505
|
const stringsWithPlurals = strings.filter(s => s.en_string.includes('|'));
|
|
505
|
-
|
|
506
|
+
const pluralKeys = await translateToLang(lang, stringsWithPlurals, true);
|
|
507
|
+
totalTranslated = totalTranslated.concat(noPluralKeys, pluralKeys);
|
|
506
508
|
}));
|
|
507
509
|
|
|
508
510
|
await Promise.all(
|
|
@@ -526,7 +528,7 @@ ${
|
|
|
526
528
|
}
|
|
527
529
|
}
|
|
528
530
|
|
|
529
|
-
return totalTranslated;
|
|
531
|
+
return new Set(totalTranslated).size;
|
|
530
532
|
|
|
531
533
|
}
|
|
532
534
|
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adminforth/i18n",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.18-next.2",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"scripts": {
|
|
8
|
-
"build": "tsc && rsync -av --exclude 'node_modules' custom dist/
|
|
9
|
-
"rollout": "npm run build && npm publish --access public",
|
|
8
|
+
"build": "tsc && rsync -av --exclude 'node_modules' custom dist/",
|
|
9
|
+
"rollout": "npm run build && npm version patch && npm publish --access public",
|
|
10
10
|
"rollout-next": "npm run build && npm version prerelease --preid=next && npm publish --tag next",
|
|
11
11
|
"prepare": "npm link adminforth"
|
|
12
12
|
},
|