@adminforth/i18n 1.0.18-next.2 → 1.0.18-next.4
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 +12 -5
- package/index.ts +18 -6
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -141,6 +141,7 @@ export default class I18N extends AdminForthPlugin {
|
|
|
141
141
|
if (!enColumn) {
|
|
142
142
|
throw new Error(`Field ${this.enFieldName} not found column to store english original string in resource ${resourceConfig.resourceId}`);
|
|
143
143
|
}
|
|
144
|
+
enColumn.editReadonly = true;
|
|
144
145
|
// if sourceFieldName defined, check it exists
|
|
145
146
|
if (this.options.sourceFieldName) {
|
|
146
147
|
if (!resourceConfig.columns.find(c => c.name === this.options.sourceFieldName)) {
|
|
@@ -290,7 +291,8 @@ export default class I18N extends AdminForthPlugin {
|
|
|
290
291
|
process.env.HEAVY_DEBUG && console.log('🪲bulkTranslate done', selectedIds);
|
|
291
292
|
this.updateUntranslatedMenuBadge();
|
|
292
293
|
return {
|
|
293
|
-
ok: true,
|
|
294
|
+
ok: true,
|
|
295
|
+
error: undefined,
|
|
294
296
|
successMessage: yield tr(`Translated {count} items`, 'backend', {
|
|
295
297
|
count: translatedCount,
|
|
296
298
|
}),
|
|
@@ -375,10 +377,10 @@ ${JSON.stringify(strings.reduce((acc, s) => {
|
|
|
375
377
|
}, {}), null, 2)}
|
|
376
378
|
\`\`\`
|
|
377
379
|
`;
|
|
378
|
-
process.env.HEAVY_DEBUG && console.log('🧠 llm prompt', prompt);
|
|
380
|
+
// process.env.HEAVY_DEBUG && console.log('🧠 llm prompt', prompt);
|
|
379
381
|
// call OpenAI
|
|
380
382
|
const resp = yield this.options.completeAdapter.complete(prompt, [], 300);
|
|
381
|
-
process.env.HEAVY_DEBUG && console.log('🧠 llm resp', resp);
|
|
383
|
+
// process.env.HEAVY_DEBUG && console.log('🧠 llm resp', resp);
|
|
382
384
|
if (resp.error) {
|
|
383
385
|
throw new AiTranslateError(resp.error);
|
|
384
386
|
}
|
|
@@ -420,20 +422,25 @@ ${JSON.stringify(strings.reduce((acc, s) => {
|
|
|
420
422
|
yield Promise.all(Object.entries(needToTranslateByLang).map((_b) => __awaiter(this, [_b], void 0, function* ([lang, strings]) {
|
|
421
423
|
// first translate without plurals
|
|
422
424
|
const stringsWithoutPlurals = strings.filter(s => !s.en_string.includes('|'));
|
|
425
|
+
process.env.HEAVY_DEBUG && console.log(`🔗 ${lang} noplurals started ${stringsWithoutPlurals.length}`);
|
|
423
426
|
const noPluralKeys = yield translateToLang(lang, stringsWithoutPlurals, false);
|
|
427
|
+
process.env.HEAVY_DEBUG && console.log(`🔗 ${lang} noplurals finished`);
|
|
424
428
|
const stringsWithPlurals = strings.filter(s => s.en_string.includes('|'));
|
|
429
|
+
process.env.HEAVY_DEBUG && console.log(`🔗 ${lang} plurals started ${stringsWithPlurals.length}`);
|
|
425
430
|
const pluralKeys = yield translateToLang(lang, stringsWithPlurals, true);
|
|
431
|
+
process.env.HEAVY_DEBUG && console.log(`🔗 ${lang} plurals finished`);
|
|
426
432
|
totalTranslated = totalTranslated.concat(noPluralKeys, pluralKeys);
|
|
427
433
|
})));
|
|
434
|
+
process.env.HEAVY_DEBUG && console.log('updateStrings were formed', totalTranslated);
|
|
428
435
|
yield Promise.all(Object.entries(updateStrings).map((_c) => __awaiter(this, [_c], void 0, function* ([_, { updates, strId }]) {
|
|
429
436
|
// because this will translate all languages, we can set completedLangs to all languages
|
|
430
437
|
const futureCompletedFieldValue = this.fullCompleatedFieldValue;
|
|
431
438
|
yield this.adminforth.resource(this.resourceConfig.resourceId).update(strId, Object.assign(Object.assign({}, updates), { [this.options.completedFieldName]: futureCompletedFieldValue }));
|
|
432
439
|
})));
|
|
433
440
|
for (const lang of langsInvolved) {
|
|
434
|
-
this.cache.clear(`${this.resourceConfig.resourceId}:frontend:${lang}`);
|
|
441
|
+
yield this.cache.clear(`${this.resourceConfig.resourceId}:frontend:${lang}`);
|
|
435
442
|
for (const [enStr, { category }] of Object.entries(updateStrings)) {
|
|
436
|
-
this.cache.clear(`${this.resourceConfig.resourceId}:${category}:${lang}:${enStr}`);
|
|
443
|
+
yield this.cache.clear(`${this.resourceConfig.resourceId}:${category}:${lang}:${enStr}`);
|
|
437
444
|
}
|
|
438
445
|
}
|
|
439
446
|
return new Set(totalTranslated).size;
|
package/index.ts
CHANGED
|
@@ -156,6 +156,8 @@ export default class I18N extends AdminForthPlugin {
|
|
|
156
156
|
throw new Error(`Field ${this.enFieldName} not found column to store english original string in resource ${resourceConfig.resourceId}`);
|
|
157
157
|
}
|
|
158
158
|
|
|
159
|
+
enColumn.editReadonly = true;
|
|
160
|
+
|
|
159
161
|
// if sourceFieldName defined, check it exists
|
|
160
162
|
if (this.options.sourceFieldName) {
|
|
161
163
|
if (!resourceConfig.columns.find(c => c.name === this.options.sourceFieldName)) {
|
|
@@ -330,7 +332,8 @@ export default class I18N extends AdminForthPlugin {
|
|
|
330
332
|
process.env.HEAVY_DEBUG && console.log('🪲bulkTranslate done', selectedIds);
|
|
331
333
|
this.updateUntranslatedMenuBadge();
|
|
332
334
|
return {
|
|
333
|
-
ok: true,
|
|
335
|
+
ok: true,
|
|
336
|
+
error: undefined,
|
|
334
337
|
successMessage: await tr(`Translated {count} items`, 'backend', {
|
|
335
338
|
count: translatedCount,
|
|
336
339
|
}),
|
|
@@ -440,7 +443,7 @@ ${
|
|
|
440
443
|
\`\`\`
|
|
441
444
|
`;
|
|
442
445
|
|
|
443
|
-
process.env.HEAVY_DEBUG && console.log('🧠 llm prompt', prompt);
|
|
446
|
+
// process.env.HEAVY_DEBUG && console.log('🧠 llm prompt', prompt);
|
|
444
447
|
|
|
445
448
|
// call OpenAI
|
|
446
449
|
const resp = await this.options.completeAdapter.complete(
|
|
@@ -449,7 +452,7 @@ ${
|
|
|
449
452
|
300,
|
|
450
453
|
);
|
|
451
454
|
|
|
452
|
-
process.env.HEAVY_DEBUG && console.log('🧠 llm resp', resp);
|
|
455
|
+
// process.env.HEAVY_DEBUG && console.log('🧠 llm resp', resp);
|
|
453
456
|
|
|
454
457
|
if (resp.error) {
|
|
455
458
|
throw new AiTranslateError(resp.error);
|
|
@@ -500,12 +503,21 @@ ${
|
|
|
500
503
|
await Promise.all(Object.entries(needToTranslateByLang).map(async ([lang, strings]: [LanguageCode, { en_string: string, category: string }[]]) => {
|
|
501
504
|
// first translate without plurals
|
|
502
505
|
const stringsWithoutPlurals = strings.filter(s => !s.en_string.includes('|'));
|
|
506
|
+
process.env.HEAVY_DEBUG && console.log(`🔗 ${lang} noplurals started ${stringsWithoutPlurals.length}`);
|
|
503
507
|
const noPluralKeys = await translateToLang(lang, stringsWithoutPlurals, false);
|
|
508
|
+
process.env.HEAVY_DEBUG && console.log(`🔗 ${lang} noplurals finished`);
|
|
509
|
+
|
|
504
510
|
|
|
505
511
|
const stringsWithPlurals = strings.filter(s => s.en_string.includes('|'));
|
|
512
|
+
|
|
513
|
+
process.env.HEAVY_DEBUG && console.log(`🔗 ${lang} plurals started ${stringsWithPlurals.length}`);
|
|
506
514
|
const pluralKeys = await translateToLang(lang, stringsWithPlurals, true);
|
|
515
|
+
process.env.HEAVY_DEBUG && console.log(`🔗 ${lang} plurals finished`);
|
|
516
|
+
|
|
507
517
|
totalTranslated = totalTranslated.concat(noPluralKeys, pluralKeys);
|
|
508
|
-
}));
|
|
518
|
+
}));
|
|
519
|
+
|
|
520
|
+
process.env.HEAVY_DEBUG && console.log('updateStrings were formed', totalTranslated);
|
|
509
521
|
|
|
510
522
|
await Promise.all(
|
|
511
523
|
Object.entries(updateStrings).map(
|
|
@@ -522,9 +534,9 @@ ${
|
|
|
522
534
|
);
|
|
523
535
|
|
|
524
536
|
for (const lang of langsInvolved) {
|
|
525
|
-
this.cache.clear(`${this.resourceConfig.resourceId}:frontend:${lang}`);
|
|
537
|
+
await this.cache.clear(`${this.resourceConfig.resourceId}:frontend:${lang}`);
|
|
526
538
|
for (const [enStr, { category }] of Object.entries(updateStrings)) {
|
|
527
|
-
this.cache.clear(`${this.resourceConfig.resourceId}:${category}:${lang}:${enStr}`);
|
|
539
|
+
await this.cache.clear(`${this.resourceConfig.resourceId}:${category}:${lang}:${enStr}`);
|
|
528
540
|
}
|
|
529
541
|
}
|
|
530
542
|
|