@jsverse/transloco 7.0.0

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 (167) hide show
  1. package/CHANGELOG.md +1005 -0
  2. package/LICENSE +22 -0
  3. package/README.md +44 -0
  4. package/esm2022/index.mjs +20 -0
  5. package/esm2022/jsverse-transloco.mjs +5 -0
  6. package/esm2022/lib/browser-lang.mjs +28 -0
  7. package/esm2022/lib/get-fallbacks-loaders.mjs +13 -0
  8. package/esm2022/lib/helpers.mjs +104 -0
  9. package/esm2022/lib/lang-resolver.mjs +54 -0
  10. package/esm2022/lib/loader-component.component.mjs +21 -0
  11. package/esm2022/lib/resolve-loader.mjs +13 -0
  12. package/esm2022/lib/scope-resolver.mjs +24 -0
  13. package/esm2022/lib/shared.mjs +73 -0
  14. package/esm2022/lib/template-handler.mjs +28 -0
  15. package/esm2022/lib/transloco-fallback-strategy.mjs +26 -0
  16. package/esm2022/lib/transloco-lang.mjs +3 -0
  17. package/esm2022/lib/transloco-loading-template.mjs +3 -0
  18. package/esm2022/lib/transloco-missing-handler.mjs +18 -0
  19. package/esm2022/lib/transloco-scope.mjs +3 -0
  20. package/esm2022/lib/transloco-testing.module.mjs +76 -0
  21. package/esm2022/lib/transloco.config.mjs +37 -0
  22. package/esm2022/lib/transloco.directive.mjs +169 -0
  23. package/esm2022/lib/transloco.interceptor.mjs +17 -0
  24. package/esm2022/lib/transloco.loader.mjs +13 -0
  25. package/esm2022/lib/transloco.module.mjs +18 -0
  26. package/esm2022/lib/transloco.pipe.mjs +97 -0
  27. package/esm2022/lib/transloco.providers.mjs +92 -0
  28. package/esm2022/lib/transloco.service.mjs +579 -0
  29. package/esm2022/lib/transloco.transpiler.mjs +145 -0
  30. package/esm2022/lib/types.mjs +2 -0
  31. package/fesm2022/jsverse-transloco.mjs +1580 -0
  32. package/fesm2022/jsverse-transloco.mjs.map +1 -0
  33. package/index.d.ts +19 -0
  34. package/lib/browser-lang.d.ts +8 -0
  35. package/lib/get-fallbacks-loaders.d.ts +14 -0
  36. package/lib/helpers.d.ts +21 -0
  37. package/lib/lang-resolver.d.ts +32 -0
  38. package/lib/loader-component.component.d.ts +6 -0
  39. package/lib/resolve-loader.d.ts +10 -0
  40. package/lib/scope-resolver.d.ts +12 -0
  41. package/lib/shared.d.ts +17 -0
  42. package/lib/template-handler.d.ts +9 -0
  43. package/lib/transloco-fallback-strategy.d.ts +14 -0
  44. package/lib/transloco-lang.d.ts +2 -0
  45. package/lib/transloco-loading-template.d.ts +3 -0
  46. package/lib/transloco-missing-handler.d.ts +16 -0
  47. package/lib/transloco-scope.d.ts +3 -0
  48. package/lib/transloco-testing.module.d.ts +27 -0
  49. package/lib/transloco.config.d.ts +27 -0
  50. package/lib/transloco.directive.d.ts +50 -0
  51. package/lib/transloco.interceptor.d.ts +14 -0
  52. package/lib/transloco.loader.d.ts +15 -0
  53. package/lib/transloco.module.d.ts +8 -0
  54. package/lib/transloco.pipe.d.ts +23 -0
  55. package/lib/transloco.providers.d.ts +30 -0
  56. package/lib/transloco.service.d.ts +199 -0
  57. package/lib/transloco.transpiler.d.ts +58 -0
  58. package/lib/types.d.ts +45 -0
  59. package/package.json +54 -0
  60. package/schematics/src/assets/i18n/en.json +1 -0
  61. package/schematics/src/collection.json +59 -0
  62. package/schematics/src/component/index.d.ts +2 -0
  63. package/schematics/src/component/index.js +21 -0
  64. package/schematics/src/component/index.js.map +1 -0
  65. package/schematics/src/join/index.d.ts +3 -0
  66. package/schematics/src/join/index.js +79 -0
  67. package/schematics/src/join/index.js.map +1 -0
  68. package/schematics/src/join/schema.d.ts +28 -0
  69. package/schematics/src/join/schema.js +3 -0
  70. package/schematics/src/join/schema.js.map +1 -0
  71. package/schematics/src/join/schema.json +43 -0
  72. package/schematics/src/keys-manager/index.d.ts +5 -0
  73. package/schematics/src/keys-manager/index.js +97 -0
  74. package/schematics/src/keys-manager/index.js.map +1 -0
  75. package/schematics/src/keys-manager/schema.d.ts +19 -0
  76. package/schematics/src/keys-manager/schema.js +3 -0
  77. package/schematics/src/keys-manager/schema.js.map +1 -0
  78. package/schematics/src/keys-manager/schema.json +33 -0
  79. package/schematics/src/migrate/index.d.ts +3 -0
  80. package/schematics/src/migrate/index.js +21 -0
  81. package/schematics/src/migrate/index.js.map +1 -0
  82. package/schematics/src/migrate/ngx-translate-migration.d.ts +3 -0
  83. package/schematics/src/migrate/ngx-translate-migration.js +169 -0
  84. package/schematics/src/migrate/ngx-translate-migration.js.map +1 -0
  85. package/schematics/src/migrate/schema.d.ts +10 -0
  86. package/schematics/src/migrate/schema.js +3 -0
  87. package/schematics/src/migrate/schema.js.map +1 -0
  88. package/schematics/src/migrate/schema.json +23 -0
  89. package/schematics/src/ng-add/files/transloco-loader/transloco-loader.__ts__ +12 -0
  90. package/schematics/src/ng-add/files/transloco-module/transloco-root.module.__ts__ +24 -0
  91. package/schematics/src/ng-add/generators/http-loader.gen.d.ts +4 -0
  92. package/schematics/src/ng-add/generators/http-loader.gen.js +15 -0
  93. package/schematics/src/ng-add/generators/http-loader.gen.js.map +1 -0
  94. package/schematics/src/ng-add/generators/root-module.gen.d.ts +9 -0
  95. package/schematics/src/ng-add/generators/root-module.gen.js +31 -0
  96. package/schematics/src/ng-add/generators/root-module.gen.js.map +1 -0
  97. package/schematics/src/ng-add/generators/translation-files.gen.d.ts +4 -0
  98. package/schematics/src/ng-add/generators/translation-files.gen.js +23 -0
  99. package/schematics/src/ng-add/generators/translation-files.gen.js.map +1 -0
  100. package/schematics/src/ng-add/index.d.ts +3 -0
  101. package/schematics/src/ng-add/index.js +103 -0
  102. package/schematics/src/ng-add/index.js.map +1 -0
  103. package/schematics/src/ng-add/schema.d.ts +42 -0
  104. package/schematics/src/ng-add/schema.js +14 -0
  105. package/schematics/src/ng-add/schema.js.map +1 -0
  106. package/schematics/src/ng-add/schema.json +53 -0
  107. package/schematics/src/ng-migrate/index.d.ts +3 -0
  108. package/schematics/src/ng-migrate/index.js +14 -0
  109. package/schematics/src/ng-migrate/index.js.map +1 -0
  110. package/schematics/src/ng-migrate/ng-migrate.d.ts +5 -0
  111. package/schematics/src/ng-migrate/ng-migrate.js +106 -0
  112. package/schematics/src/ng-migrate/ng-migrate.js.map +1 -0
  113. package/schematics/src/ng-migrate/schema.d.ts +14 -0
  114. package/schematics/src/ng-migrate/schema.js +3 -0
  115. package/schematics/src/ng-migrate/schema.js.map +1 -0
  116. package/schematics/src/ng-migrate/schema.json +27 -0
  117. package/schematics/src/schematics.consts.d.ts +4 -0
  118. package/schematics/src/schematics.consts.js +8 -0
  119. package/schematics/src/schematics.consts.js.map +1 -0
  120. package/schematics/src/scope/index.d.ts +3 -0
  121. package/schematics/src/scope/index.js +101 -0
  122. package/schematics/src/scope/index.js.map +1 -0
  123. package/schematics/src/scope/schema.d.ts +28 -0
  124. package/schematics/src/scope/schema.js +3 -0
  125. package/schematics/src/scope/schema.js.map +1 -0
  126. package/schematics/src/scope/schema.json +84 -0
  127. package/schematics/src/split/index.d.ts +3 -0
  128. package/schematics/src/split/index.js +66 -0
  129. package/schematics/src/split/index.js.map +1 -0
  130. package/schematics/src/split/schema.d.ts +20 -0
  131. package/schematics/src/split/schema.js +3 -0
  132. package/schematics/src/split/schema.js.map +1 -0
  133. package/schematics/src/split/schema.json +35 -0
  134. package/schematics/src/types.d.ts +5 -0
  135. package/schematics/src/types.js +10 -0
  136. package/schematics/src/types.js.map +1 -0
  137. package/schematics/src/upgrade/index.d.ts +3 -0
  138. package/schematics/src/upgrade/index.js +19 -0
  139. package/schematics/src/upgrade/index.js.map +1 -0
  140. package/schematics/src/upgrade/schema.d.ts +6 -0
  141. package/schematics/src/upgrade/schema.js +3 -0
  142. package/schematics/src/upgrade/schema.js.map +1 -0
  143. package/schematics/src/upgrade/schema.json +16 -0
  144. package/schematics/src/upgrade/v2.d.ts +1 -0
  145. package/schematics/src/upgrade/v2.js +89 -0
  146. package/schematics/src/upgrade/v2.js.map +1 -0
  147. package/schematics/src/utils/array.d.ts +3 -0
  148. package/schematics/src/utils/array.js +12 -0
  149. package/schematics/src/utils/array.js.map +1 -0
  150. package/schematics/src/utils/config.d.ts +2 -0
  151. package/schematics/src/utils/config.js +13 -0
  152. package/schematics/src/utils/config.js.map +1 -0
  153. package/schematics/src/utils/find-module.d.ts +23 -0
  154. package/schematics/src/utils/find-module.js +110 -0
  155. package/schematics/src/utils/find-module.js.map +1 -0
  156. package/schematics/src/utils/package.d.ts +5 -0
  157. package/schematics/src/utils/package.js +19 -0
  158. package/schematics/src/utils/package.js.map +1 -0
  159. package/schematics/src/utils/projects.d.ts +8 -0
  160. package/schematics/src/utils/projects.js +56 -0
  161. package/schematics/src/utils/projects.js.map +1 -0
  162. package/schematics/src/utils/translations.d.ts +7 -0
  163. package/schematics/src/utils/translations.js +31 -0
  164. package/schematics/src/utils/translations.js.map +1 -0
  165. package/schematics/src/utils/transloco.d.ts +24 -0
  166. package/schematics/src/utils/transloco.js +93 -0
  167. package/schematics/src/utils/transloco.js.map +1 -0
@@ -0,0 +1,8 @@
1
+ import { WorkspaceSchema } from '@schematics/angular/utility/workspace-models';
2
+ import { Tree } from '@angular-devkit/schematics';
3
+ export declare function getWorkspacePath(host: Tree): string;
4
+ export declare function getWorkspace(host: Tree): WorkspaceSchema;
5
+ export declare function setWorkspace(host: Tree, workspace: any): void;
6
+ export declare function getProject(host: Tree, project?: string): import("@schematics/angular/utility/workspace-models").WorkspaceProject<import("@schematics/angular/utility/workspace-models").ProjectType>;
7
+ export declare function setEnvironments(host: Tree, sourceRoot: string, transformer: (env: string) => string): void;
8
+ export declare function getProjectPath(host: Tree, project: any, options: any): any;
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getProjectPath = exports.setEnvironments = exports.getProject = exports.setWorkspace = exports.getWorkspace = exports.getWorkspacePath = void 0;
4
+ const schematics_1 = require("@angular-devkit/schematics");
5
+ function getWorkspacePath(host) {
6
+ const possibleFiles = ['/angular.json', '/.angular.json'];
7
+ const [path] = possibleFiles.filter((path) => host.exists(path));
8
+ return path;
9
+ }
10
+ exports.getWorkspacePath = getWorkspacePath;
11
+ function getWorkspace(host) {
12
+ const path = getWorkspacePath(host);
13
+ const configBuffer = host.read(path);
14
+ if (configBuffer === null) {
15
+ throw new schematics_1.SchematicsException(`Could not find (${path})`);
16
+ }
17
+ const config = configBuffer.toString();
18
+ return JSON.parse(config);
19
+ }
20
+ exports.getWorkspace = getWorkspace;
21
+ function setWorkspace(host, workspace) {
22
+ const path = getWorkspacePath(host);
23
+ host.overwrite(path, JSON.stringify(workspace, null, 2));
24
+ }
25
+ exports.setWorkspace = setWorkspace;
26
+ function getProject(host, project) {
27
+ const workspace = getWorkspace(host);
28
+ if (workspace) {
29
+ return workspace.projects[project];
30
+ }
31
+ throw new schematics_1.SchematicsException('could not find a workspace project');
32
+ }
33
+ exports.getProject = getProject;
34
+ function setEnvironments(host, sourceRoot, transformer) {
35
+ const path = sourceRoot + '/environments';
36
+ const environments = host.getDir(path);
37
+ return environments.subfiles.forEach((file) => {
38
+ const filePath = `${path}/${file}`;
39
+ const configBuffer = host.read(filePath);
40
+ const source = configBuffer.toString('utf-8');
41
+ host.overwrite(filePath, transformer(source));
42
+ });
43
+ }
44
+ exports.setEnvironments = setEnvironments;
45
+ function getProjectPath(host, project, options) {
46
+ if (project.root.substr(-1) === '/') {
47
+ project.root = project.root.substr(0, project.root.length - 1);
48
+ }
49
+ if (options.path === undefined) {
50
+ const projectDirName = project.projectType === 'application' ? 'app' : 'lib';
51
+ return `${project.root ? `/${project.root}` : ''}/src/${projectDirName}`;
52
+ }
53
+ return options.path;
54
+ }
55
+ exports.getProjectPath = getProjectPath;
56
+ //# sourceMappingURL=projects.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"projects.js","sourceRoot":"","sources":["../../../../../../libs/transloco-schematics/src/utils/projects.ts"],"names":[],"mappings":";;;AACA,2DAAuE;AAEvE,SAAgB,gBAAgB,CAAC,IAAU;IACzC,MAA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e,CAAC;IAC1C,MAAM,YAAY,GAAG,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IACvC,OAAO,YAAY,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;QAC5C,MAAM,QAAQ,GAAG,GAAG,IAAI,IAAI,IAAI,EAAE,CAAC;QACnC,MAAM,YAAY,GAAG,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QACzC,MAAM,MAAM,GAAG,YAAY,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;QAC9C,IAAI,CAAC,SAAS,CAAC,QAAQ,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC,CAAC;IAChD,CAAC,CAAC,CAAC;AACL,CAAC;AAbD,0CAaC;AAED,SAAgB,cAAc,CAAC,IAAU,EAAE,OAAO,EAAE,OAAO;IACzD,IAAI,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,KAAK,GAAG,EAAE;QACnC,OAAO,CAAC,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,EAAE,OAAO,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;KAChE;IAED,IAAI,OAAO,CAAC,IAAI,KAAK,SAAS,EAAE;QAC9B,MAAM,cAAc,GAClB,OAAO,CAAC,WAAW,KAAK,aAAa,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC;QAExD,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,QAAQ,cAAc,EAAE,CAAC;KAC1E;IAED,OAAO,OAAO,CAAC,IAAI,CAAC;AACtB,CAAC;AAbD,wCAaC"}
@@ -0,0 +1,7 @@
1
+ import { Tree } from '@angular-devkit/schematics';
2
+ import { TranslationFileTypes } from '../ng-add/schema';
3
+ export declare function checkIfTranslationFilesExist(path: string, langs: string[], extension: string, skipThrow?: boolean): boolean;
4
+ export declare function createTranslateFilesFromOptions(host: Tree, options: {
5
+ translateType?: TranslationFileTypes;
6
+ langs: string[];
7
+ }, translationFilePath: any): import("@angular-devkit/schematics").Source;
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createTranslateFilesFromOptions = exports.checkIfTranslationFilesExist = void 0;
4
+ const p = require("node:path");
5
+ const fs = require("fs");
6
+ const schematics_1 = require("@angular-devkit/schematics");
7
+ const schema_1 = require("../ng-add/schema");
8
+ const translation_files_gen_1 = require("../ng-add/generators/translation-files.gen");
9
+ function checkIfTranslationFilesExist(path, langs, extension, skipThrow) {
10
+ for (const lang of langs) {
11
+ const filePath = p.resolve(`${path}/${lang}${extension}`);
12
+ if (fs.existsSync(filePath)) {
13
+ if (skipThrow) {
14
+ return true;
15
+ }
16
+ throw new schematics_1.SchematicsException(`Translation file ${filePath} is already exist, please use --skip-creation`);
17
+ }
18
+ }
19
+ return false;
20
+ }
21
+ exports.checkIfTranslationFilesExist = checkIfTranslationFilesExist;
22
+ function createTranslateFilesFromOptions(host, options, translationFilePath) {
23
+ const extension = options.translateType === schema_1.TranslationFileTypes.Typescript ? '.ts' : '.json';
24
+ const translationCreator = options.translateType === schema_1.TranslationFileTypes.Typescript
25
+ ? translation_files_gen_1.typescriptTranslationFileCreator
26
+ : translation_files_gen_1.jsonTranslationFileCreator;
27
+ checkIfTranslationFilesExist(translationFilePath, options.langs, extension);
28
+ return (0, translation_files_gen_1.createTranslateFiles)(options.langs, translationCreator, translationFilePath);
29
+ }
30
+ exports.createTranslateFilesFromOptions = createTranslateFilesFromOptions;
31
+ //# sourceMappingURL=translations.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"translations.js","sourceRoot":"","sources":["../../../../../../libs/transloco-schematics/src/utils/translations.ts"],"names":[],"mappings":";;;AAAA,+BAA+B;AAC/B,yBAAyB;AAEzB,2DAAuE;AAEvE,6CAAwD;AACxD,sFAIoD;AAEpD,SAAgB,4BAA4B,CAC1C,IAAY,EACZ,KAAe,EACf,SAAiB,EACjB,SAAmB;IAEnB,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE;QACxB,MAAM,QAAQ,GAAG,CAAC,CAAC,OAAO,CAAC,GAAG,IAAI,IAAI,IAAI,GAAG,SAAS,EAAE,CAAC,CAAC;QAC1D,IAAI,EAAE,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE;YAC3B,IAAI,SAAS,EAAE;gBACb,OAAO,IAAI,CAAC;aACb;YACD,MAAM,IAAI,gCAAmB,CAC3B,oBAAoB,QAAQ,+CAA+C,CAC5E,CAAC;SACH;KACF;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAlBD,oEAkBC;AAED,SAAgB,+BAA+B,CAC7C,IAAU,EACV,OAAkE,EAClE,mBAAmB;IAEnB,MAAM,SAAS,GACb,OAAO,CAAC,aAAa,KAAK,6BAAoB,CAAC,UAAU,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,OAAO,CAAC;IAC9E,MAAM,kBAAkB,GACtB,OAAO,CAAC,aAAa,KAAK,6BAAoB,CAAC,UAAU;QACvD,CAAC,CAAC,wDAAgC;QAClC,CAAC,CAAC,kDAA0B,CAAC;IAEjC,4BAA4B,CAAC,mBAAmB,EAAE,OAAO,CAAC,KAAK,EAAE,SAAS,CAAC,CAAC;IAE5E,OAAO,IAAA,4CAAoB,EACzB,OAAO,CAAC,KAAK,EACb,kBAAkB,EAClB,mBAAmB,CACpB,CAAC;AACJ,CAAC;AAnBD,0EAmBC"}
@@ -0,0 +1,24 @@
1
+ import { PathFragment } from '@angular-devkit/core';
2
+ import { DirEntry, Tree } from '@angular-devkit/schematics';
3
+ import { TranslocoGlobalConfig } from '@jsverse/transloco-utils';
4
+ import { SchemaOptions } from '../join/schema';
5
+ export declare function createConfig(host: Tree, langs: string[], rootTranslationsPath?: string): void;
6
+ export declare function updateConfig(host: Tree, config: TranslocoGlobalConfig): void;
7
+ export declare function getJsonFileContent(fileName: PathFragment, dir: DirEntry, parser?: (text: string, reviver?: (this: any, key: string, value: any) => any) => any): any;
8
+ export declare function setFileContent(host: Tree, dirPath: string, fileName: PathFragment, content: any): void;
9
+ export declare function hasSubdirs(dir: DirEntry): number;
10
+ export declare function hasFiles(dir: DirEntry): number;
11
+ export declare function getTranslationKey(prefix: string, key: any): any;
12
+ export declare function getTranslationsRoot(host: Tree, options: {
13
+ project?: string;
14
+ translationPath?: string;
15
+ }): string;
16
+ export declare function getTranslationFiles(host: Tree, root: string, parser?: any): {
17
+ lang: string;
18
+ translation: Record<string, unknown>;
19
+ }[];
20
+ export declare function getTranslationEntryPaths(host: Tree, rootDirPath: string): {
21
+ scope: string;
22
+ path: string;
23
+ }[];
24
+ export declare function getDefaultLang(options: SchemaOptions): string;
@@ -0,0 +1,93 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getDefaultLang = exports.getTranslationEntryPaths = exports.getTranslationFiles = exports.getTranslationsRoot = exports.getTranslationKey = exports.hasFiles = exports.hasSubdirs = exports.setFileContent = exports.getJsonFileContent = exports.updateConfig = exports.createConfig = void 0;
4
+ const p = require("node:path");
5
+ const schematics_consts_1 = require("../schematics.consts");
6
+ const array_1 = require("./array");
7
+ const projects_1 = require("./projects");
8
+ const config_1 = require("./config");
9
+ function createConfig(host, langs, rootTranslationsPath = 'assets/i18n/') {
10
+ if (!host.get(schematics_consts_1.CONFIG_FILE)) {
11
+ const config = `module.exports = {
12
+ rootTranslationsPath: '${rootTranslationsPath}',
13
+ langs: [${(0, array_1.stringifyList)(langs)}],
14
+ keysManager: {}
15
+ };`;
16
+ host.create(schematics_consts_1.CONFIG_FILE, config);
17
+ }
18
+ }
19
+ exports.createConfig = createConfig;
20
+ function updateConfig(host, config) {
21
+ const originalConfig = (0, config_1.getConfig)();
22
+ if (!originalConfig || Object.keys(originalConfig).length === 0) {
23
+ return createConfig(host, config.langs, config.rootTranslationsPath);
24
+ }
25
+ const stringifyConfig = JSON.stringify({ ...config, ...originalConfig }, null, 2);
26
+ const content = `module.exports = ${stringifyConfig};`;
27
+ host.overwrite(schematics_consts_1.CONFIG_FILE, content);
28
+ }
29
+ exports.updateConfig = updateConfig;
30
+ function getJsonFileContent(fileName, dir, parser = JSON.parse) {
31
+ return parser(dir.file(fileName).content.toString('utf-8'));
32
+ }
33
+ exports.getJsonFileContent = getJsonFileContent;
34
+ function setFileContent(host, dirPath, fileName, content) {
35
+ return host.overwrite(p.join(dirPath, fileName), JSON.stringify(content, null, 2));
36
+ }
37
+ exports.setFileContent = setFileContent;
38
+ function hasSubdirs(dir) {
39
+ return dir.subdirs && dir.subdirs.length;
40
+ }
41
+ exports.hasSubdirs = hasSubdirs;
42
+ function hasFiles(dir) {
43
+ return dir.subfiles && dir.subfiles.length;
44
+ }
45
+ exports.hasFiles = hasFiles;
46
+ function getTranslationKey(prefix = '', key) {
47
+ return prefix ? `${prefix}.${key}` : key;
48
+ }
49
+ exports.getTranslationKey = getTranslationKey;
50
+ function getTranslationsRoot(host, options) {
51
+ const translocoConfig = (0, config_1.getConfig)();
52
+ if (options.translationPath) {
53
+ return options.translationPath;
54
+ }
55
+ else if (translocoConfig && translocoConfig.rootTranslationsPath) {
56
+ return translocoConfig.rootTranslationsPath;
57
+ }
58
+ else {
59
+ const project = (0, projects_1.getProject)(host, options.project);
60
+ const rootPath = (project && project.sourceRoot) || 'src';
61
+ return p.join(rootPath, 'assets', 'i18n');
62
+ }
63
+ }
64
+ exports.getTranslationsRoot = getTranslationsRoot;
65
+ function getTranslationFiles(host, root, parser) {
66
+ const rootDir = host.getDir(root);
67
+ return rootDir.subfiles.map((fileName) => ({
68
+ lang: fileName.split('.')[0],
69
+ translation: getJsonFileContent(fileName, rootDir, parser),
70
+ }));
71
+ }
72
+ exports.getTranslationFiles = getTranslationFiles;
73
+ function getTranslationEntryPaths(host, rootDirPath) {
74
+ const translocoConfig = (0, config_1.getConfig)();
75
+ if (translocoConfig.scopePathMap &&
76
+ Object.keys(translocoConfig.scopePathMap).length) {
77
+ return Object.entries(translocoConfig.scopePathMap).map(([scope, path]) => ({
78
+ scope,
79
+ path,
80
+ }));
81
+ }
82
+ const rootDir = host.getDir(rootDirPath);
83
+ return rootDir.subdirs.map((subDir) => ({
84
+ scope: subDir,
85
+ path: p.join(rootDirPath, subDir),
86
+ }));
87
+ }
88
+ exports.getTranslationEntryPaths = getTranslationEntryPaths;
89
+ function getDefaultLang(options) {
90
+ return options.defaultLang || (0, config_1.getConfig)().defaultLang;
91
+ }
92
+ exports.getDefaultLang = getDefaultLang;
93
+ //# sourceMappingURL=transloco.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transloco.js","sourceRoot":"","sources":["../../../../../../libs/transloco-schematics/src/utils/transloco.ts"],"names":[],"mappings":";;;AAAA,+BAA+B;AAO/B,4DAAmD;AAEnD,mCAAwC;AACxC,yCAAwC;AACxC,qCAAqC;AAErC,SAAgB,YAAY,CAC1B,IAAU,EACV,KAAe,EACf,oBAAoB,GAAG,cAAc;IAErC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,+BAAW,CAAC,EAAE;QAC1B,MAAM,MAAM,GAAG;2BACQ,oBAAoB;YACnC,IAAA,qBAAa,EAAC,KAAK,CAAC;;GAE7B,CAAC;QACA,IAAI,CAAC,MAAM,CAAC,+BAAW,EAAE,MAAM,CAAC,CAAC;KAClC;AACH,CAAC;AAbD,oCAaC;AAED,SAAgB,YAAY,CAAC,IAAU,EAAE,MAA6B;IACpE,MAAM,cAAc,GAAG,IAAA,kBAAS,GAAE,CAAC;IACnC,IAAI,CAAC,cAAc,IAAI,MAAM,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC,MAAM,KAAK,CAAC,EAAE;QAC/D,OAAO,YAAY,CAAC,IAAI,EAAE,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,oBAAoB,CAAC,CAAC;KACtE;IACD,MAAM,eAAe,GAAG,IAAI,CAAC,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