@taon-dev/i18n 21.0.48 → 21.0.50

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 (145) hide show
  1. package/VERIFIED-BUILD-DATA.jsonc +3 -3
  2. package/browser/fesm2022/i18n-browser.mjs +1 -1
  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 +1 -1
  6. package/browser-prod/fesm2022/i18n-browser-prod.mjs +1 -1
  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 +1 -1
  10. package/full-dts/build-info._auto-generated_.d.ts +1 -1
  11. package/lib/build-info._auto-generated_.d.ts +1 -1
  12. package/lib/build-info._auto-generated_.js +1 -1
  13. package/lib/package.json +1 -1
  14. package/lib-esm/lib/build-info._auto-generated_.d.ts +1 -1
  15. package/lib-esm/lib/build-info._auto-generated_.js +1 -1
  16. package/lib-prod/build-info._auto-generated_.d.ts +1 -1
  17. package/lib-prod/build-info._auto-generated_.js +1 -1
  18. package/lib-prod/package.json +1 -1
  19. package/package.json +1 -1
  20. package/ts-source/browser-code/build-info._auto-generated_.ts +18 -0
  21. package/ts-source/browser-code/i18n/lib.translation.ts +17 -0
  22. package/ts-source/browser-code/i18n/translation.ts.en-US.i18n.data.ts +38 -0
  23. package/ts-source/browser-code/i18n/translation.ts.en-US.po +17 -0
  24. package/ts-source/browser-code/i18n/translation.ts.pl-PL.i18n.data.ts +38 -0
  25. package/ts-source/browser-code/i18n/translation.ts.pl-PL.po +17 -0
  26. package/ts-source/browser-code/index._auto-generated_.ts +25 -0
  27. package/ts-source/browser-code/index.scss +12 -0
  28. package/ts-source/browser-code/index.ts +15 -0
  29. package/ts-source/browser-code/lib-info.md +8 -0
  30. package/ts-source/browser-code/local-translation.ts +131 -0
  31. package/ts-source/browser-code/migrations/migrations-info.md +6 -0
  32. package/ts-source/browser-code/start-cli.ts +17 -0
  33. package/ts-source/browser-code/translate.directive.ts +64 -0
  34. package/ts-source/browser-code/translate.pipe.ts +37 -0
  35. package/ts-source/browser-code/translate.service.ts +25 -0
  36. package/ts-source/browser-code/translation-manager.ts +106 -0
  37. package/ts-source/browser-code/translation.models.ts +32 -0
  38. package/ts-source/browser-code/translation.ts +184 -0
  39. package/ts-source/browser-code/utils-i18n-extract-gettext-translate-from-html.ts +92 -0
  40. package/ts-source/browser-code/utils-i18n-html.ts +84 -0
  41. package/ts-source/browser-code/utils-po-file.ts +75 -0
  42. package/ts-source/browser-code-prod/build-info._auto-generated_.split-namespaces.json +4 -0
  43. package/ts-source/browser-code-prod/build-info._auto-generated_.ts +18 -0
  44. package/ts-source/browser-code-prod/i18n/lib.translation.split-namespaces.json +4 -0
  45. package/ts-source/browser-code-prod/i18n/lib.translation.ts +17 -0
  46. package/ts-source/browser-code-prod/i18n/translation.ts.en-US.i18n.data.ts +38 -0
  47. package/ts-source/browser-code-prod/i18n/translation.ts.en-US.po +17 -0
  48. package/ts-source/browser-code-prod/i18n/translation.ts.pl-PL.i18n.data.ts +38 -0
  49. package/ts-source/browser-code-prod/i18n/translation.ts.pl-PL.po +17 -0
  50. package/ts-source/browser-code-prod/index._auto-generated_.split-namespaces.json +4 -0
  51. package/ts-source/browser-code-prod/index._auto-generated_.ts +25 -0
  52. package/ts-source/browser-code-prod/index.scss +12 -0
  53. package/ts-source/browser-code-prod/index.split-namespaces.json +4 -0
  54. package/ts-source/browser-code-prod/index.ts +15 -0
  55. package/ts-source/browser-code-prod/lib-info.md +8 -0
  56. package/ts-source/browser-code-prod/local-translation.split-namespaces.json +4 -0
  57. package/ts-source/browser-code-prod/local-translation.ts +131 -0
  58. package/ts-source/browser-code-prod/migrations/migrations-info.md +6 -0
  59. package/ts-source/browser-code-prod/start-cli.split-namespaces.json +4 -0
  60. package/ts-source/browser-code-prod/start-cli.ts +17 -0
  61. package/ts-source/browser-code-prod/translate.directive.split-namespaces.json +4 -0
  62. package/ts-source/browser-code-prod/translate.directive.ts +64 -0
  63. package/ts-source/browser-code-prod/translate.pipe.split-namespaces.json +4 -0
  64. package/ts-source/browser-code-prod/translate.pipe.ts +37 -0
  65. package/ts-source/browser-code-prod/translate.service.split-namespaces.json +4 -0
  66. package/ts-source/browser-code-prod/translate.service.ts +25 -0
  67. package/ts-source/browser-code-prod/translation-manager.split-namespaces.json +4 -0
  68. package/ts-source/browser-code-prod/translation-manager.ts +106 -0
  69. package/ts-source/browser-code-prod/translation.models.split-namespaces.json +4 -0
  70. package/ts-source/browser-code-prod/translation.models.ts +32 -0
  71. package/ts-source/browser-code-prod/translation.split-namespaces.json +4 -0
  72. package/ts-source/browser-code-prod/translation.ts +184 -0
  73. package/ts-source/browser-code-prod/utils-i18n-extract-gettext-translate-from-html.split-namespaces.json +10 -0
  74. package/ts-source/browser-code-prod/utils-i18n-extract-gettext-translate-from-html.ts +90 -0
  75. package/ts-source/browser-code-prod/utils-i18n-html.split-namespaces.json +16 -0
  76. package/ts-source/browser-code-prod/utils-i18n-html.ts +82 -0
  77. package/ts-source/browser-code-prod/utils-po-file.split-namespaces.json +18 -0
  78. package/ts-source/browser-code-prod/utils-po-file.ts +73 -0
  79. package/ts-source/websql-code/build-info._auto-generated_.ts +18 -0
  80. package/ts-source/websql-code/i18n/lib.translation.ts +17 -0
  81. package/ts-source/websql-code/i18n/translation.ts.en-US.i18n.data.ts +38 -0
  82. package/ts-source/websql-code/i18n/translation.ts.en-US.po +17 -0
  83. package/ts-source/websql-code/i18n/translation.ts.pl-PL.i18n.data.ts +38 -0
  84. package/ts-source/websql-code/i18n/translation.ts.pl-PL.po +17 -0
  85. package/ts-source/websql-code/index._auto-generated_.ts +25 -0
  86. package/ts-source/websql-code/index.scss +12 -0
  87. package/ts-source/websql-code/index.ts +15 -0
  88. package/ts-source/websql-code/lib-info.md +8 -0
  89. package/ts-source/websql-code/local-translation.ts +131 -0
  90. package/ts-source/websql-code/migrations/migrations-info.md +6 -0
  91. package/ts-source/websql-code/start-cli.ts +17 -0
  92. package/ts-source/websql-code/translate.directive.ts +64 -0
  93. package/ts-source/websql-code/translate.pipe.ts +37 -0
  94. package/ts-source/websql-code/translate.service.ts +25 -0
  95. package/ts-source/websql-code/translation-manager.ts +106 -0
  96. package/ts-source/websql-code/translation.models.ts +32 -0
  97. package/ts-source/websql-code/translation.ts +184 -0
  98. package/ts-source/websql-code/utils-i18n-extract-gettext-translate-from-html.ts +92 -0
  99. package/ts-source/websql-code/utils-i18n-html.ts +84 -0
  100. package/ts-source/websql-code/utils-po-file.ts +75 -0
  101. package/ts-source/websql-code-prod/build-info._auto-generated_.split-namespaces.json +4 -0
  102. package/ts-source/websql-code-prod/build-info._auto-generated_.ts +18 -0
  103. package/ts-source/websql-code-prod/i18n/lib.translation.split-namespaces.json +4 -0
  104. package/ts-source/websql-code-prod/i18n/lib.translation.ts +17 -0
  105. package/ts-source/websql-code-prod/i18n/translation.ts.en-US.i18n.data.ts +38 -0
  106. package/ts-source/websql-code-prod/i18n/translation.ts.en-US.po +17 -0
  107. package/ts-source/websql-code-prod/i18n/translation.ts.pl-PL.i18n.data.ts +38 -0
  108. package/ts-source/websql-code-prod/i18n/translation.ts.pl-PL.po +17 -0
  109. package/ts-source/websql-code-prod/index._auto-generated_.split-namespaces.json +4 -0
  110. package/ts-source/websql-code-prod/index._auto-generated_.ts +25 -0
  111. package/ts-source/websql-code-prod/index.scss +12 -0
  112. package/ts-source/websql-code-prod/index.split-namespaces.json +4 -0
  113. package/ts-source/websql-code-prod/index.ts +15 -0
  114. package/ts-source/websql-code-prod/lib-info.md +8 -0
  115. package/ts-source/websql-code-prod/local-translation.split-namespaces.json +4 -0
  116. package/ts-source/websql-code-prod/local-translation.ts +131 -0
  117. package/ts-source/websql-code-prod/migrations/migrations-info.md +6 -0
  118. package/ts-source/websql-code-prod/start-cli.split-namespaces.json +4 -0
  119. package/ts-source/websql-code-prod/start-cli.ts +17 -0
  120. package/ts-source/websql-code-prod/translate.directive.split-namespaces.json +4 -0
  121. package/ts-source/websql-code-prod/translate.directive.ts +64 -0
  122. package/ts-source/websql-code-prod/translate.pipe.split-namespaces.json +4 -0
  123. package/ts-source/websql-code-prod/translate.pipe.ts +37 -0
  124. package/ts-source/websql-code-prod/translate.service.split-namespaces.json +4 -0
  125. package/ts-source/websql-code-prod/translate.service.ts +25 -0
  126. package/ts-source/websql-code-prod/translation-manager.split-namespaces.json +4 -0
  127. package/ts-source/websql-code-prod/translation-manager.ts +106 -0
  128. package/ts-source/websql-code-prod/translation.models.split-namespaces.json +4 -0
  129. package/ts-source/websql-code-prod/translation.models.ts +32 -0
  130. package/ts-source/websql-code-prod/translation.split-namespaces.json +4 -0
  131. package/ts-source/websql-code-prod/translation.ts +184 -0
  132. package/ts-source/websql-code-prod/utils-i18n-extract-gettext-translate-from-html.split-namespaces.json +10 -0
  133. package/ts-source/websql-code-prod/utils-i18n-extract-gettext-translate-from-html.ts +90 -0
  134. package/ts-source/websql-code-prod/utils-i18n-html.split-namespaces.json +16 -0
  135. package/ts-source/websql-code-prod/utils-i18n-html.ts +82 -0
  136. package/ts-source/websql-code-prod/utils-po-file.split-namespaces.json +18 -0
  137. package/ts-source/websql-code-prod/utils-po-file.ts +73 -0
  138. package/websql/fesm2022/i18n-websql.mjs +1 -1
  139. package/websql/fesm2022/i18n-websql.mjs.map +1 -1
  140. package/websql/package.json +1 -1
  141. package/websql/types/i18n-websql.d.ts +1 -1
  142. package/websql-prod/fesm2022/i18n-websql-prod.mjs +1 -1
  143. package/websql-prod/fesm2022/i18n-websql-prod.mjs.map +1 -1
  144. package/websql-prod/package.json +1 -1
  145. package/websql-prod/types/i18n-websql-prod.d.ts +1 -1
@@ -0,0 +1,18 @@
1
+ // @ts-nocheck
2
+ /* ============================================================================
3
+
4
+ - TAON READONLY SOURCE
5
+ - DO NOT MODIFY THIS FILE.
6
+ - Changes may be overwritten.
7
+ - Use command: taon build:lib:watch
8
+ inside @taon-dev/i18n project repository
9
+ for watch development of third party modules like this.
10
+
11
+ * ========================================================================== */
12
+
13
+ export const BUILD_FRAMEWORK_CLI_NAME = 'tnp';
14
+ export const APP_ID = 'com.domain.example.i18n';
15
+ export const BUILD_BASE_HREF = '';
16
+ export const PROJECT_NPM_NAME = '@taon-dev/i18n';
17
+ export const CURRENT_PACKAGE_TAON_VERSION = 'v21';
18
+ export const CURRENT_PACKAGE_VERSION = '21.0.50';
@@ -0,0 +1,17 @@
1
+ // @ts-nocheck
2
+ /* ============================================================================
3
+
4
+ - TAON READONLY SOURCE
5
+ - DO NOT MODIFY THIS FILE.
6
+ - Changes may be overwritten.
7
+ - Use command: taon build:lib:watch
8
+ inside @taon-dev/i18n project repository
9
+ for watch development of third party modules like this.
10
+
11
+ * ========================================================================== */
12
+
13
+ import { CoreModels } from 'tnp-core/browser';
14
+ import { EnUsTraslationOverrideSrcLibTranslationTs } from './translation.ts.en-US.i18n.data';
15
+ import { PlPlTraslationOverrideSrcLibTranslationTs } from './translation.ts.pl-PL.i18n.data';
16
+ ;
17
+ export type LibOverride = CoreModels.DeepPartial<EnUsTraslationOverrideSrcLibTranslationTs | PlPlTraslationOverrideSrcLibTranslationTs>;
@@ -0,0 +1,38 @@
1
+ // @ts-nocheck
2
+ /* ============================================================================
3
+
4
+ - TAON READONLY SOURCE
5
+ - DO NOT MODIFY THIS FILE.
6
+ - Changes may be overwritten.
7
+ - Use command: taon build:lib:watch
8
+ inside @taon-dev/i18n project repository
9
+ for watch development of third party modules like this.
10
+
11
+ * ========================================================================== */
12
+
13
+ export interface EnUsTraslationOverrideSrcLibTranslationTs {
14
+ "en-US": {
15
+ "": {
16
+ "amazing better place"?: string;
17
+ "asdasd"?: string;
18
+ "hello"?: string;
19
+ };
20
+ };
21
+ }
22
+ export default {
23
+ "fileRelativePath": "src/lib/translation.ts",
24
+ "tags": [
25
+ {
26
+ "gettextString": "asdasd",
27
+ "lineNumber": 345
28
+ },
29
+ {
30
+ "gettextString": "amazing better place",
31
+ "lineNumber": 355
32
+ },
33
+ {
34
+ "gettextString": "hello",
35
+ "lineNumber": 369
36
+ }
37
+ ]
38
+ };
@@ -0,0 +1,17 @@
1
+ msgid ""
2
+ msgstr ""
3
+ "Language: en-US\n"
4
+ "Content-Type: text/plain; charset=UTF-8\n"
5
+ "Content-Transfer-Encoding: 8bit\n"
6
+
7
+ #: src/lib/translation.ts:345
8
+ msgid "asdasd"
9
+ msgstr ""
10
+
11
+ #: src/lib/translation.ts:355
12
+ msgid "amazing better place"
13
+ msgstr ""
14
+
15
+ #: src/lib/translation.ts:369
16
+ msgid "hello"
17
+ msgstr ""
@@ -0,0 +1,38 @@
1
+ // @ts-nocheck
2
+ /* ============================================================================
3
+
4
+ - TAON READONLY SOURCE
5
+ - DO NOT MODIFY THIS FILE.
6
+ - Changes may be overwritten.
7
+ - Use command: taon build:lib:watch
8
+ inside @taon-dev/i18n project repository
9
+ for watch development of third party modules like this.
10
+
11
+ * ========================================================================== */
12
+
13
+ export interface PlPlTraslationOverrideSrcLibTranslationTs {
14
+ "pl-PL": {
15
+ "": {
16
+ "amazing better place"?: string;
17
+ "asdasd"?: string;
18
+ "hello"?: string;
19
+ };
20
+ };
21
+ }
22
+ export default {
23
+ "fileRelativePath": "src/lib/translation.ts",
24
+ "tags": [
25
+ {
26
+ "gettextString": "asdasd",
27
+ "lineNumber": 345
28
+ },
29
+ {
30
+ "gettextString": "amazing better place",
31
+ "lineNumber": 355
32
+ },
33
+ {
34
+ "gettextString": "hello",
35
+ "lineNumber": 369
36
+ }
37
+ ]
38
+ };
@@ -0,0 +1,17 @@
1
+ msgid ""
2
+ msgstr ""
3
+ "Language: pl-PL\n"
4
+ "Content-Type: text/plain; charset=UTF-8\n"
5
+ "Content-Transfer-Encoding: 8bit\n"
6
+
7
+ #: src/lib/translation.ts:345
8
+ msgid "asdasd"
9
+ msgstr ""
10
+
11
+ #: src/lib/translation.ts:355
12
+ msgid "amazing better place"
13
+ msgstr ""
14
+
15
+ #: src/lib/translation.ts:369
16
+ msgid "hello"
17
+ msgstr ""
@@ -0,0 +1,25 @@
1
+ // @ts-nocheck
2
+ /* ============================================================================
3
+
4
+ - TAON READONLY SOURCE
5
+ - DO NOT MODIFY THIS FILE.
6
+ - Changes may be overwritten.
7
+ - Use command: taon build:lib:watch
8
+ inside @taon-dev/i18n project repository
9
+ for watch development of third party modules like this.
10
+
11
+ * ========================================================================== */
12
+
13
+ export * from './build-info._auto-generated_';
14
+ export * from './local-translation';
15
+ export * from './start-cli';
16
+ export * from './translate.directive';
17
+ export * from './translate.pipe';
18
+ export * from './translate.service';
19
+ export * from './translation-manager';
20
+ export * from './translation.models';
21
+ export * from './translation';
22
+ export * from './utils-i18n-extract-gettext-translate-from-html';
23
+ export * from './utils-i18n-html';
24
+ export * from './utils-po-file';
25
+ export * from './i18n/lib.translation';
@@ -0,0 +1,12 @@
1
+ /* ============================================================================
2
+
3
+ - TAON READONLY SOURCE
4
+ - DO NOT MODIFY THIS FILE.
5
+ - Changes may be overwritten.
6
+ - Use command: taon build:lib:watch
7
+ inside @taon-dev/i18n project repository
8
+ for watch development of third party modules like this.
9
+
10
+ * ========================================================================== */
11
+
12
+
@@ -0,0 +1,15 @@
1
+ // @ts-nocheck
2
+ /* ============================================================================
3
+
4
+ - TAON READONLY SOURCE
5
+ - DO NOT MODIFY THIS FILE.
6
+ - Changes may be overwritten.
7
+ - Use command: taon build:lib:watch
8
+ inside @taon-dev/i18n project repository
9
+ for watch development of third party modules like this.
10
+
11
+ * ========================================================================== */
12
+
13
+ export * from './index._auto-generated_';
14
+ export * from './start-cli';
15
+ export default {};
@@ -0,0 +1,8 @@
1
+ THIS FILE IS GENERATED - DO NOT MODIFY
2
+
3
+ This folder is an entry point for npm Angular/NodeJS library
4
+
5
+ DON'T USE STUFF FROM PARENT FOLDER app.* FILES HERE (except src/migrations/** files).
6
+
7
+ THIS FILE IS GENERATED - DO NOT MODIFY
8
+
@@ -0,0 +1,131 @@
1
+ // @ts-nocheck
2
+ /* ============================================================================
3
+
4
+ - TAON READONLY SOURCE
5
+ - DO NOT MODIFY THIS FILE.
6
+ - Changes may be overwritten.
7
+ - Use command: taon build:lib:watch
8
+ inside @taon-dev/i18n project repository
9
+ for watch development of third party modules like this.
10
+
11
+ * ========================================================================== */
12
+
13
+ import { crossPlatformPath, dotTaonFolder, UtilsI18n, UtilsOs, _, Helpers, } from 'tnp-core/browser';
14
+ export interface TranslationOptions {
15
+ text: string;
16
+ from: UtilsI18n.CommonLocaleCode;
17
+ to: UtilsI18n.CommonLocaleCode;
18
+ context?: string;
19
+ glossary?: Record<string, string>;
20
+ }
21
+ export interface AiDownloadProgress {
22
+ status: 'initiate' | 'download' | 'progress' | 'progress_total' | 'done' | 'ready' | string;
23
+ file?: string;
24
+ progress?: number;
25
+ loaded?: number;
26
+ total?: number;
27
+ }
28
+ export interface MakeSureAiDownloadedOptions {
29
+ onProgress?: (progress: AiDownloadProgress) => void;
30
+ warmup?: boolean;
31
+ }
32
+ const MODEL_ID = 'Xenova/nllb-200-distilled-600M';
33
+ const nllbLanguageCodes: Partial<Record<UtilsI18n.CommonLocaleCode, string>> = {
34
+ 'en-US': 'eng_Latn',
35
+ 'pl-PL': 'pol_Latn',
36
+ 'de-DE': 'deu_Latn',
37
+ };
38
+ export class LocalTranslationService {
39
+ private translatorPromise?: Promise<any>;
40
+ private aiReady = false;
41
+ private warmupPromise?: Promise<void>;
42
+ private progressListeners = new Set<(progress: AiDownloadProgress) => void>();
43
+ async makeSureAiDownloaded(options: MakeSureAiDownloadedOptions = {}): Promise<void> {
44
+ return (void 0);
45
+ }
46
+ isAiReady(): boolean {
47
+ return this.aiReady;
48
+ }
49
+ private getTranslator(): Promise<any> {
50
+ this.translatorPromise ??= this.createTranslator().catch(error => {
51
+ this.translatorPromise = undefined;
52
+ this.aiReady = false;
53
+ throw error;
54
+ });
55
+ return this.translatorPromise;
56
+ }
57
+ private async createTranslator(): Promise<any> {
58
+ return (void 0);
59
+ return void 0 as any;
60
+ }
61
+ private emitProgress(progress: AiDownloadProgress): void {
62
+ for (const listener of this.progressListeners) {
63
+ try {
64
+ listener(progress);
65
+ }
66
+ catch {
67
+ }
68
+ }
69
+ }
70
+ private warmupTranslator(translator: any): Promise<void> {
71
+ this.warmupPromise ??= translator('Hello.', {
72
+ src_lang: 'eng_Latn',
73
+ tgt_lang: 'pol_Latn',
74
+ max_new_tokens: 16,
75
+ })
76
+ .then(() => undefined)
77
+ .catch(error => {
78
+ this.warmupPromise = undefined;
79
+ throw error;
80
+ });
81
+ return this.warmupPromise;
82
+ }
83
+ async translate(options: TranslationOptions): Promise<string> {
84
+ return (void 0);
85
+ }
86
+ private protectGlossary(text: string, glossary?: Record<string, string>): {
87
+ preparedText: string;
88
+ restore: (translatedText: string) => string;
89
+ } {
90
+ if (!glossary || Object.keys(glossary).length === 0) {
91
+ return {
92
+ preparedText: text,
93
+ restore: translatedText => translatedText,
94
+ };
95
+ }
96
+ const replacements: Array<{
97
+ placeholder: string;
98
+ translatedValue: string;
99
+ }> = [];
100
+ let preparedText = text;
101
+ Object.entries(glossary)
102
+ .sort(([left], [right]) => right.length - left.length)
103
+ .forEach(([sourceValue, translatedValue], index) => {
104
+ const placeholder = `TAONTERM${index}PLACEHOLDER`;
105
+ preparedText = preparedText.replaceAll(sourceValue, placeholder);
106
+ replacements.push({
107
+ placeholder,
108
+ translatedValue,
109
+ });
110
+ });
111
+ return {
112
+ preparedText,
113
+ restore(translatedText: string): string {
114
+ let result = translatedText;
115
+ for (const replacement of replacements) {
116
+ result = result.replaceAll(replacement.placeholder, replacement.translatedValue);
117
+ }
118
+ return result;
119
+ },
120
+ };
121
+ }
122
+ private getModelsCachePath(): string {
123
+ const cachePath = crossPlatformPath([
124
+ UtilsOs.getRealHomeDir(),
125
+ dotTaonFolder,
126
+ 'ai-models-cache',
127
+ ]);
128
+ Helpers.mkdirp(cachePath);
129
+ return cachePath;
130
+ }
131
+ }
@@ -0,0 +1,6 @@
1
+ THIS FILE IS GENERATED - DO NOT MODIFY
2
+
3
+ This folder is only for storing migration files with auto-generated names.
4
+
5
+ THIS FILE IS GENERATED - DO NOT MODIFY
6
+
@@ -0,0 +1,17 @@
1
+ // @ts-nocheck
2
+ /* ============================================================================
3
+
4
+ - TAON READONLY SOURCE
5
+ - DO NOT MODIFY THIS FILE.
6
+ - Changes may be overwritten.
7
+ - Use command: taon build:lib:watch
8
+ inside @taon-dev/i18n project repository
9
+ for watch development of third party modules like this.
10
+
11
+ * ========================================================================== */
12
+
13
+ import { LocalTranslationService } from './local-translation';
14
+ export async function startCli(argsv: string[], filename: string): Promise<void> {
15
+ return (void 0);
16
+ }
17
+ export default startCli;
@@ -0,0 +1,64 @@
1
+ // @ts-nocheck
2
+ /* ============================================================================
3
+
4
+ - TAON READONLY SOURCE
5
+ - DO NOT MODIFY THIS FILE.
6
+ - Changes may be overwritten.
7
+ - Use command: taon build:lib:watch
8
+ inside @taon-dev/i18n project repository
9
+ for watch development of third party modules like this.
10
+
11
+ * ========================================================================== */
12
+
13
+ import { AfterViewInit, DestroyRef, Directive, ElementRef, inject, Input, OnChanges, } from '@angular/core';
14
+ import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
15
+ import { Translation } from './translation';
16
+ @Directive({
17
+ selector: '[translate]',
18
+ standalone: true,
19
+ })
20
+ export class TranslateDirective implements AfterViewInit, OnChanges {
21
+ private static readonly selector = '[translate]';
22
+ @Input('translate-t')
23
+ t!: Translation;
24
+ @Input('translate-params')
25
+ params?: Record<string, unknown>;
26
+ @Input('translate-context')
27
+ translateContext?: string;
28
+ private initialized = false;
29
+ private readonly element = inject(ElementRef<HTMLElement>);
30
+ private readonly destroyRef = inject(DestroyRef);
31
+ private originalText = '';
32
+ ngAfterViewInit(): void {
33
+ const nativeElement = this.element.nativeElement;
34
+ this.validateContent();
35
+ this.originalText = nativeElement.textContent?.trim() ?? '';
36
+ this.initialized = true;
37
+ this.render();
38
+ this.t.isLoadingLang$
39
+ .pipe(takeUntilDestroyed(this.destroyRef))
40
+ .subscribe(() => {
41
+ this.render();
42
+ });
43
+ }
44
+ ngOnChanges(): void {
45
+ if (!this.initialized) {
46
+ return;
47
+ }
48
+ this.render();
49
+ }
50
+ private validateContent(): void {
51
+ const element = this.element.nativeElement;
52
+ if (element.children.length > 0) {
53
+ console.error(`[@taon-dev/i18n] ${TranslateDirective.selector} should only be used ` +
54
+ `with plain text. HTML/content elements detected inside:`, element);
55
+ }
56
+ }
57
+ private render(): void {
58
+ if (!this.t) {
59
+ throw (`Directive ${TranslateDirective.selector} applied on component ` +
60
+ `without implemented Translatable interface`);
61
+ }
62
+ this.element.nativeElement.textContent = this.t.translate(this.originalText, this.params, this.translateContext);
63
+ }
64
+ }
@@ -0,0 +1,37 @@
1
+ // @ts-nocheck
2
+ /* ============================================================================
3
+
4
+ - TAON READONLY SOURCE
5
+ - DO NOT MODIFY THIS FILE.
6
+ - Changes may be overwritten.
7
+ - Use command: taon build:lib:watch
8
+ inside @taon-dev/i18n project repository
9
+ for watch development of third party modules like this.
10
+
11
+ * ========================================================================== */
12
+
13
+ import { ChangeDetectorRef, inject, OnDestroy, Pipe, PipeTransform, } from '@angular/core';
14
+ import { Subscription } from 'rxjs';
15
+ import { Translation } from './translation';
16
+ import { TranslationManager } from './translation-manager';
17
+ @Pipe({
18
+ name: 'translate',
19
+ standalone: true,
20
+ pure: false,
21
+ })
22
+ export class TranslatePipe implements PipeTransform, OnDestroy {
23
+ private readonly cdr = inject(ChangeDetectorRef);
24
+ private tranlsationManager = TranslationManager.Instance;
25
+ private readonly sub: Subscription;
26
+ constructor() {
27
+ this.sub = this.tranlsationManager.isLoadingLangs$.subscribe(() => {
28
+ this.cdr.markForCheck();
29
+ });
30
+ }
31
+ transform(text: string, t: Translation, params?: Record<string, unknown>, context?: string): string {
32
+ return t?.gettext(text, params, context) ?? text;
33
+ }
34
+ ngOnDestroy(): void {
35
+ this.sub.unsubscribe();
36
+ }
37
+ }
@@ -0,0 +1,25 @@
1
+ // @ts-nocheck
2
+ /* ============================================================================
3
+
4
+ - TAON READONLY SOURCE
5
+ - DO NOT MODIFY THIS FILE.
6
+ - Changes may be overwritten.
7
+ - Use command: taon build:lib:watch
8
+ inside @taon-dev/i18n project repository
9
+ for watch development of third party modules like this.
10
+
11
+ * ========================================================================== */
12
+
13
+ import { Injectable } from '@angular/core';
14
+ import { UtilsI18n } from 'tnp-core/browser';
15
+ import { TranslationManager } from './translation-manager';
16
+ @Injectable({ providedIn: 'root' })
17
+ export class TranslateService {
18
+ public manager = TranslationManager.Instance;
19
+ public setOneLanguagePernament(lang: UtilsI18n.CommonLocaleCode): void {
20
+ this.manager.setOneLanguagePernament(lang);
21
+ }
22
+ async changeGlobalLang(lang: UtilsI18n.CommonLocaleCode): Promise<void> {
23
+ await this.manager.changeGlobalLang(lang);
24
+ }
25
+ }
@@ -0,0 +1,106 @@
1
+ // @ts-nocheck
2
+ /* ============================================================================
3
+
4
+ - TAON READONLY SOURCE
5
+ - DO NOT MODIFY THIS FILE.
6
+ - Changes may be overwritten.
7
+ - Use command: taon build:lib:watch
8
+ inside @taon-dev/i18n project repository
9
+ for watch development of third party modules like this.
10
+
11
+ * ========================================================================== */
12
+
13
+ import { BehaviorSubject, filter, map, tap } from 'rxjs';
14
+ import { GlobalStorage, UtilsI18n, _ } from 'tnp-core/browser';
15
+ import type { Translation } from './translation';
16
+ const globalStorageKeyMainLanguage = 'taon-gettext-main-language';
17
+ const globalTaonLanguageLocalKeyLocalStor = 'taon-language-local';
18
+ const TranslationManagerGlobalStorKey = 'TranslationManagerGlobalStorKey';
19
+ export class TranslationManager {
20
+ static globalDefautlLanguageOverride: UtilsI18n.CommonLocaleCode;
21
+ public get instances(): Set<Translation> {
22
+ let set = GlobalStorage.get(TranslationManagerGlobalStorKey) as Set<Translation>;
23
+ if (_.isNil(set)) {
24
+ GlobalStorage.set(TranslationManagerGlobalStorKey, new Set<Translation>());
25
+ }
26
+ set = GlobalStorage.get(TranslationManagerGlobalStorKey) as Set<Translation>;
27
+ return set;
28
+ }
29
+ constructor() {
30
+ }
31
+ private defaultLangLocale: UtilsI18n.CommonLocaleCode = (() => {
32
+ return ((localStorage.getItem(globalTaonLanguageLocalKeyLocalStor) as UtilsI18n.CommonLocaleCode) ||
33
+ TranslationManager.globalDefautlLanguageOverride ||
34
+ (UtilsI18n.detectLocale() as UtilsI18n.CommonLocaleCode));
35
+ return UtilsI18n.defaultLangLocale;
36
+ })();
37
+ private _currentGlobalLanguage = this
38
+ .defaultLangLocale as UtilsI18n.CommonLocaleCode;
39
+ public get currentGlobalLanguage(): UtilsI18n.CommonLocaleCode {
40
+ return this._currentGlobalLanguage;
41
+ }
42
+ public set currentGlobalLanguage(v: UtilsI18n.CommonLocaleCode) {
43
+ this._currentGlobalLanguage = v;
44
+ this.currentGlobalLanguageSrc.next(v);
45
+ }
46
+ private currentGlobalLanguageSrc = new BehaviorSubject(this.currentGlobalLanguage);
47
+ public readonly currentGlobalLanguage$ = this.currentGlobalLanguageSrc
48
+ .asObservable()
49
+ .pipe(tap(currentGlobalLanguage => {
50
+ GlobalStorage.set<UtilsI18n.CommonLocaleCode>(globalStorageKeyMainLanguage, currentGlobalLanguage);
51
+ }));
52
+ public availableLangs = _.cloneDeep(UtilsI18n.LangOptionArr);
53
+ private availableLangsSrc = new BehaviorSubject(this.availableLangs);
54
+ public readonly availableLangs$ = this.availableLangsSrc.asObservable().pipe(map(f => {
55
+ if (this.visibleLanguages.length > 0) {
56
+ return f.filter(a => this.visibleLanguages.includes(a.code));
57
+ }
58
+ return f;
59
+ }));
60
+ public _visibleLanguages: UtilsI18n.CommonLocaleCode[] = [];
61
+ public get visibleLanguages(): UtilsI18n.CommonLocaleCode[] {
62
+ return this._visibleLanguages;
63
+ }
64
+ public set visibleLanguages(v: UtilsI18n.CommonLocaleCode[]) {
65
+ if (this.pernamentLanguage) {
66
+ v = v.filter(a => [this.pernamentLanguage].includes(a));
67
+ }
68
+ this._visibleLanguages = v;
69
+ this.visibleLanguagesSrc.next(v);
70
+ this.availableLangsSrc.next(this.availableLangs);
71
+ }
72
+ private visibleLanguagesSrc = new BehaviorSubject(this.visibleLanguages);
73
+ public readonly visibleLanguages$ = this.visibleLanguagesSrc.asObservable();
74
+ private loadingLangsSubjectSrc = new BehaviorSubject(false);
75
+ public readonly isLoadingLangs$ = this.loadingLangsSubjectSrc.asObservable();
76
+ private static _instance: TranslationManager;
77
+ static get Instance(): TranslationManager {
78
+ if (!this._instance) {
79
+ this._instance = new TranslationManager();
80
+ }
81
+ return this._instance;
82
+ }
83
+ public readonly pernamentLanguage: UtilsI18n.CommonLocaleCode | null = null;
84
+ public setOneLanguagePernament(lang: UtilsI18n.CommonLocaleCode): void {
85
+ console.info(`Setting pernament language to ${lang}`);
86
+ if (this.pernamentLanguage) {
87
+ console.log('You are trying to set again pernament language');
88
+ return;
89
+ }
90
+ this.visibleLanguages = [lang];
91
+ this.pernamentLanguage = lang;
92
+ void this.changeGlobalLang(lang);
93
+ }
94
+ async changeGlobalLang(lang: UtilsI18n.CommonLocaleCode): Promise<void> {
95
+ this.loadingLangsSubjectSrc.next(true);
96
+ this.currentGlobalLanguage = lang;
97
+ localStorage.setItem(globalTaonLanguageLocalKeyLocalStor, lang);
98
+ try {
99
+ await Promise.all([...this.instances].map(c => c.useGlobalFileLang()));
100
+ }
101
+ catch (error) {
102
+ console.error(error);
103
+ }
104
+ this.loadingLangsSubjectSrc.next(false);
105
+ }
106
+ }
@@ -0,0 +1,32 @@
1
+ // @ts-nocheck
2
+ /* ============================================================================
3
+
4
+ - TAON READONLY SOURCE
5
+ - DO NOT MODIFY THIS FILE.
6
+ - Changes may be overwritten.
7
+ - Use command: taon build:lib:watch
8
+ inside @taon-dev/i18n project repository
9
+ for watch development of third party modules like this.
10
+
11
+ * ========================================================================== */
12
+
13
+ import { UtilsI18n } from 'tnp-core/browser';
14
+ import type { Translation } from './translation';
15
+ export type TranslationLookup = Record<string, string>;
16
+ export type TranslationParams = Record<string, unknown> | null;
17
+ type FileRelativeLocation = string;
18
+ export type TaonTranslationsMapImport = Record<FileRelativeLocation, {
19
+ [lang in UtilsI18n.CommonLocaleCode]?: () => Promise<UtilsI18n.GettextFile>;
20
+ }>;
21
+ export type TaonTranslationsMap = Record<FileRelativeLocation, {
22
+ [lang in UtilsI18n.CommonLocaleCode]?: UtilsI18n.GettextFile;
23
+ }>;
24
+ export interface TranslationBinding {
25
+ text: string;
26
+ params?: TranslationParams;
27
+ context?: string;
28
+ update(value: string): void;
29
+ }
30
+ export interface Translatable {
31
+ t: Translation;
32
+ }