@taon-dev/i18n 21.0.50 → 21.0.53
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/VERIFIED-BUILD-DATA.jsonc +3 -3
- package/browser/fesm2022/i18n-browser.mjs +91 -6
- package/browser/fesm2022/i18n-browser.mjs.map +1 -1
- package/browser/package.json +1 -1
- package/browser/types/i18n-browser.d.ts +11 -26
- package/browser-prod/fesm2022/i18n-browser-prod.mjs +91 -6
- package/browser-prod/fesm2022/i18n-browser-prod.mjs.map +1 -1
- package/browser-prod/package.json +1 -1
- package/browser-prod/types/i18n-browser-prod.d.ts +11 -26
- package/full-dts/build-info._auto-generated_.d.ts +1 -1
- package/full-dts/index._auto-generated_.d.ts +1 -2
- package/full-dts/local-translation.d.ts +8 -1
- package/lib/build-info._auto-generated_.d.ts +1 -1
- package/lib/build-info._auto-generated_.js +1 -1
- package/lib/index._auto-generated_.d.ts +0 -1
- package/lib/index._auto-generated_.js +0 -1
- package/lib/index._auto-generated_.js.map +1 -1
- package/lib/local-translation.d.ts +8 -1
- package/lib/local-translation.js +93 -6
- package/lib/local-translation.js.map +1 -1
- package/lib/package.json +1 -1
- package/lib-esm/lib/build-info._auto-generated_.d.ts +1 -1
- package/lib-esm/lib/build-info._auto-generated_.js +1 -1
- package/lib-esm/lib/index._auto-generated_.d.ts +0 -1
- package/lib-esm/lib/index._auto-generated_.js +0 -1
- package/lib-esm/lib/index._auto-generated_.js.map +1 -1
- package/lib-esm/lib/local-translation.d.ts +8 -1
- package/lib-esm/lib/local-translation.js +93 -8
- package/lib-esm/lib/local-translation.js.map +1 -1
- package/lib-prod/build-info._auto-generated_.d.ts +1 -1
- package/lib-prod/build-info._auto-generated_.js +1 -1
- package/lib-prod/index._auto-generated_.d.ts +0 -1
- package/lib-prod/index._auto-generated_.js +0 -1
- package/lib-prod/index._auto-generated_.js.map +1 -1
- package/lib-prod/local-translation.d.ts +8 -1
- package/lib-prod/local-translation.js +93 -6
- package/lib-prod/local-translation.js.map +1 -1
- package/lib-prod/package.json +1 -1
- package/package.json +1 -1
- package/ts-source/browser-code/build-info._auto-generated_.ts +2 -2
- package/ts-source/browser-code/i18n/lib.translation.ts +1 -1
- package/ts-source/browser-code/i18n/translation.ts.en-US.i18n.data.ts +1 -1
- package/ts-source/browser-code/i18n/translation.ts.pl-PL.i18n.data.ts +1 -1
- package/ts-source/browser-code/index._auto-generated_.ts +1 -2
- package/ts-source/browser-code/index.scss +1 -1
- package/ts-source/browser-code/index.ts +1 -1
- package/ts-source/browser-code/local-translation.ts +36 -1
- package/ts-source/browser-code/start-cli.ts +1 -1
- package/ts-source/browser-code/translate.directive.ts +1 -1
- package/ts-source/browser-code/translate.pipe.ts +1 -1
- package/ts-source/browser-code/translate.service.ts +1 -1
- package/ts-source/browser-code/translation-manager.ts +1 -1
- package/ts-source/browser-code/translation.models.ts +1 -1
- package/ts-source/browser-code/translation.ts +1 -1
- package/ts-source/browser-code/utils-i18n-extract-gettext-translate-from-html.ts +1 -1
- package/ts-source/browser-code/utils-i18n-html.ts +1 -1
- package/ts-source/browser-code/utils-po-file.ts +1 -1
- package/ts-source/browser-code-prod/build-info._auto-generated_.ts +2 -2
- package/ts-source/browser-code-prod/i18n/lib.translation.ts +1 -1
- package/ts-source/browser-code-prod/i18n/translation.ts.en-US.i18n.data.ts +1 -1
- package/ts-source/browser-code-prod/i18n/translation.ts.pl-PL.i18n.data.ts +1 -1
- package/ts-source/browser-code-prod/index._auto-generated_.ts +1 -2
- package/ts-source/browser-code-prod/index.scss +1 -1
- package/ts-source/browser-code-prod/index.ts +1 -1
- package/ts-source/browser-code-prod/local-translation.ts +36 -1
- package/ts-source/browser-code-prod/start-cli.ts +1 -1
- package/ts-source/browser-code-prod/translate.directive.ts +1 -1
- package/ts-source/browser-code-prod/translate.pipe.ts +1 -1
- package/ts-source/browser-code-prod/translate.service.ts +1 -1
- package/ts-source/browser-code-prod/translation-manager.ts +1 -1
- package/ts-source/browser-code-prod/translation.models.ts +1 -1
- package/ts-source/browser-code-prod/translation.ts +1 -1
- package/ts-source/browser-code-prod/utils-i18n-extract-gettext-translate-from-html.ts +1 -1
- package/ts-source/browser-code-prod/utils-i18n-html.ts +1 -1
- package/ts-source/browser-code-prod/utils-po-file.ts +1 -1
- package/ts-source/websql-code/build-info._auto-generated_.ts +2 -2
- package/ts-source/websql-code/i18n/lib.translation.ts +1 -1
- package/ts-source/websql-code/i18n/translation.ts.en-US.i18n.data.ts +1 -1
- package/ts-source/websql-code/i18n/translation.ts.pl-PL.i18n.data.ts +1 -1
- package/ts-source/websql-code/index._auto-generated_.ts +1 -2
- package/ts-source/websql-code/index.scss +1 -1
- package/ts-source/websql-code/index.ts +1 -1
- package/ts-source/websql-code/local-translation.ts +36 -1
- package/ts-source/websql-code/start-cli.ts +1 -1
- package/ts-source/websql-code/translate.directive.ts +1 -1
- package/ts-source/websql-code/translate.pipe.ts +1 -1
- package/ts-source/websql-code/translate.service.ts +1 -1
- package/ts-source/websql-code/translation-manager.ts +1 -1
- package/ts-source/websql-code/translation.models.ts +1 -1
- package/ts-source/websql-code/translation.ts +1 -1
- package/ts-source/websql-code/utils-i18n-extract-gettext-translate-from-html.ts +1 -1
- package/ts-source/websql-code/utils-i18n-html.ts +1 -1
- package/ts-source/websql-code/utils-po-file.ts +1 -1
- package/ts-source/websql-code-prod/build-info._auto-generated_.ts +2 -2
- package/ts-source/websql-code-prod/i18n/lib.translation.ts +1 -1
- package/ts-source/websql-code-prod/i18n/translation.ts.en-US.i18n.data.ts +1 -1
- package/ts-source/websql-code-prod/i18n/translation.ts.pl-PL.i18n.data.ts +1 -1
- package/ts-source/websql-code-prod/index._auto-generated_.ts +1 -2
- package/ts-source/websql-code-prod/index.scss +1 -1
- package/ts-source/websql-code-prod/index.ts +1 -1
- package/ts-source/websql-code-prod/local-translation.ts +36 -1
- package/ts-source/websql-code-prod/start-cli.ts +1 -1
- package/ts-source/websql-code-prod/translate.directive.ts +1 -1
- package/ts-source/websql-code-prod/translate.pipe.ts +1 -1
- package/ts-source/websql-code-prod/translate.service.ts +1 -1
- package/ts-source/websql-code-prod/translation-manager.ts +1 -1
- package/ts-source/websql-code-prod/translation.models.ts +1 -1
- package/ts-source/websql-code-prod/translation.ts +1 -1
- package/ts-source/websql-code-prod/utils-i18n-extract-gettext-translate-from-html.ts +1 -1
- package/ts-source/websql-code-prod/utils-i18n-html.ts +1 -1
- package/ts-source/websql-code-prod/utils-po-file.ts +1 -1
- package/websql/fesm2022/i18n-websql.mjs +91 -6
- package/websql/fesm2022/i18n-websql.mjs.map +1 -1
- package/websql/package.json +1 -1
- package/websql/types/i18n-websql.d.ts +11 -26
- package/websql-prod/fesm2022/i18n-websql-prod.mjs +91 -6
- package/websql-prod/fesm2022/i18n-websql-prod.mjs.map +1 -1
- package/websql-prod/package.json +1 -1
- package/websql-prod/types/i18n-websql-prod.d.ts +11 -26
|
@@ -1,21 +1,29 @@
|
|
|
1
|
+
//#region imports
|
|
1
2
|
import { crossPlatformPath, dotTaonFolder, ___NS__first, Helpers__NS__mkdirp, UtilsOs__NS__getRealHomeDir } from 'tnp-core/lib-prod';
|
|
3
|
+
//#endregion
|
|
4
|
+
//#region constants
|
|
2
5
|
const MODEL_ID = 'Xenova/nllb-200-distilled-600M';
|
|
3
6
|
const nllbLanguageCodes = {
|
|
4
7
|
'en-US': 'eng_Latn',
|
|
5
8
|
'pl-PL': 'pol_Latn',
|
|
6
9
|
'de-DE': 'deu_Latn',
|
|
7
10
|
};
|
|
11
|
+
const CONTEXT_SEPARATOR = '→';
|
|
12
|
+
//#endregion
|
|
8
13
|
export class LocalTranslationService {
|
|
14
|
+
//#region fields & getters
|
|
9
15
|
translatorPromise;
|
|
10
16
|
aiReady = false;
|
|
11
17
|
warmupPromise;
|
|
12
18
|
progressListeners = new Set();
|
|
19
|
+
//#endregion
|
|
13
20
|
/**
|
|
14
21
|
* Downloads, caches and loads the translation model.
|
|
15
22
|
*
|
|
16
23
|
* Multiple simultaneous calls share the same initialization promise.
|
|
17
24
|
* After this resolves, translate() reuses the already loaded model.
|
|
18
25
|
*/
|
|
26
|
+
//#region methods / make sure ai downloaded
|
|
19
27
|
async makeSureAiDownloaded(options = {}) {
|
|
20
28
|
//#region @backendFunc
|
|
21
29
|
const { onProgress, warmup = false } = options;
|
|
@@ -35,12 +43,16 @@ export class LocalTranslationService {
|
|
|
35
43
|
}
|
|
36
44
|
//#endregion
|
|
37
45
|
}
|
|
46
|
+
//#endregion
|
|
38
47
|
/**
|
|
39
48
|
* True only in this process after pipeline initialization succeeded.
|
|
40
49
|
*/
|
|
50
|
+
//#region methods / is ai ready
|
|
41
51
|
isAiReady() {
|
|
42
52
|
return this.aiReady;
|
|
43
53
|
}
|
|
54
|
+
//#endregion
|
|
55
|
+
//#region methods / get translator
|
|
44
56
|
getTranslator() {
|
|
45
57
|
this.translatorPromise ??= this.createTranslator().catch(error => {
|
|
46
58
|
// Allow a later call to retry after a network or disk failure.
|
|
@@ -50,6 +62,8 @@ export class LocalTranslationService {
|
|
|
50
62
|
});
|
|
51
63
|
return this.translatorPromise;
|
|
52
64
|
}
|
|
65
|
+
//#endregion
|
|
66
|
+
//#region methods / create translator
|
|
53
67
|
async createTranslator() {
|
|
54
68
|
//#region @backendFunc
|
|
55
69
|
//#region @esmRemove
|
|
@@ -71,6 +85,8 @@ export class LocalTranslationService {
|
|
|
71
85
|
//#endregion
|
|
72
86
|
return void 0;
|
|
73
87
|
}
|
|
88
|
+
//#endregion
|
|
89
|
+
//#region methods / emit progress
|
|
74
90
|
emitProgress(progress) {
|
|
75
91
|
for (const listener of this.progressListeners) {
|
|
76
92
|
try {
|
|
@@ -81,6 +97,8 @@ export class LocalTranslationService {
|
|
|
81
97
|
}
|
|
82
98
|
}
|
|
83
99
|
}
|
|
100
|
+
//#endregion
|
|
101
|
+
//#region methods / warmup translator
|
|
84
102
|
warmupTranslator(translator) {
|
|
85
103
|
this.warmupPromise ??= translator('Hello.', {
|
|
86
104
|
src_lang: 'eng_Latn',
|
|
@@ -94,6 +112,8 @@ export class LocalTranslationService {
|
|
|
94
112
|
});
|
|
95
113
|
return this.warmupPromise;
|
|
96
114
|
}
|
|
115
|
+
//#endregion
|
|
116
|
+
//#region methods / translate
|
|
97
117
|
async translate(options) {
|
|
98
118
|
//#region @backendFunc
|
|
99
119
|
let { text, context, from, to, glossary } = options;
|
|
@@ -112,19 +132,54 @@ export class LocalTranslationService {
|
|
|
112
132
|
if (!tgtLang) {
|
|
113
133
|
throw new Error(`Unsupported target translation locale: ${toOrg}`);
|
|
114
134
|
}
|
|
115
|
-
|
|
116
|
-
|
|
135
|
+
/**
|
|
136
|
+
* Context is included so NLLB can use it while translating,
|
|
137
|
+
* but only content after CONTEXT_SEPARATOR is returned.
|
|
138
|
+
*/
|
|
139
|
+
const hasContext = !!context?.trim();
|
|
140
|
+
const input = hasContext
|
|
141
|
+
? `${context.trim()}\n\n${CONTEXT_SEPARATOR}\n\n${text.trim()}`
|
|
117
142
|
: text;
|
|
118
|
-
|
|
143
|
+
/**
|
|
144
|
+
* Protect [[ ... ]] before doing glossary substitutions.
|
|
145
|
+
*
|
|
146
|
+
* This is intentionally first so glossary entries can never
|
|
147
|
+
* accidentally modify interpolation expressions.
|
|
148
|
+
*/
|
|
149
|
+
const protectedInterpolation = this.protectInterpolation(input);
|
|
150
|
+
const protectedGlossary = this.protectGlossary(protectedInterpolation.preparedText, glossary);
|
|
119
151
|
const translator = await this.getTranslator();
|
|
120
|
-
const result = await translator(
|
|
152
|
+
const result = await translator(protectedGlossary.preparedText, {
|
|
121
153
|
src_lang: srcLang,
|
|
122
154
|
tgt_lang: tgtLang,
|
|
123
155
|
});
|
|
124
|
-
|
|
125
|
-
|
|
156
|
+
let translatedText = result[0]?.translation_text ?? '';
|
|
157
|
+
/**
|
|
158
|
+
* Restore glossary values first, then interpolation expressions.
|
|
159
|
+
*/
|
|
160
|
+
translatedText = protectedGlossary.restore(translatedText);
|
|
161
|
+
translatedText = protectedInterpolation.restore(translatedText);
|
|
162
|
+
/**
|
|
163
|
+
* Remove translated context from the final result.
|
|
164
|
+
*/
|
|
165
|
+
if (hasContext) {
|
|
166
|
+
const separatorIndex = translatedText.lastIndexOf('→');
|
|
167
|
+
if (separatorIndex !== -1) {
|
|
168
|
+
translatedText = translatedText.slice(separatorIndex + 1).trim();
|
|
169
|
+
}
|
|
170
|
+
else {
|
|
171
|
+
// separator disappeared — never return context accidentally
|
|
172
|
+
return this.translate({
|
|
173
|
+
...options,
|
|
174
|
+
context: undefined,
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
return translatedText;
|
|
126
179
|
//#endregion
|
|
127
180
|
}
|
|
181
|
+
//#endregion
|
|
182
|
+
//#region methods / protect glossary
|
|
128
183
|
protectGlossary(text, glossary) {
|
|
129
184
|
if (!glossary || Object.keys(glossary).length === 0) {
|
|
130
185
|
return {
|
|
@@ -155,6 +210,38 @@ export class LocalTranslationService {
|
|
|
155
210
|
},
|
|
156
211
|
};
|
|
157
212
|
}
|
|
213
|
+
//#endregion
|
|
214
|
+
//#region methods / protect interpolation
|
|
215
|
+
protectInterpolation(text) {
|
|
216
|
+
const replacements = [];
|
|
217
|
+
const preparedText = text.replace(/\[\[[\s\S]*?\]\]/g, originalValue => {
|
|
218
|
+
const placeholder = `TAONINTERPOLATION${replacements.length}PLACEHOLDER`;
|
|
219
|
+
replacements.push({
|
|
220
|
+
placeholder,
|
|
221
|
+
originalValue,
|
|
222
|
+
});
|
|
223
|
+
return placeholder;
|
|
224
|
+
});
|
|
225
|
+
return {
|
|
226
|
+
preparedText,
|
|
227
|
+
restore(translatedText) {
|
|
228
|
+
let result = translatedText;
|
|
229
|
+
for (const replacement of replacements) {
|
|
230
|
+
if (!result.includes(replacement.placeholder)) {
|
|
231
|
+
console.error(`Translation model removed interpolation placeholder ` +
|
|
232
|
+
`"${replacement.placeholder}" while translating "${text}". ` +
|
|
233
|
+
`Appending "${replacement.originalValue}" manually.`);
|
|
234
|
+
result = `${result.trimEnd()} ${replacement.originalValue}`;
|
|
235
|
+
continue;
|
|
236
|
+
}
|
|
237
|
+
result = result.replaceAll(replacement.placeholder, replacement.originalValue);
|
|
238
|
+
}
|
|
239
|
+
return result;
|
|
240
|
+
},
|
|
241
|
+
};
|
|
242
|
+
}
|
|
243
|
+
//#endregion
|
|
244
|
+
//#region methods / get models cache path
|
|
158
245
|
getModelsCachePath() {
|
|
159
246
|
const cachePath = crossPlatformPath([
|
|
160
247
|
UtilsOs__NS__getRealHomeDir(),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"local-translation.js","sourceRoot":"","sources":[""],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,aAAa,EAA+lC,YAAY,EAAg4K,mBAAmB,EAAyvD,2BAA2B,EAAgtC,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"local-translation.js","sourceRoot":"","sources":[""],"names":[],"mappings":"AAAA,iBAAiB;AACjB,OAAO,EAAE,iBAAiB,EAAE,aAAa,EAA+lC,YAAY,EAAg4K,mBAAmB,EAAyvD,2BAA2B,EAAgtC,MAAM,mBAAmB,CAAC;AAwEriT,YAAY;AAEZ,mBAAmB;AACnB,MAAM,QAAQ,GAAG,gCAAgC,CAAC;AAElD,MAAM,iBAAiB,GAA6D;IAClF,OAAO,EAAE,UAAU;IACnB,OAAO,EAAE,UAAU;IACnB,OAAO,EAAE,UAAU;CACpB,CAAC;AAEF,MAAM,iBAAiB,GAAG,GAAG,CAAC;AAC9B,YAAY;AAEZ,MAAM,OAAO,uBAAuB;IAClC,0BAA0B;IAClB,iBAAiB,CAAgB;IAEjC,OAAO,GAAG,KAAK,CAAC;IAEhB,aAAa,CAAiB;IAE9B,iBAAiB,GAAG,IAAI,GAAG,EAA0C,CAAC;IAC9E,YAAY;IAEZ;;;;;OAKG;IACH,2CAA2C;IAC3C,KAAK,CAAC,oBAAoB,CACxB,UAAuC,EAAE;QAEzC,sBAAsB;QACtB,MAAM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BAC9C,OAAO,CAAC,KAAK,CACX,sDAAsD;4BACpD,IAAI,WAAW,CAAC,WAAW,wBAAwB,IAAI,KAAK;4BAC5D,cAAc,WAAW,CAAC,aAAa,aAAa,CACvD,CAAC;wBAEF,MAAM,GAAG,GAAG,MAAM,CAAC,OAAO,EAAE,IAAI,WAAW,CAAC,aAAa,EAAE,CAAC;wBAC5D,SAAS;oBACX,CAAC;oBAED,MAAM,GAAG,MAAM,CAAC,UAAU,CACxB,WAAW,CAAC,WAAW,EACvB,WAAW,CAAC,aAAa,CAC1B,CAAC;gBACJ,CAAC;gBAED,OAAO,MAAM,CAAC;YAChB,CAAC;SACF,CAAC;IACJ,CAAC;IACD,YAAY;IAEZ,yCAAyC;IACjC,kBAAkB;QACxB,MAAM,SAAS,GAAG,iBAAiB,CAAC;YAClC,2BAA2B,EAAE;YAC7B,aAAa;YACb,iBAAiB;SAClB,CAAC,CAAC;QAEH,mBAAmB,CAAC,SAAS,CAAC,CAAC;QAE/B,OAAO,SAAS,CAAC;IACnB,CAAC;CAEF"}
|
package/lib-prod/package.json
CHANGED
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
- TAON READONLY SOURCE
|
|
5
5
|
- DO NOT MODIFY THIS FILE.
|
|
6
6
|
- Changes may be overwritten.
|
|
7
|
-
- Use command: taon build:lib
|
|
7
|
+
- Use command: taon build:watch:lib
|
|
8
8
|
inside @taon-dev/i18n project repository
|
|
9
9
|
for watch development of third party modules like this.
|
|
10
10
|
|
|
@@ -15,4 +15,4 @@ export const APP_ID = 'com.domain.example.i18n';
|
|
|
15
15
|
export const BUILD_BASE_HREF = '';
|
|
16
16
|
export const PROJECT_NPM_NAME = '@taon-dev/i18n';
|
|
17
17
|
export const CURRENT_PACKAGE_TAON_VERSION = 'v21';
|
|
18
|
-
export const CURRENT_PACKAGE_VERSION = '21.0.
|
|
18
|
+
export const CURRENT_PACKAGE_VERSION = '21.0.53';
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
- TAON READONLY SOURCE
|
|
5
5
|
- DO NOT MODIFY THIS FILE.
|
|
6
6
|
- Changes may be overwritten.
|
|
7
|
-
- Use command: taon build:lib
|
|
7
|
+
- Use command: taon build:watch:lib
|
|
8
8
|
inside @taon-dev/i18n project repository
|
|
9
9
|
for watch development of third party modules like this.
|
|
10
10
|
|
|
@@ -22,4 +22,3 @@ export * from './translation';
|
|
|
22
22
|
export * from './utils-i18n-extract-gettext-translate-from-html';
|
|
23
23
|
export * from './utils-i18n-html';
|
|
24
24
|
export * from './utils-po-file';
|
|
25
|
-
export * from './i18n/lib.translation';
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
- TAON READONLY SOURCE
|
|
5
5
|
- DO NOT MODIFY THIS FILE.
|
|
6
6
|
- Changes may be overwritten.
|
|
7
|
-
- Use command: taon build:lib
|
|
7
|
+
- Use command: taon build:watch:lib
|
|
8
8
|
inside @taon-dev/i18n project repository
|
|
9
9
|
for watch development of third party modules like this.
|
|
10
10
|
|
|
@@ -35,6 +35,7 @@ const nllbLanguageCodes: Partial<Record<UtilsI18n.CommonLocaleCode, string>> = {
|
|
|
35
35
|
'pl-PL': 'pol_Latn',
|
|
36
36
|
'de-DE': 'deu_Latn',
|
|
37
37
|
};
|
|
38
|
+
const CONTEXT_SEPARATOR = '→';
|
|
38
39
|
export class LocalTranslationService {
|
|
39
40
|
private translatorPromise?: Promise<any>;
|
|
40
41
|
private aiReady = false;
|
|
@@ -119,6 +120,40 @@ export class LocalTranslationService {
|
|
|
119
120
|
},
|
|
120
121
|
};
|
|
121
122
|
}
|
|
123
|
+
private protectInterpolation(text: string): {
|
|
124
|
+
preparedText: string;
|
|
125
|
+
restore: (translatedText: string) => string;
|
|
126
|
+
} {
|
|
127
|
+
const replacements: Array<{
|
|
128
|
+
placeholder: string;
|
|
129
|
+
originalValue: string;
|
|
130
|
+
}> = [];
|
|
131
|
+
const preparedText = text.replace(/\[\[[\s\S]*?\]\]/g, originalValue => {
|
|
132
|
+
const placeholder = `TAONINTERPOLATION${replacements.length}PLACEHOLDER`;
|
|
133
|
+
replacements.push({
|
|
134
|
+
placeholder,
|
|
135
|
+
originalValue,
|
|
136
|
+
});
|
|
137
|
+
return placeholder;
|
|
138
|
+
});
|
|
139
|
+
return {
|
|
140
|
+
preparedText,
|
|
141
|
+
restore(translatedText: string): string {
|
|
142
|
+
let result = translatedText;
|
|
143
|
+
for (const replacement of replacements) {
|
|
144
|
+
if (!result.includes(replacement.placeholder)) {
|
|
145
|
+
console.error(`Translation model removed interpolation placeholder ` +
|
|
146
|
+
`"${replacement.placeholder}" while translating "${text}". ` +
|
|
147
|
+
`Appending "${replacement.originalValue}" manually.`);
|
|
148
|
+
result = `${result.trimEnd()} ${replacement.originalValue}`;
|
|
149
|
+
continue;
|
|
150
|
+
}
|
|
151
|
+
result = result.replaceAll(replacement.placeholder, replacement.originalValue);
|
|
152
|
+
}
|
|
153
|
+
return result;
|
|
154
|
+
},
|
|
155
|
+
};
|
|
156
|
+
}
|
|
122
157
|
private getModelsCachePath(): string {
|
|
123
158
|
const cachePath = crossPlatformPath([
|
|
124
159
|
UtilsOs.getRealHomeDir(),
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
- TAON READONLY SOURCE
|
|
5
5
|
- DO NOT MODIFY THIS FILE.
|
|
6
6
|
- Changes may be overwritten.
|
|
7
|
-
- Use command: taon build:lib
|
|
7
|
+
- Use command: taon build:watch:lib
|
|
8
8
|
inside @taon-dev/i18n project repository
|
|
9
9
|
for watch development of third party modules like this.
|
|
10
10
|
|
|
@@ -15,4 +15,4 @@ export const APP_ID = 'com.domain.example.i18n';
|
|
|
15
15
|
export const BUILD_BASE_HREF = '';
|
|
16
16
|
export const PROJECT_NPM_NAME = '@taon-dev/i18n';
|
|
17
17
|
export const CURRENT_PACKAGE_TAON_VERSION = 'v21';
|
|
18
|
-
export const CURRENT_PACKAGE_VERSION = '21.0.
|
|
18
|
+
export const CURRENT_PACKAGE_VERSION = '21.0.53';
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
- TAON READONLY SOURCE
|
|
5
5
|
- DO NOT MODIFY THIS FILE.
|
|
6
6
|
- Changes may be overwritten.
|
|
7
|
-
- Use command: taon build:lib
|
|
7
|
+
- Use command: taon build:watch:lib
|
|
8
8
|
inside @taon-dev/i18n project repository
|
|
9
9
|
for watch development of third party modules like this.
|
|
10
10
|
|
|
@@ -22,4 +22,3 @@ export * from './translation';
|
|
|
22
22
|
export * from './utils-i18n-extract-gettext-translate-from-html';
|
|
23
23
|
export * from './utils-i18n-html';
|
|
24
24
|
export * from './utils-po-file';
|
|
25
|
-
export * from './i18n/lib.translation';
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
- TAON READONLY SOURCE
|
|
5
5
|
- DO NOT MODIFY THIS FILE.
|
|
6
6
|
- Changes may be overwritten.
|
|
7
|
-
- Use command: taon build:lib
|
|
7
|
+
- Use command: taon build:watch:lib
|
|
8
8
|
inside @taon-dev/i18n project repository
|
|
9
9
|
for watch development of third party modules like this.
|
|
10
10
|
|
|
@@ -35,6 +35,7 @@ const nllbLanguageCodes: Partial<Record<UtilsI18n__NS__CommonLocaleCode, string>
|
|
|
35
35
|
'pl-PL': 'pol_Latn',
|
|
36
36
|
'de-DE': 'deu_Latn',
|
|
37
37
|
};
|
|
38
|
+
const CONTEXT_SEPARATOR = '→';
|
|
38
39
|
export class LocalTranslationService {
|
|
39
40
|
private translatorPromise?: Promise<any>;
|
|
40
41
|
private aiReady = false;
|
|
@@ -119,6 +120,40 @@ export class LocalTranslationService {
|
|
|
119
120
|
},
|
|
120
121
|
};
|
|
121
122
|
}
|
|
123
|
+
private protectInterpolation(text: string): {
|
|
124
|
+
preparedText: string;
|
|
125
|
+
restore: (translatedText: string) => string;
|
|
126
|
+
} {
|
|
127
|
+
const replacements: Array<{
|
|
128
|
+
placeholder: string;
|
|
129
|
+
originalValue: string;
|
|
130
|
+
}> = [];
|
|
131
|
+
const preparedText = text.replace(/\[\[[\s\S]*?\]\]/g, originalValue => {
|
|
132
|
+
const placeholder = `TAONINTERPOLATION${replacements.length}PLACEHOLDER`;
|
|
133
|
+
replacements.push({
|
|
134
|
+
placeholder,
|
|
135
|
+
originalValue,
|
|
136
|
+
});
|
|
137
|
+
return placeholder;
|
|
138
|
+
});
|
|
139
|
+
return {
|
|
140
|
+
preparedText,
|
|
141
|
+
restore(translatedText: string): string {
|
|
142
|
+
let result = translatedText;
|
|
143
|
+
for (const replacement of replacements) {
|
|
144
|
+
if (!result.includes(replacement.placeholder)) {
|
|
145
|
+
console.error(`Translation model removed interpolation placeholder ` +
|
|
146
|
+
`"${replacement.placeholder}" while translating "${text}". ` +
|
|
147
|
+
`Appending "${replacement.originalValue}" manually.`);
|
|
148
|
+
result = `${result.trimEnd()} ${replacement.originalValue}`;
|
|
149
|
+
continue;
|
|
150
|
+
}
|
|
151
|
+
result = result.replaceAll(replacement.placeholder, replacement.originalValue);
|
|
152
|
+
}
|
|
153
|
+
return result;
|
|
154
|
+
},
|
|
155
|
+
};
|
|
156
|
+
}
|
|
122
157
|
private getModelsCachePath(): string {
|
|
123
158
|
const cachePath = crossPlatformPath([
|
|
124
159
|
UtilsOs__NS__getRealHomeDir(),
|