@adminforth/i18n 1.0.18-next.4 → 1.0.18-next.6
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 +9 -2
- package/index.ts +29 -16
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -13,6 +13,9 @@ import path from 'path';
|
|
|
13
13
|
import fs from 'fs-extra';
|
|
14
14
|
import chokidar from 'chokidar';
|
|
15
15
|
import { AsyncQueue } from '@sapphire/async-queue';
|
|
16
|
+
console.log = (...args) => {
|
|
17
|
+
process.stdout.write(args.join(" ") + "\n");
|
|
18
|
+
};
|
|
16
19
|
const processFrontendMessagesQueue = new AsyncQueue();
|
|
17
20
|
const SLAVIC_PLURAL_EXAMPLES = {
|
|
18
21
|
uk: 'яблук | Яблуко | Яблука | Яблук', // zero | singular | 2-4 | 5+
|
|
@@ -288,7 +291,7 @@ export default class I18N extends AdminForthPlugin {
|
|
|
288
291
|
return { ok: false, error: e.message };
|
|
289
292
|
}
|
|
290
293
|
}
|
|
291
|
-
process.env.HEAVY_DEBUG && console.log('🪲bulkTranslate done',
|
|
294
|
+
process.env.HEAVY_DEBUG && console.log('🪲bulkTranslate done', translatedCount);
|
|
292
295
|
this.updateUntranslatedMenuBadge();
|
|
293
296
|
return {
|
|
294
297
|
ok: true,
|
|
@@ -419,6 +422,7 @@ ${JSON.stringify(strings.reduce((acc, s) => {
|
|
|
419
422
|
});
|
|
420
423
|
const langsInvolved = new Set(Object.keys(needToTranslateByLang));
|
|
421
424
|
let totalTranslated = [];
|
|
425
|
+
process.env.HEAVY_DEBUG && console.log(' 🐛starting Promise.all Object.entries(needToTranslateByLang)');
|
|
422
426
|
yield Promise.all(Object.entries(needToTranslateByLang).map((_b) => __awaiter(this, [_b], void 0, function* ([lang, strings]) {
|
|
423
427
|
// first translate without plurals
|
|
424
428
|
const stringsWithoutPlurals = strings.filter(s => !s.en_string.includes('|'));
|
|
@@ -431,7 +435,7 @@ ${JSON.stringify(strings.reduce((acc, s) => {
|
|
|
431
435
|
process.env.HEAVY_DEBUG && console.log(`🔗 ${lang} plurals finished`);
|
|
432
436
|
totalTranslated = totalTranslated.concat(noPluralKeys, pluralKeys);
|
|
433
437
|
})));
|
|
434
|
-
process.env.HEAVY_DEBUG && console.log('updateStrings were formed', totalTranslated);
|
|
438
|
+
process.env.HEAVY_DEBUG && console.log('✅ updateStrings were formed', totalTranslated);
|
|
435
439
|
yield Promise.all(Object.entries(updateStrings).map((_c) => __awaiter(this, [_c], void 0, function* ([_, { updates, strId }]) {
|
|
436
440
|
// because this will translate all languages, we can set completedLangs to all languages
|
|
437
441
|
const futureCompletedFieldValue = this.fullCompleatedFieldValue;
|
|
@@ -515,6 +519,9 @@ ${JSON.stringify(strings.reduce((acc, s) => {
|
|
|
515
519
|
validateConfigAfterDiscover(adminforth, resourceConfig) {
|
|
516
520
|
// optional method where you can safely check field types after database discovery was performed
|
|
517
521
|
// ensure each trFieldName (apart from enFieldName) is nullable column of type string
|
|
522
|
+
if (this.options.completeAdapter) {
|
|
523
|
+
this.options.completeAdapter.validate();
|
|
524
|
+
}
|
|
518
525
|
for (const lang of this.options.supportedLanguages) {
|
|
519
526
|
if (lang === 'en') {
|
|
520
527
|
continue;
|
package/index.ts
CHANGED
|
@@ -7,6 +7,11 @@ import fs from 'fs-extra';
|
|
|
7
7
|
import chokidar from 'chokidar';
|
|
8
8
|
import { AsyncQueue } from '@sapphire/async-queue';
|
|
9
9
|
|
|
10
|
+
|
|
11
|
+
console.log = (...args) => {
|
|
12
|
+
process.stdout.write(args.join(" ") + "\n");
|
|
13
|
+
};
|
|
14
|
+
|
|
10
15
|
const processFrontendMessagesQueue = new AsyncQueue();
|
|
11
16
|
|
|
12
17
|
const SLAVIC_PLURAL_EXAMPLES = {
|
|
@@ -329,7 +334,7 @@ export default class I18N extends AdminForthPlugin {
|
|
|
329
334
|
return { ok: false, error: e.message };
|
|
330
335
|
}
|
|
331
336
|
}
|
|
332
|
-
process.env.HEAVY_DEBUG && console.log('🪲bulkTranslate done',
|
|
337
|
+
process.env.HEAVY_DEBUG && console.log('🪲bulkTranslate done', translatedCount);
|
|
333
338
|
this.updateUntranslatedMenuBadge();
|
|
334
339
|
return {
|
|
335
340
|
ok: true,
|
|
@@ -500,24 +505,30 @@ ${
|
|
|
500
505
|
const langsInvolved = new Set(Object.keys(needToTranslateByLang));
|
|
501
506
|
|
|
502
507
|
let totalTranslated = [];
|
|
503
|
-
|
|
504
|
-
// first translate without plurals
|
|
505
|
-
const stringsWithoutPlurals = strings.filter(s => !s.en_string.includes('|'));
|
|
506
|
-
process.env.HEAVY_DEBUG && console.log(`🔗 ${lang} noplurals started ${stringsWithoutPlurals.length}`);
|
|
507
|
-
const noPluralKeys = await translateToLang(lang, stringsWithoutPlurals, false);
|
|
508
|
-
process.env.HEAVY_DEBUG && console.log(`🔗 ${lang} noplurals finished`);
|
|
508
|
+
process.env.HEAVY_DEBUG && console.log(' 🐛starting Promise.all Object.entries(needToTranslateByLang)');
|
|
509
509
|
|
|
510
|
+
await Promise.all(
|
|
511
|
+
Object.entries(needToTranslateByLang).map(
|
|
512
|
+
async ([lang, strings]: [LanguageCode, { en_string: string, category: string }[]]) => {
|
|
513
|
+
// first translate without plurals
|
|
514
|
+
const stringsWithoutPlurals = strings.filter(s => !s.en_string.includes('|'));
|
|
515
|
+
process.env.HEAVY_DEBUG && console.log(`🔗 ${lang} noplurals started ${stringsWithoutPlurals.length}`);
|
|
516
|
+
const noPluralKeys = await translateToLang(lang, stringsWithoutPlurals, false);
|
|
517
|
+
process.env.HEAVY_DEBUG && console.log(`🔗 ${lang} noplurals finished`);
|
|
510
518
|
|
|
511
|
-
const stringsWithPlurals = strings.filter(s => s.en_string.includes('|'));
|
|
512
519
|
|
|
513
|
-
|
|
514
|
-
const pluralKeys = await translateToLang(lang, stringsWithPlurals, true);
|
|
515
|
-
process.env.HEAVY_DEBUG && console.log(`🔗 ${lang} plurals finished`);
|
|
520
|
+
const stringsWithPlurals = strings.filter(s => s.en_string.includes('|'));
|
|
516
521
|
|
|
517
|
-
|
|
518
|
-
|
|
522
|
+
process.env.HEAVY_DEBUG && console.log(`🔗 ${lang} plurals started ${stringsWithPlurals.length}`);
|
|
523
|
+
const pluralKeys = await translateToLang(lang, stringsWithPlurals, true);
|
|
524
|
+
process.env.HEAVY_DEBUG && console.log(`🔗 ${lang} plurals finished`);
|
|
525
|
+
|
|
526
|
+
totalTranslated = totalTranslated.concat(noPluralKeys, pluralKeys);
|
|
527
|
+
}
|
|
528
|
+
)
|
|
529
|
+
);
|
|
519
530
|
|
|
520
|
-
process.env.HEAVY_DEBUG && console.log('updateStrings were formed', totalTranslated);
|
|
531
|
+
process.env.HEAVY_DEBUG && console.log('✅ updateStrings were formed', totalTranslated);
|
|
521
532
|
|
|
522
533
|
await Promise.all(
|
|
523
534
|
Object.entries(updateStrings).map(
|
|
@@ -607,12 +618,10 @@ ${
|
|
|
607
618
|
});
|
|
608
619
|
w.on('change', () => {
|
|
609
620
|
process.env.HEAVY_DEBUG && console.log('🪲🔔messagesFile change', messagesFile);
|
|
610
|
-
|
|
611
621
|
this.processExtractedMessages(adminforth, messagesFile);
|
|
612
622
|
});
|
|
613
623
|
w.on('add', () => {
|
|
614
624
|
process.env.HEAVY_DEBUG && console.log('🪲🔔messagesFile add', messagesFile);
|
|
615
|
-
|
|
616
625
|
this.processExtractedMessages(adminforth, messagesFile);
|
|
617
626
|
});
|
|
618
627
|
|
|
@@ -621,6 +630,10 @@ ${
|
|
|
621
630
|
validateConfigAfterDiscover(adminforth: IAdminForth, resourceConfig: AdminForthResource) {
|
|
622
631
|
// optional method where you can safely check field types after database discovery was performed
|
|
623
632
|
// ensure each trFieldName (apart from enFieldName) is nullable column of type string
|
|
633
|
+
if (this.options.completeAdapter) {
|
|
634
|
+
this.options.completeAdapter.validate();
|
|
635
|
+
}
|
|
636
|
+
|
|
624
637
|
for (const lang of this.options.supportedLanguages) {
|
|
625
638
|
if (lang === 'en') {
|
|
626
639
|
continue;
|