@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.
Files changed (119) hide show
  1. package/VERIFIED-BUILD-DATA.jsonc +3 -3
  2. package/browser/fesm2022/i18n-browser.mjs +91 -6
  3. package/browser/fesm2022/i18n-browser.mjs.map +1 -1
  4. package/browser/package.json +1 -1
  5. package/browser/types/i18n-browser.d.ts +11 -26
  6. package/browser-prod/fesm2022/i18n-browser-prod.mjs +91 -6
  7. package/browser-prod/fesm2022/i18n-browser-prod.mjs.map +1 -1
  8. package/browser-prod/package.json +1 -1
  9. package/browser-prod/types/i18n-browser-prod.d.ts +11 -26
  10. package/full-dts/build-info._auto-generated_.d.ts +1 -1
  11. package/full-dts/index._auto-generated_.d.ts +1 -2
  12. package/full-dts/local-translation.d.ts +8 -1
  13. package/lib/build-info._auto-generated_.d.ts +1 -1
  14. package/lib/build-info._auto-generated_.js +1 -1
  15. package/lib/index._auto-generated_.d.ts +0 -1
  16. package/lib/index._auto-generated_.js +0 -1
  17. package/lib/index._auto-generated_.js.map +1 -1
  18. package/lib/local-translation.d.ts +8 -1
  19. package/lib/local-translation.js +93 -6
  20. package/lib/local-translation.js.map +1 -1
  21. package/lib/package.json +1 -1
  22. package/lib-esm/lib/build-info._auto-generated_.d.ts +1 -1
  23. package/lib-esm/lib/build-info._auto-generated_.js +1 -1
  24. package/lib-esm/lib/index._auto-generated_.d.ts +0 -1
  25. package/lib-esm/lib/index._auto-generated_.js +0 -1
  26. package/lib-esm/lib/index._auto-generated_.js.map +1 -1
  27. package/lib-esm/lib/local-translation.d.ts +8 -1
  28. package/lib-esm/lib/local-translation.js +93 -8
  29. package/lib-esm/lib/local-translation.js.map +1 -1
  30. package/lib-prod/build-info._auto-generated_.d.ts +1 -1
  31. package/lib-prod/build-info._auto-generated_.js +1 -1
  32. package/lib-prod/index._auto-generated_.d.ts +0 -1
  33. package/lib-prod/index._auto-generated_.js +0 -1
  34. package/lib-prod/index._auto-generated_.js.map +1 -1
  35. package/lib-prod/local-translation.d.ts +8 -1
  36. package/lib-prod/local-translation.js +93 -6
  37. package/lib-prod/local-translation.js.map +1 -1
  38. package/lib-prod/package.json +1 -1
  39. package/package.json +1 -1
  40. package/ts-source/browser-code/build-info._auto-generated_.ts +2 -2
  41. package/ts-source/browser-code/i18n/lib.translation.ts +1 -1
  42. package/ts-source/browser-code/i18n/translation.ts.en-US.i18n.data.ts +1 -1
  43. package/ts-source/browser-code/i18n/translation.ts.pl-PL.i18n.data.ts +1 -1
  44. package/ts-source/browser-code/index._auto-generated_.ts +1 -2
  45. package/ts-source/browser-code/index.scss +1 -1
  46. package/ts-source/browser-code/index.ts +1 -1
  47. package/ts-source/browser-code/local-translation.ts +36 -1
  48. package/ts-source/browser-code/start-cli.ts +1 -1
  49. package/ts-source/browser-code/translate.directive.ts +1 -1
  50. package/ts-source/browser-code/translate.pipe.ts +1 -1
  51. package/ts-source/browser-code/translate.service.ts +1 -1
  52. package/ts-source/browser-code/translation-manager.ts +1 -1
  53. package/ts-source/browser-code/translation.models.ts +1 -1
  54. package/ts-source/browser-code/translation.ts +1 -1
  55. package/ts-source/browser-code/utils-i18n-extract-gettext-translate-from-html.ts +1 -1
  56. package/ts-source/browser-code/utils-i18n-html.ts +1 -1
  57. package/ts-source/browser-code/utils-po-file.ts +1 -1
  58. package/ts-source/browser-code-prod/build-info._auto-generated_.ts +2 -2
  59. package/ts-source/browser-code-prod/i18n/lib.translation.ts +1 -1
  60. package/ts-source/browser-code-prod/i18n/translation.ts.en-US.i18n.data.ts +1 -1
  61. package/ts-source/browser-code-prod/i18n/translation.ts.pl-PL.i18n.data.ts +1 -1
  62. package/ts-source/browser-code-prod/index._auto-generated_.ts +1 -2
  63. package/ts-source/browser-code-prod/index.scss +1 -1
  64. package/ts-source/browser-code-prod/index.ts +1 -1
  65. package/ts-source/browser-code-prod/local-translation.ts +36 -1
  66. package/ts-source/browser-code-prod/start-cli.ts +1 -1
  67. package/ts-source/browser-code-prod/translate.directive.ts +1 -1
  68. package/ts-source/browser-code-prod/translate.pipe.ts +1 -1
  69. package/ts-source/browser-code-prod/translate.service.ts +1 -1
  70. package/ts-source/browser-code-prod/translation-manager.ts +1 -1
  71. package/ts-source/browser-code-prod/translation.models.ts +1 -1
  72. package/ts-source/browser-code-prod/translation.ts +1 -1
  73. package/ts-source/browser-code-prod/utils-i18n-extract-gettext-translate-from-html.ts +1 -1
  74. package/ts-source/browser-code-prod/utils-i18n-html.ts +1 -1
  75. package/ts-source/browser-code-prod/utils-po-file.ts +1 -1
  76. package/ts-source/websql-code/build-info._auto-generated_.ts +2 -2
  77. package/ts-source/websql-code/i18n/lib.translation.ts +1 -1
  78. package/ts-source/websql-code/i18n/translation.ts.en-US.i18n.data.ts +1 -1
  79. package/ts-source/websql-code/i18n/translation.ts.pl-PL.i18n.data.ts +1 -1
  80. package/ts-source/websql-code/index._auto-generated_.ts +1 -2
  81. package/ts-source/websql-code/index.scss +1 -1
  82. package/ts-source/websql-code/index.ts +1 -1
  83. package/ts-source/websql-code/local-translation.ts +36 -1
  84. package/ts-source/websql-code/start-cli.ts +1 -1
  85. package/ts-source/websql-code/translate.directive.ts +1 -1
  86. package/ts-source/websql-code/translate.pipe.ts +1 -1
  87. package/ts-source/websql-code/translate.service.ts +1 -1
  88. package/ts-source/websql-code/translation-manager.ts +1 -1
  89. package/ts-source/websql-code/translation.models.ts +1 -1
  90. package/ts-source/websql-code/translation.ts +1 -1
  91. package/ts-source/websql-code/utils-i18n-extract-gettext-translate-from-html.ts +1 -1
  92. package/ts-source/websql-code/utils-i18n-html.ts +1 -1
  93. package/ts-source/websql-code/utils-po-file.ts +1 -1
  94. package/ts-source/websql-code-prod/build-info._auto-generated_.ts +2 -2
  95. package/ts-source/websql-code-prod/i18n/lib.translation.ts +1 -1
  96. package/ts-source/websql-code-prod/i18n/translation.ts.en-US.i18n.data.ts +1 -1
  97. package/ts-source/websql-code-prod/i18n/translation.ts.pl-PL.i18n.data.ts +1 -1
  98. package/ts-source/websql-code-prod/index._auto-generated_.ts +1 -2
  99. package/ts-source/websql-code-prod/index.scss +1 -1
  100. package/ts-source/websql-code-prod/index.ts +1 -1
  101. package/ts-source/websql-code-prod/local-translation.ts +36 -1
  102. package/ts-source/websql-code-prod/start-cli.ts +1 -1
  103. package/ts-source/websql-code-prod/translate.directive.ts +1 -1
  104. package/ts-source/websql-code-prod/translate.pipe.ts +1 -1
  105. package/ts-source/websql-code-prod/translate.service.ts +1 -1
  106. package/ts-source/websql-code-prod/translation-manager.ts +1 -1
  107. package/ts-source/websql-code-prod/translation.models.ts +1 -1
  108. package/ts-source/websql-code-prod/translation.ts +1 -1
  109. package/ts-source/websql-code-prod/utils-i18n-extract-gettext-translate-from-html.ts +1 -1
  110. package/ts-source/websql-code-prod/utils-i18n-html.ts +1 -1
  111. package/ts-source/websql-code-prod/utils-po-file.ts +1 -1
  112. package/websql/fesm2022/i18n-websql.mjs +91 -6
  113. package/websql/fesm2022/i18n-websql.mjs.map +1 -1
  114. package/websql/package.json +1 -1
  115. package/websql/types/i18n-websql.d.ts +11 -26
  116. package/websql-prod/fesm2022/i18n-websql-prod.mjs +91 -6
  117. package/websql-prod/fesm2022/i18n-websql-prod.mjs.map +1 -1
  118. package/websql-prod/package.json +1 -1
  119. package/websql-prod/types/i18n-websql-prod.d.ts +11 -26
@@ -1,5 +1,5 @@
1
1
  // @ts-nocheck
2
- import { UtilsI18n, CoreModels } from 'tnp-core/websql';
2
+ import { UtilsI18n } from 'tnp-core/websql';
3
3
  import * as i0 from '@angular/core';
4
4
  import { ChangeDetectorRef, WritableSignal, AfterViewInit, OnChanges, PipeTransform, OnDestroy } from '@angular/core';
5
5
  import * as rxjs from 'rxjs';
@@ -28,16 +28,22 @@ declare const CURRENT_PACKAGE_TAON_VERSION = "v21";
28
28
  /**
29
29
  * Autogenerated by current cli tool. Use *tnp release* to bump version.
30
30
  */
31
- declare const CURRENT_PACKAGE_VERSION = "21.0.50";
31
+ declare const CURRENT_PACKAGE_VERSION = "21.0.53";
32
32
 
33
33
  interface TranslationOptions {
34
34
  text: string;
35
35
  from: UtilsI18n.CommonLocaleCode;
36
36
  to: UtilsI18n.CommonLocaleCode;
37
37
  /**
38
- * Nearby source-language text.
38
+ * Nearby source-language text used only to give the translator
39
+ * additional context.
40
+ *
41
+ * Context is never returned from translate().
39
42
  */
40
43
  context?: string;
44
+ /**
45
+ * Source terms that should be replaced with specific translated terms.
46
+ */
41
47
  glossary?: Record<string, string>;
42
48
  }
43
49
  interface AiDownloadProgress {
@@ -94,6 +100,7 @@ declare class LocalTranslationService {
94
100
  private warmupTranslator;
95
101
  translate(options: TranslationOptions): Promise<string>;
96
102
  private protectGlossary;
103
+ private protectInterpolation;
97
104
  private getModelsCachePath;
98
105
  }
99
106
 
@@ -256,27 +263,5 @@ declare namespace UtilsPoFile {
256
263
  function mergeGettextFile(jsonContent1FromTsHtml: UtilsI18n.GettextFile, json2ContentFromPoFileModifedByUser?: UtilsI18n.GettextFile | null): UtilsI18n.GettextFile;
257
264
  }
258
265
 
259
- interface EnUsTraslationOverrideSrcLibTranslationTs {
260
- "en-US": {
261
- "": {
262
- "amazing better place"?: string;
263
- "asdasd"?: string;
264
- "hello"?: string;
265
- };
266
- };
267
- }
268
-
269
- interface PlPlTraslationOverrideSrcLibTranslationTs {
270
- "pl-PL": {
271
- "": {
272
- "amazing better place"?: string;
273
- "asdasd"?: string;
274
- "hello"?: string;
275
- };
276
- };
277
- }
278
-
279
- type LibOverride = CoreModels.DeepPartial<EnUsTraslationOverrideSrcLibTranslationTs | PlPlTraslationOverrideSrcLibTranslationTs>;
280
-
281
266
  export { APP_ID, BUILD_BASE_HREF, BUILD_FRAMEWORK_CLI_NAME, CURRENT_PACKAGE_TAON_VERSION, CURRENT_PACKAGE_VERSION, LocalTranslationService, PROJECT_NPM_NAME, TranslateDirective, TranslatePipe, TranslateService, Translation, TranslationManager, UtilsI18nExtractGettextTranslateFromHtml, UtilsI18nHtml, UtilsPoFile, startCli };
282
- export type { AiDownloadProgress, LibOverride, MakeSureAiDownloadedOptions, TaonTranslationsMap, TaonTranslationsMapImport, Translatable, TranslationBinding, TranslationLookup, TranslationOptions, TranslationParams };
267
+ export type { AiDownloadProgress, MakeSureAiDownloadedOptions, TaonTranslationsMap, TaonTranslationsMapImport, Translatable, TranslationBinding, TranslationLookup, TranslationOptions, TranslationParams };
@@ -28,26 +28,34 @@ const CURRENT_PACKAGE_TAON_VERSION = 'v21';
28
28
  /**
29
29
  * Autogenerated by current cli tool. Use *tnp release* to bump version.
30
30
  */
31
- const CURRENT_PACKAGE_VERSION = '21.0.50';
31
+ const CURRENT_PACKAGE_VERSION = '21.0.53';
32
32
  // THIS FILE IS GENERATED - DO NOT MODIFY
33
33
 
34
+ //#region imports
35
+ //#endregion
36
+ //#region constants
34
37
  const MODEL_ID = 'Xenova/nllb-200-distilled-600M';
35
38
  const nllbLanguageCodes = {
36
39
  'en-US': 'eng_Latn',
37
40
  'pl-PL': 'pol_Latn',
38
41
  'de-DE': 'deu_Latn',
39
42
  };
43
+ const CONTEXT_SEPARATOR = '→';
44
+ //#endregion
40
45
  class LocalTranslationService {
41
46
  constructor() {
42
47
  this.aiReady = false;
43
48
  this.progressListeners = new Set();
49
+ //#endregion
44
50
  }
51
+ //#endregion
45
52
  /**
46
53
  * Downloads, caches and loads the translation model.
47
54
  *
48
55
  * Multiple simultaneous calls share the same initialization promise.
49
56
  * After this resolves, translate() reuses the already loaded model.
50
57
  */
58
+ //#region methods / make sure ai downloaded
51
59
  async makeSureAiDownloaded(options = {}) {
52
60
  /* */
53
61
  /* */
@@ -69,12 +77,16 @@ class LocalTranslationService {
69
77
  /* */
70
78
  return (void 0);
71
79
  }
80
+ //#endregion
72
81
  /**
73
82
  * True only in this process after pipeline initialization succeeded.
74
83
  */
84
+ //#region methods / is ai ready
75
85
  isAiReady() {
76
86
  return this.aiReady;
77
87
  }
88
+ //#endregion
89
+ //#region methods / get translator
78
90
  getTranslator() {
79
91
  this.translatorPromise ??= this.createTranslator().catch(error => {
80
92
  // Allow a later call to retry after a network or disk failure.
@@ -84,6 +96,8 @@ class LocalTranslationService {
84
96
  });
85
97
  return this.translatorPromise;
86
98
  }
99
+ //#endregion
100
+ //#region methods / create translator
87
101
  async createTranslator() {
88
102
  /* */
89
103
  /* */
@@ -108,11 +122,11 @@ class LocalTranslationService {
108
122
  /* */
109
123
  /* */
110
124
  /* */
111
- /* */
112
- /* */
113
125
  return (void 0);
114
126
  return void 0;
115
127
  }
128
+ //#endregion
129
+ //#region methods / emit progress
116
130
  emitProgress(progress) {
117
131
  for (const listener of this.progressListeners) {
118
132
  try {
@@ -123,6 +137,8 @@ class LocalTranslationService {
123
137
  }
124
138
  }
125
139
  }
140
+ //#endregion
141
+ //#region methods / warmup translator
126
142
  warmupTranslator(translator) {
127
143
  this.warmupPromise ??= translator('Hello.', {
128
144
  src_lang: 'eng_Latn',
@@ -136,6 +152,8 @@ class LocalTranslationService {
136
152
  });
137
153
  return this.warmupPromise;
138
154
  }
155
+ //#endregion
156
+ //#region methods / translate
139
157
  async translate(options) {
140
158
  /* */
141
159
  /* */
@@ -181,8 +199,46 @@ class LocalTranslationService {
181
199
  /* */
182
200
  /* */
183
201
  /* */
202
+ /* */
203
+ /* */
204
+ /* */
205
+ /* */
206
+ /* */
207
+ /* */
208
+ /* */
209
+ /* */
210
+ /* */
211
+ /* */
212
+ /* */
213
+ /* */
214
+ /* */
215
+ /* */
216
+ /* */
217
+ /* */
218
+ /* */
219
+ /* */
220
+ /* */
221
+ /* */
222
+ /* */
223
+ /* */
224
+ /* */
225
+ /* */
226
+ /* */
227
+ /* */
228
+ /* */
229
+ /* */
230
+ /* */
231
+ /* */
232
+ /* */
233
+ /* */
234
+ /* */
235
+ /* */
236
+ /* */
237
+ /* */
184
238
  return (void 0);
185
239
  }
240
+ //#endregion
241
+ //#region methods / protect glossary
186
242
  protectGlossary(text, glossary) {
187
243
  if (!glossary || Object.keys(glossary).length === 0) {
188
244
  return {
@@ -213,6 +269,38 @@ class LocalTranslationService {
213
269
  },
214
270
  };
215
271
  }
272
+ //#endregion
273
+ //#region methods / protect interpolation
274
+ protectInterpolation(text) {
275
+ const replacements = [];
276
+ const preparedText = text.replace(/\[\[[\s\S]*?\]\]/g, originalValue => {
277
+ const placeholder = `TAONINTERPOLATION${replacements.length}PLACEHOLDER`;
278
+ replacements.push({
279
+ placeholder,
280
+ originalValue,
281
+ });
282
+ return placeholder;
283
+ });
284
+ return {
285
+ preparedText,
286
+ restore(translatedText) {
287
+ let result = translatedText;
288
+ for (const replacement of replacements) {
289
+ if (!result.includes(replacement.placeholder)) {
290
+ console.error(`Translation model removed interpolation placeholder ` +
291
+ `"${replacement.placeholder}" while translating "${text}". ` +
292
+ `Appending "${replacement.originalValue}" manually.`);
293
+ result = `${result.trimEnd()} ${replacement.originalValue}`;
294
+ continue;
295
+ }
296
+ result = result.replaceAll(replacement.placeholder, replacement.originalValue);
297
+ }
298
+ return result;
299
+ },
300
+ };
301
+ }
302
+ //#endregion
303
+ //#region methods / get models cache path
216
304
  getModelsCachePath() {
217
305
  const cachePath = crossPlatformPath([
218
306
  UtilsOs__NS__getRealHomeDir(),
@@ -1931,9 +2019,6 @@ function unescapePoString(value) {
1931
2019
  //#endregion
1932
2020
  //end of namespace UtilsPoFile
1933
2021
 
1934
- ;
1935
- // THIS FILE IS GENERATED - DO NOT MODIFY
1936
-
1937
2022
  // @ts-nocheck
1938
2023
  // This file is auto-generated during init process. Do not modify.
1939
2024
  // This disable this auto generate file.