@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.
- package/CHANGELOG.md +1005 -0
- package/LICENSE +22 -0
- package/README.md +44 -0
- package/esm2022/index.mjs +20 -0
- package/esm2022/jsverse-transloco.mjs +5 -0
- package/esm2022/lib/browser-lang.mjs +28 -0
- package/esm2022/lib/get-fallbacks-loaders.mjs +13 -0
- package/esm2022/lib/helpers.mjs +104 -0
- package/esm2022/lib/lang-resolver.mjs +54 -0
- package/esm2022/lib/loader-component.component.mjs +21 -0
- package/esm2022/lib/resolve-loader.mjs +13 -0
- package/esm2022/lib/scope-resolver.mjs +24 -0
- package/esm2022/lib/shared.mjs +73 -0
- package/esm2022/lib/template-handler.mjs +28 -0
- package/esm2022/lib/transloco-fallback-strategy.mjs +26 -0
- package/esm2022/lib/transloco-lang.mjs +3 -0
- package/esm2022/lib/transloco-loading-template.mjs +3 -0
- package/esm2022/lib/transloco-missing-handler.mjs +18 -0
- package/esm2022/lib/transloco-scope.mjs +3 -0
- package/esm2022/lib/transloco-testing.module.mjs +76 -0
- package/esm2022/lib/transloco.config.mjs +37 -0
- package/esm2022/lib/transloco.directive.mjs +169 -0
- package/esm2022/lib/transloco.interceptor.mjs +17 -0
- package/esm2022/lib/transloco.loader.mjs +13 -0
- package/esm2022/lib/transloco.module.mjs +18 -0
- package/esm2022/lib/transloco.pipe.mjs +97 -0
- package/esm2022/lib/transloco.providers.mjs +92 -0
- package/esm2022/lib/transloco.service.mjs +579 -0
- package/esm2022/lib/transloco.transpiler.mjs +145 -0
- package/esm2022/lib/types.mjs +2 -0
- package/fesm2022/jsverse-transloco.mjs +1580 -0
- package/fesm2022/jsverse-transloco.mjs.map +1 -0
- package/index.d.ts +19 -0
- package/lib/browser-lang.d.ts +8 -0
- package/lib/get-fallbacks-loaders.d.ts +14 -0
- package/lib/helpers.d.ts +21 -0
- package/lib/lang-resolver.d.ts +32 -0
- package/lib/loader-component.component.d.ts +6 -0
- package/lib/resolve-loader.d.ts +10 -0
- package/lib/scope-resolver.d.ts +12 -0
- package/lib/shared.d.ts +17 -0
- package/lib/template-handler.d.ts +9 -0
- package/lib/transloco-fallback-strategy.d.ts +14 -0
- package/lib/transloco-lang.d.ts +2 -0
- package/lib/transloco-loading-template.d.ts +3 -0
- package/lib/transloco-missing-handler.d.ts +16 -0
- package/lib/transloco-scope.d.ts +3 -0
- package/lib/transloco-testing.module.d.ts +27 -0
- package/lib/transloco.config.d.ts +27 -0
- package/lib/transloco.directive.d.ts +50 -0
- package/lib/transloco.interceptor.d.ts +14 -0
- package/lib/transloco.loader.d.ts +15 -0
- package/lib/transloco.module.d.ts +8 -0
- package/lib/transloco.pipe.d.ts +23 -0
- package/lib/transloco.providers.d.ts +30 -0
- package/lib/transloco.service.d.ts +199 -0
- package/lib/transloco.transpiler.d.ts +58 -0
- package/lib/types.d.ts +45 -0
- package/package.json +54 -0
- package/schematics/src/assets/i18n/en.json +1 -0
- package/schematics/src/collection.json +59 -0
- package/schematics/src/component/index.d.ts +2 -0
- package/schematics/src/component/index.js +21 -0
- package/schematics/src/component/index.js.map +1 -0
- package/schematics/src/join/index.d.ts +3 -0
- package/schematics/src/join/index.js +79 -0
- package/schematics/src/join/index.js.map +1 -0
- package/schematics/src/join/schema.d.ts +28 -0
- package/schematics/src/join/schema.js +3 -0
- package/schematics/src/join/schema.js.map +1 -0
- package/schematics/src/join/schema.json +43 -0
- package/schematics/src/keys-manager/index.d.ts +5 -0
- package/schematics/src/keys-manager/index.js +97 -0
- package/schematics/src/keys-manager/index.js.map +1 -0
- package/schematics/src/keys-manager/schema.d.ts +19 -0
- package/schematics/src/keys-manager/schema.js +3 -0
- package/schematics/src/keys-manager/schema.js.map +1 -0
- package/schematics/src/keys-manager/schema.json +33 -0
- package/schematics/src/migrate/index.d.ts +3 -0
- package/schematics/src/migrate/index.js +21 -0
- package/schematics/src/migrate/index.js.map +1 -0
- package/schematics/src/migrate/ngx-translate-migration.d.ts +3 -0
- package/schematics/src/migrate/ngx-translate-migration.js +169 -0
- package/schematics/src/migrate/ngx-translate-migration.js.map +1 -0
- package/schematics/src/migrate/schema.d.ts +10 -0
- package/schematics/src/migrate/schema.js +3 -0
- package/schematics/src/migrate/schema.js.map +1 -0
- package/schematics/src/migrate/schema.json +23 -0
- package/schematics/src/ng-add/files/transloco-loader/transloco-loader.__ts__ +12 -0
- package/schematics/src/ng-add/files/transloco-module/transloco-root.module.__ts__ +24 -0
- package/schematics/src/ng-add/generators/http-loader.gen.d.ts +4 -0
- package/schematics/src/ng-add/generators/http-loader.gen.js +15 -0
- package/schematics/src/ng-add/generators/http-loader.gen.js.map +1 -0
- package/schematics/src/ng-add/generators/root-module.gen.d.ts +9 -0
- package/schematics/src/ng-add/generators/root-module.gen.js +31 -0
- package/schematics/src/ng-add/generators/root-module.gen.js.map +1 -0
- package/schematics/src/ng-add/generators/translation-files.gen.d.ts +4 -0
- package/schematics/src/ng-add/generators/translation-files.gen.js +23 -0
- package/schematics/src/ng-add/generators/translation-files.gen.js.map +1 -0
- package/schematics/src/ng-add/index.d.ts +3 -0
- package/schematics/src/ng-add/index.js +103 -0
- package/schematics/src/ng-add/index.js.map +1 -0
- package/schematics/src/ng-add/schema.d.ts +42 -0
- package/schematics/src/ng-add/schema.js +14 -0
- package/schematics/src/ng-add/schema.js.map +1 -0
- package/schematics/src/ng-add/schema.json +53 -0
- package/schematics/src/ng-migrate/index.d.ts +3 -0
- package/schematics/src/ng-migrate/index.js +14 -0
- package/schematics/src/ng-migrate/index.js.map +1 -0
- package/schematics/src/ng-migrate/ng-migrate.d.ts +5 -0
- package/schematics/src/ng-migrate/ng-migrate.js +106 -0
- package/schematics/src/ng-migrate/ng-migrate.js.map +1 -0
- package/schematics/src/ng-migrate/schema.d.ts +14 -0
- package/schematics/src/ng-migrate/schema.js +3 -0
- package/schematics/src/ng-migrate/schema.js.map +1 -0
- package/schematics/src/ng-migrate/schema.json +27 -0
- package/schematics/src/schematics.consts.d.ts +4 -0
- package/schematics/src/schematics.consts.js +8 -0
- package/schematics/src/schematics.consts.js.map +1 -0
- package/schematics/src/scope/index.d.ts +3 -0
- package/schematics/src/scope/index.js +101 -0
- package/schematics/src/scope/index.js.map +1 -0
- package/schematics/src/scope/schema.d.ts +28 -0
- package/schematics/src/scope/schema.js +3 -0
- package/schematics/src/scope/schema.js.map +1 -0
- package/schematics/src/scope/schema.json +84 -0
- package/schematics/src/split/index.d.ts +3 -0
- package/schematics/src/split/index.js +66 -0
- package/schematics/src/split/index.js.map +1 -0
- package/schematics/src/split/schema.d.ts +20 -0
- package/schematics/src/split/schema.js +3 -0
- package/schematics/src/split/schema.js.map +1 -0
- package/schematics/src/split/schema.json +35 -0
- package/schematics/src/types.d.ts +5 -0
- package/schematics/src/types.js +10 -0
- package/schematics/src/types.js.map +1 -0
- package/schematics/src/upgrade/index.d.ts +3 -0
- package/schematics/src/upgrade/index.js +19 -0
- package/schematics/src/upgrade/index.js.map +1 -0
- package/schematics/src/upgrade/schema.d.ts +6 -0
- package/schematics/src/upgrade/schema.js +3 -0
- package/schematics/src/upgrade/schema.js.map +1 -0
- package/schematics/src/upgrade/schema.json +16 -0
- package/schematics/src/upgrade/v2.d.ts +1 -0
- package/schematics/src/upgrade/v2.js +89 -0
- package/schematics/src/upgrade/v2.js.map +1 -0
- package/schematics/src/utils/array.d.ts +3 -0
- package/schematics/src/utils/array.js +12 -0
- package/schematics/src/utils/array.js.map +1 -0
- package/schematics/src/utils/config.d.ts +2 -0
- package/schematics/src/utils/config.js +13 -0
- package/schematics/src/utils/config.js.map +1 -0
- package/schematics/src/utils/find-module.d.ts +23 -0
- package/schematics/src/utils/find-module.js +110 -0
- package/schematics/src/utils/find-module.js.map +1 -0
- package/schematics/src/utils/package.d.ts +5 -0
- package/schematics/src/utils/package.js +19 -0
- package/schematics/src/utils/package.js.map +1 -0
- package/schematics/src/utils/projects.d.ts +8 -0
- package/schematics/src/utils/projects.js +56 -0
- package/schematics/src/utils/projects.js.map +1 -0
- package/schematics/src/utils/translations.d.ts +7 -0
- package/schematics/src/utils/translations.js +31 -0
- package/schematics/src/utils/translations.js.map +1 -0
- package/schematics/src/utils/transloco.d.ts +24 -0
- package/schematics/src/utils/transloco.js +93 -0
- package/schematics/src/utils/transloco.js.map +1 -0
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const node_path_1 = require("node:path");
|
|
4
|
+
const schematics_1 = require("@angular-devkit/schematics");
|
|
5
|
+
const ng_ast_utils_1 = require("@schematics/angular/utility/ng-ast-utils");
|
|
6
|
+
const util_1 = require("@schematics/angular/utility/standalone/util");
|
|
7
|
+
const rules_1 = require("@schematics/angular/utility/standalone/rules");
|
|
8
|
+
const app_config_1 = require("@schematics/angular/utility/standalone/app_config");
|
|
9
|
+
const array_1 = require("../utils/array");
|
|
10
|
+
const projects_1 = require("../utils/projects");
|
|
11
|
+
const translations_1 = require("../utils/translations");
|
|
12
|
+
const transloco_1 = require("../utils/transloco");
|
|
13
|
+
const schema_1 = require("./schema");
|
|
14
|
+
const http_loader_gen_1 = require("./generators/http-loader.gen");
|
|
15
|
+
const translation_files_gen_1 = require("./generators/translation-files.gen");
|
|
16
|
+
const root_module_gen_1 = require("./generators/root-module.gen");
|
|
17
|
+
function updateEnvironmentBaseUrl(host, sourceRoot, defaultValue) {
|
|
18
|
+
const template = `$1{
|
|
19
|
+
baseUrl: '${defaultValue}',`;
|
|
20
|
+
(0, projects_1.setEnvironments)(host, sourceRoot, (env) => env.indexOf('baseUrl') === -1
|
|
21
|
+
? env.replace(/(environment.*=*)\{/, template)
|
|
22
|
+
: env);
|
|
23
|
+
}
|
|
24
|
+
function resolveLoaderPath({ host, mainPath, isStandalone, modulePath }) {
|
|
25
|
+
let resolved = modulePath;
|
|
26
|
+
if (isStandalone) {
|
|
27
|
+
const bootstrapCall = (0, util_1.findBootstrapApplicationCall)(host, mainPath);
|
|
28
|
+
resolved =
|
|
29
|
+
(0, app_config_1.findAppConfig)(bootstrapCall, host, mainPath)?.filePath || mainPath;
|
|
30
|
+
resolved = (0, node_path_1.dirname)(resolved);
|
|
31
|
+
}
|
|
32
|
+
return resolved;
|
|
33
|
+
}
|
|
34
|
+
function default_1(options) {
|
|
35
|
+
return async (host, context) => {
|
|
36
|
+
const langs = options.langs.split(',').map((l) => l.trim());
|
|
37
|
+
const project = (0, projects_1.getProject)(host, options.project);
|
|
38
|
+
const sourceRoot = project.sourceRoot ?? 'src';
|
|
39
|
+
const isLib = project.projectType === 'library';
|
|
40
|
+
const assetsPath = `${sourceRoot}/${options.path}`;
|
|
41
|
+
const mainPath = await (0, util_1.getMainFilePath)(host, options.project);
|
|
42
|
+
const isStandalone = (0, ng_ast_utils_1.isStandaloneApp)(host, mainPath);
|
|
43
|
+
const modulePath = isStandalone
|
|
44
|
+
? ''
|
|
45
|
+
: (0, node_path_1.dirname)((0, ng_ast_utils_1.getAppModulePath)(host, mainPath));
|
|
46
|
+
const actions = [];
|
|
47
|
+
if (options.loader === schema_1.Loaders.Http) {
|
|
48
|
+
const loaderPath = resolveLoaderPath({
|
|
49
|
+
host,
|
|
50
|
+
mainPath,
|
|
51
|
+
isStandalone,
|
|
52
|
+
modulePath,
|
|
53
|
+
});
|
|
54
|
+
if (isStandalone) {
|
|
55
|
+
actions.push((0, rules_1.addRootProvider)(options.project, ({ code, external }) => code `${external('provideHttpClient', '@angular/common/http')}()`));
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
actions.push((0, rules_1.addRootImport)(options.project, ({ code, external }) => code `${external('HttpClientModule', '@angular/common/http')}`));
|
|
59
|
+
}
|
|
60
|
+
actions.push((0, schematics_1.mergeWith)((0, http_loader_gen_1.createLoaderFile)({
|
|
61
|
+
ssr: options.ssr,
|
|
62
|
+
loaderPath,
|
|
63
|
+
})));
|
|
64
|
+
}
|
|
65
|
+
const hasTranslationFiles = (0, translations_1.checkIfTranslationFilesExist)(assetsPath, langs, '.json', true);
|
|
66
|
+
if (!hasTranslationFiles) {
|
|
67
|
+
actions.push((0, schematics_1.mergeWith)((0, translation_files_gen_1.createTranslateFiles)(langs, translation_files_gen_1.jsonTranslationFileCreator, assetsPath)));
|
|
68
|
+
}
|
|
69
|
+
if (isStandalone) {
|
|
70
|
+
actions.push((0, rules_1.addRootProvider)(options.project, ({ code, external }) => {
|
|
71
|
+
external('isDevMode', '@angular/core');
|
|
72
|
+
external('TranslocoHttpLoader', './transloco-loader');
|
|
73
|
+
return code `${external('provideTransloco', '@jsverse/transloco')}({
|
|
74
|
+
config: {
|
|
75
|
+
availableLangs: [${(0, array_1.stringifyList)(langs)}],
|
|
76
|
+
defaultLang: '${langs[0]}',
|
|
77
|
+
// Remove this option if your application doesn't support changing language in runtime.
|
|
78
|
+
reRenderOnLangChange: true,
|
|
79
|
+
prodMode: !isDevMode(),
|
|
80
|
+
},
|
|
81
|
+
loader: TranslocoHttpLoader
|
|
82
|
+
})`;
|
|
83
|
+
}));
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
actions.push((0, rules_1.addRootImport)(options.project, ({ code, external }) => code `${external('TranslocoRootModule', './transloco-root.module')}`), (0, schematics_1.mergeWith)((0, root_module_gen_1.createTranslocoModule)({
|
|
87
|
+
sourceRoot,
|
|
88
|
+
isLib,
|
|
89
|
+
ssr: options.ssr,
|
|
90
|
+
langs,
|
|
91
|
+
modulePath,
|
|
92
|
+
host,
|
|
93
|
+
})));
|
|
94
|
+
}
|
|
95
|
+
if (options.ssr) {
|
|
96
|
+
updateEnvironmentBaseUrl(host, sourceRoot, 'http://localhost:4200');
|
|
97
|
+
}
|
|
98
|
+
(0, transloco_1.createConfig)(host, langs, assetsPath);
|
|
99
|
+
return (0, schematics_1.chain)(actions)(host, context);
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
exports.default = default_1;
|
|
103
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
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V,KAAK;gBACL,GAAG,EAAE,OAAO,CAAC,GAAG;gBAChB,KAAK;gBACL,UAAU;gBACV,IAAI;aACL,CAAC,CACH,CACF,CAAC;SACH;QAED,IAAI,OAAO,CAAC,GAAG,EAAE;YACf,wBAAwB,CAAC,IAAI,EAAE,UAAU,EAAE,uBAAuB,CAAC,CAAC;SACrE;QAED,IAAA,wBAAY,EAAC,IAAI,EAAE,KAAK,EAAE,UAAU,CAAC,CAAC;QAEtC,OAAO,IAAA,kBAAK,EAAC,OAAO,CAAC,CAAC,IAAI,EAAE,OAAO,CAAQ,CAAC;IAC9C,CAAC,CAAC;AACJ,CAAC;AAjHD,4BAiHC"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
export declare enum Loaders {
|
|
2
|
+
Http = "Http",
|
|
3
|
+
Webpack = "Webpack"
|
|
4
|
+
}
|
|
5
|
+
export declare enum TranslationFileTypes {
|
|
6
|
+
Typescript = "Typescript",
|
|
7
|
+
JSON = "JSON"
|
|
8
|
+
}
|
|
9
|
+
export interface SchemaOptions {
|
|
10
|
+
/**
|
|
11
|
+
* The languages of the project.
|
|
12
|
+
*/
|
|
13
|
+
langs: string;
|
|
14
|
+
/**
|
|
15
|
+
* The translations loader
|
|
16
|
+
*/
|
|
17
|
+
loader: Loaders;
|
|
18
|
+
/**
|
|
19
|
+
* The translation files type.
|
|
20
|
+
*/
|
|
21
|
+
translateType: TranslationFileTypes;
|
|
22
|
+
/**
|
|
23
|
+
* The translation files folder.
|
|
24
|
+
*/
|
|
25
|
+
path: string;
|
|
26
|
+
/**
|
|
27
|
+
* The root module name.
|
|
28
|
+
*/
|
|
29
|
+
module: string;
|
|
30
|
+
/**
|
|
31
|
+
* The root project name.
|
|
32
|
+
*/
|
|
33
|
+
project: string;
|
|
34
|
+
/**
|
|
35
|
+
* If the user is working with server side rendering.
|
|
36
|
+
*/
|
|
37
|
+
ssr: boolean;
|
|
38
|
+
/**
|
|
39
|
+
* If the user is working with server side rendering.
|
|
40
|
+
*/
|
|
41
|
+
translocoKeysManager: boolean;
|
|
42
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TranslationFileTypes = exports.Loaders = void 0;
|
|
4
|
+
var Loaders;
|
|
5
|
+
(function (Loaders) {
|
|
6
|
+
Loaders["Http"] = "Http";
|
|
7
|
+
Loaders["Webpack"] = "Webpack";
|
|
8
|
+
})(Loaders || (exports.Loaders = Loaders = {}));
|
|
9
|
+
var TranslationFileTypes;
|
|
10
|
+
(function (TranslationFileTypes) {
|
|
11
|
+
TranslationFileTypes["Typescript"] = "Typescript";
|
|
12
|
+
TranslationFileTypes["JSON"] = "JSON";
|
|
13
|
+
})(TranslationFileTypes || (exports.TranslationFileTypes = TranslationFileTypes = {}));
|
|
14
|
+
//# sourceMappingURL=schema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../../../../../../libs/transloco-schematics/src/ng-add/schema.ts"],"names":[],"mappings":";;;AAAA,IAAY,OAGX;AAHD,WAAY,OAAO;IACjB,wBAAa,CAAA;IACb,8BAAmB,CAAA;AACrB,CAAC,EAHW,OAAO,uBAAP,OAAO,QAGlB;AAED,IAAY,oBAGX;AAHD,WAAY,oBAAoB;IAC9B,iDAAyB,CAAA;IACzB,qCAAa,CAAA;AACf,CAAC,EAHW,oBAAoB,oCAApB,oBAAoB,QAG/B"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "http://json-schema.org/schema",
|
|
3
|
+
"$id": "transloco-ng-add",
|
|
4
|
+
"title": "Adds Transloco to a project",
|
|
5
|
+
"type": "object",
|
|
6
|
+
"properties": {
|
|
7
|
+
"langs": {
|
|
8
|
+
"description": "The languages of the project.",
|
|
9
|
+
"x-prompt": "\uD83C\uDF0D Which languages do you need?",
|
|
10
|
+
"type": "string",
|
|
11
|
+
"default": "en, es",
|
|
12
|
+
"alias": "la"
|
|
13
|
+
},
|
|
14
|
+
"ssr": {
|
|
15
|
+
"description": "If the user is working with server side rendering.",
|
|
16
|
+
"x-prompt": "\uD83D\uDE80 Are you working with server side rendering?",
|
|
17
|
+
"type": "boolean",
|
|
18
|
+
"default": false
|
|
19
|
+
},
|
|
20
|
+
"loader": {
|
|
21
|
+
"description": "The loader strategy for the translate files.",
|
|
22
|
+
"type": "string",
|
|
23
|
+
"default": "Http",
|
|
24
|
+
"enum": ["Http", "Webpack"],
|
|
25
|
+
"alias": "lo"
|
|
26
|
+
},
|
|
27
|
+
"translateType": {
|
|
28
|
+
"description": "The translation files type.",
|
|
29
|
+
"type": "string",
|
|
30
|
+
"default": "JSON",
|
|
31
|
+
"enum": ["JSON", "Typescript"],
|
|
32
|
+
"alias": "t"
|
|
33
|
+
},
|
|
34
|
+
"path": {
|
|
35
|
+
"type": "string",
|
|
36
|
+
"default": "assets/i18n/",
|
|
37
|
+
"alias": "p"
|
|
38
|
+
},
|
|
39
|
+
"project": {
|
|
40
|
+
"description": "The project name.",
|
|
41
|
+
"type": "string",
|
|
42
|
+
"$default": {
|
|
43
|
+
"$source": "projectName"
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
"module": {
|
|
47
|
+
"description": "The root module name.",
|
|
48
|
+
"type": "string",
|
|
49
|
+
"default": "app"
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
"required": []
|
|
53
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const process_1 = require("process");
|
|
4
|
+
const ng_migrate_1 = require("./ng-migrate");
|
|
5
|
+
function default_1(options) {
|
|
6
|
+
return () => {
|
|
7
|
+
const langs = options.langs.split(',').map((l) => l.trim());
|
|
8
|
+
(0, ng_migrate_1.run)({ input: options.path, output: options.translationFilesPath, langs });
|
|
9
|
+
// prevent "nothing to be done".
|
|
10
|
+
(0, process_1.exit)();
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
exports.default = default_1;
|
|
14
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../libs/transloco-schematics/src/ng-migrate/index.ts"],"names":[],"mappings":";;AAAA,qCAA+B;AAI/B,6CAAmC;AAGnC,mBAAyB,OAAsB;IAC7C,OAAO,GAAG,EAAE;QACV,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC;QAC5D,IAAA,gBAAG,EAAC,EAAE,KAAK,EAAE,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,oBAAoB,EAAE,KAAK,EAAE,CAAC,CAAC;QAC1E,gCAAgC;QAChC,IAAA,cAAI,GAAE,CAAC;IACT,CAAC,CAAC;AACJ,CAAC;AAPD,4BAOC"}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.run = void 0;
|
|
4
|
+
const kebabCase = require("lodash.kebabcase");
|
|
5
|
+
const glob_1 = require("glob");
|
|
6
|
+
const fs_extra_1 = require("fs-extra");
|
|
7
|
+
const regex = /<([\w-]*)\s*(?=[^>]*i18n)[^>]*i18n(?:(?:=("|')(?<attrValue>[^>]*?)\2)|(?:-(?<propName>[\w-]*)[^>]*\4=("|')(?<propValue>[^>]*?)\5))?[^>]*(?:>(?<innerText>[^]*?)<\/\1)?/g;
|
|
8
|
+
function run({ input, output, langs }) {
|
|
9
|
+
const files = (0, glob_1.sync)(`${process.cwd()}/${input}/**/*.html`);
|
|
10
|
+
let translation = {};
|
|
11
|
+
for (const filePath of files) {
|
|
12
|
+
const tpl = (0, fs_extra_1.readFileSync)(filePath, { encoding: 'utf-8' });
|
|
13
|
+
translation = { ...translation, ...getTranslation(tpl) };
|
|
14
|
+
const newTpl = getNewTemplate(tpl);
|
|
15
|
+
(0, fs_extra_1.outputFileSync)(filePath, newTpl);
|
|
16
|
+
}
|
|
17
|
+
for (const lang of langs) {
|
|
18
|
+
const sorted = Object.keys(translation)
|
|
19
|
+
.sort()
|
|
20
|
+
.reduce((acc, key) => {
|
|
21
|
+
acc[key] = translation[key];
|
|
22
|
+
return acc;
|
|
23
|
+
}, {});
|
|
24
|
+
(0, fs_extra_1.outputJsonSync)(`${process.cwd()}/${output}/${lang}.json`, sorted, {
|
|
25
|
+
spaces: 2,
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
console.log('\n 🌵 Done! 🌵');
|
|
29
|
+
console.log('Welcome to a better translation experience 🌐');
|
|
30
|
+
console.log('\nFor more information about this script please visit 👉 https://jsverse.github.io/transloco/docs/migration/angular\n');
|
|
31
|
+
}
|
|
32
|
+
exports.run = run;
|
|
33
|
+
function resolveKey(attrValue, value) {
|
|
34
|
+
let key = value;
|
|
35
|
+
if (!attrValue) {
|
|
36
|
+
return kebabCase(value);
|
|
37
|
+
}
|
|
38
|
+
if (attrValue) {
|
|
39
|
+
const splitCustomId = attrValue.split('@@');
|
|
40
|
+
const hasCustomId = splitCustomId.length === 2;
|
|
41
|
+
key = hasCustomId ? splitCustomId[1] : key;
|
|
42
|
+
}
|
|
43
|
+
key = kebabCase(key);
|
|
44
|
+
return key;
|
|
45
|
+
}
|
|
46
|
+
function getTranslation(template) {
|
|
47
|
+
let result = regex.exec(template);
|
|
48
|
+
const translation = {};
|
|
49
|
+
while (result) {
|
|
50
|
+
const { attrValue, innerText, propValue } = result.groups;
|
|
51
|
+
let context;
|
|
52
|
+
let comment;
|
|
53
|
+
let keyValue = propValue ? propValue : innerText;
|
|
54
|
+
let key = keyValue;
|
|
55
|
+
if (attrValue) {
|
|
56
|
+
const splitCustomId = attrValue.split('@@');
|
|
57
|
+
const hasCustomId = splitCustomId.length === 2;
|
|
58
|
+
key = hasCustomId ? splitCustomId[1] : key;
|
|
59
|
+
const splitContextDescription = attrValue.split('|');
|
|
60
|
+
// we have context
|
|
61
|
+
if (splitContextDescription.length === 2) {
|
|
62
|
+
context = splitContextDescription[0];
|
|
63
|
+
comment = splitContextDescription[1].split('@@')[0];
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
if (splitContextDescription[0].startsWith('@@') === false) {
|
|
67
|
+
comment = attrValue.split('@@')[0];
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
key = kebabCase(key);
|
|
72
|
+
keyValue = keyValue.trim().replace(/(\r\n|\n|\r)/gm, '');
|
|
73
|
+
if (context) {
|
|
74
|
+
translation[context] = translation[context] || {};
|
|
75
|
+
translation[context][key] = keyValue;
|
|
76
|
+
if (comment) {
|
|
77
|
+
translation[context][`${key}.comment`] = comment;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
translation[key] = keyValue;
|
|
82
|
+
if (comment) {
|
|
83
|
+
translation[`${key}.comment`] = comment;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
result = regex.exec(template);
|
|
87
|
+
}
|
|
88
|
+
return translation;
|
|
89
|
+
}
|
|
90
|
+
function getNewTemplate(template) {
|
|
91
|
+
return template.replace(regex, function (match, tag, mark, attrValue, propName, propMark, propValue, innerText) {
|
|
92
|
+
let replace = ' i18n';
|
|
93
|
+
const key = resolveKey(attrValue, propValue || innerText);
|
|
94
|
+
let value = innerText;
|
|
95
|
+
const newValue = `{{ '${key}' | transloco }}`;
|
|
96
|
+
if (attrValue) {
|
|
97
|
+
replace = ` i18n=${mark}${attrValue}${mark}`;
|
|
98
|
+
}
|
|
99
|
+
if (propName) {
|
|
100
|
+
replace = ` i18n-${propName}`;
|
|
101
|
+
value = propValue;
|
|
102
|
+
}
|
|
103
|
+
return match.replace(replace, '').replace(value, newValue);
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
//# sourceMappingURL=ng-migrate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ng-migrate.js","sourceRoot":"","sources":["../../../../../../libs/transloco-schematics/src/ng-migrate/ng-migrate.ts"],"names":[],"mappings":";;;AAAA,8CAA8C;AAC9C,+BAAwC;AACxC,uCAAwE;AAExE,MAAM,KAAK,GACT,yKAAyK,CAAC;AAE5K,SAAgB,GAAG,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE;IAC1C,MAAM,KAAK,GAAG,IAAA,WAAQ,EAAC,GAAG,OAAO,CAAC,GAAG,EAAE,IAAI,KAAK,YAAY,CAAC,CAAC;IAC9D,IAAI,WAAW,GAAG,EAAE,CAAC;IACrB,KAAK,MAAM,QAAQ,IAAI,KAAK,EAAE;QAC5B,MAAM,GAAG,GAAG,IAAA,uBAAY,EAAC,QAAQ,EAAE,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAC,CAAC;QAC1D,WAAW,GAAG,EAAE,GAAG,WAAW,EAAE,GAAG,cAAc,CAAC,GAAG,CAAC,EAAE,CAAC;QAEzD,MAAM,MAAM,GAAG,cAAc,CAAC,GAAG,CAAC,CAAC;QACnC,IAAA,yBAAc,EAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;KAClC;IAED,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE;QACxB,MAAM,MAAM,GAAG,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC;aACpC,IAAI,EAAE;aACN,MAAM,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE;YACnB,GAAG,CAAC,GAAG,CAAC,GAAG,WAAW,CAAC,GAAG,CAAC,CAAC;YAC5B,OAAO,GAAG,CAAC;QACb,CAAC,EAAE,EAAE,CAAC,CAAC;QACT,IAAA,yBAAc,EAAC,GAAG,OAAO,CAAC,GAAG,EAAE,IAAI,MAAM,IAAI,IA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;QAED,MAAM,GAAG,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;KAC/B;IAED,OAAO,WAAW,CAAC;AACrB,CAAC;AAED,SAAS,cAAc,CAAC,QAAQ;IAC9B,OAAO,QAAQ,CAAC,OAAO,CACrB,KAAK,EACL,UACE,KAAK,EACL,GAAG,EACH,IAAI,EACJ,SAAS,EACT,QAAQ,EACR,QAAQ,EACR,SAAS,EACT,SAAS;QAET,IAAI,OAAO,GAAG,OAAO,CAAC;QACtB,MAAM,GAAG,GAAG,UAAU,CAAC,SAAS,EAAE,SAAS,IAAI,SAAS,CAAC,CAAC;QAC1D,IAAI,KAAK,GAAG,SAAS,CAAC;QACtB,MAAM,QAAQ,GAAG,OAAO,GAAG,kBAAkB,CAAC;QAE9C,IAAI,SAAS,EAAE;YACb,OAAO,GAAG,SAAS,IAAI,GAAG,SAAS,GAAG,IAAI,EAAE,CAAC;SAC9C;QAED,IAAI,QAAQ,EAAE;YACZ,OAAO,GAAG,SAAS,QAAQ,EAAE,CAAC;YAC9B,KAAK,GAAG,SAAS,CAAC;SACnB;QAED,OAAO,KAAK,CAAC,OAAO,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;IAC7D,CAAC,CACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export interface SchemaOptions {
|
|
2
|
+
/**
|
|
3
|
+
* The path to the source root directory.
|
|
4
|
+
*/
|
|
5
|
+
path: string;
|
|
6
|
+
/**
|
|
7
|
+
* The location of the translation files.
|
|
8
|
+
*/
|
|
9
|
+
translationFilesPath: string;
|
|
10
|
+
/**
|
|
11
|
+
* The languages of the project.
|
|
12
|
+
*/
|
|
13
|
+
langs: string;
|
|
14
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../../../../../../libs/transloco-schematics/src/ng-migrate/schema.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "http://json-schema.org/schema",
|
|
3
|
+
"$id": "transloco-ng-migrate",
|
|
4
|
+
"title": "Run a migration script from Angular i18n",
|
|
5
|
+
"type": "object",
|
|
6
|
+
"properties": {
|
|
7
|
+
"langs": {
|
|
8
|
+
"description": "The languages of the project.",
|
|
9
|
+
"x-prompt": "Which languages do you use?",
|
|
10
|
+
"type": "string",
|
|
11
|
+
"default": "en, es"
|
|
12
|
+
},
|
|
13
|
+
"translationFilesPath": {
|
|
14
|
+
"description": "The location of the translation files.",
|
|
15
|
+
"x-prompt": "Which folder will contain the translation files?",
|
|
16
|
+
"type": "string",
|
|
17
|
+
"default": "src/assets/i18n"
|
|
18
|
+
},
|
|
19
|
+
"path": {
|
|
20
|
+
"description": "The path to the source root directory.",
|
|
21
|
+
"x-prompt": "Which folder will contain the translation files?",
|
|
22
|
+
"type": "string",
|
|
23
|
+
"default": "./src/app"
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
"required": []
|
|
27
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CONFIG_FILE = exports.LIB_NAME = exports.NPM_SCOPE = exports.PROJECT_NAME = void 0;
|
|
4
|
+
exports.PROJECT_NAME = 'transloco';
|
|
5
|
+
exports.NPM_SCOPE = '@jsverse';
|
|
6
|
+
exports.LIB_NAME = `${exports.NPM_SCOPE}/transloco`;
|
|
7
|
+
exports.CONFIG_FILE = 'transloco.config.js';
|
|
8
|
+
//# sourceMappingURL=schematics.consts.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schematics.consts.js","sourceRoot":"","sources":["../../../../../libs/transloco-schematics/src/schematics.consts.ts"],"names":[],"mappings":";;;AAAa,QAAA,YAAY,GAAG,WAAW,CAAC;AAC3B,QAAA,SAAS,GAAG,UAAU,CAAC;AACvB,QAAA,QAAQ,GAAG,GAAG,iBAAS,YAAY,CAAC;AACpC,QAAA,WAAW,GAAG,qBAAqB,CAAC"}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const node_path_1 = require("node:path");
|
|
4
|
+
const strings_1 = require("@angular-devkit/core/src/utils/strings");
|
|
5
|
+
const schematics_1 = require("@angular-devkit/schematics");
|
|
6
|
+
const typescript_1 = require("typescript");
|
|
7
|
+
const ast_utils_1 = require("@schematics/angular/utility/ast-utils");
|
|
8
|
+
const util_1 = require("@schematics/angular/utility/standalone/util");
|
|
9
|
+
const schematics_consts_1 = require("../schematics.consts");
|
|
10
|
+
const array_1 = require("../utils/array");
|
|
11
|
+
const find_module_1 = require("../utils/find-module");
|
|
12
|
+
const projects_1 = require("../utils/projects");
|
|
13
|
+
const translations_1 = require("../utils/translations");
|
|
14
|
+
const config_1 = require("../utils/config");
|
|
15
|
+
function getProviderValue(options) {
|
|
16
|
+
const name = (0, strings_1.dasherize)(options.name);
|
|
17
|
+
if (!options.inlineLoader)
|
|
18
|
+
return `'${name}'`;
|
|
19
|
+
return `{ scope: '${name}', loader }`;
|
|
20
|
+
}
|
|
21
|
+
function addScopeToModule(tree, modulePath, options) {
|
|
22
|
+
const module = tree.read(modulePath);
|
|
23
|
+
const moduleSource = (0, typescript_1.createSourceFile)(modulePath, module.toString('utf-8'), typescript_1.ScriptTarget.Latest, true);
|
|
24
|
+
const provider = `provideTranslocoScope(${getProviderValue(options)})`;
|
|
25
|
+
const changes = [];
|
|
26
|
+
changes.push((0, ast_utils_1.addProviderToModule)(moduleSource, modulePath, provider, schematics_consts_1.LIB_NAME)[0]);
|
|
27
|
+
changes.push((0, ast_utils_1.addImportToModule)(moduleSource, modulePath, 'TranslocoModule', schematics_consts_1.LIB_NAME)[0]);
|
|
28
|
+
changes.push((0, ast_utils_1.insertImport)(moduleSource, modulePath, 'provideTranslocoScope, TranslocoModule', schematics_consts_1.LIB_NAME));
|
|
29
|
+
if (options.inlineLoader) {
|
|
30
|
+
changes.push((0, ast_utils_1.insertImport)(moduleSource, modulePath, 'loader', './transloco.loader'));
|
|
31
|
+
}
|
|
32
|
+
(0, util_1.applyChangesToFile)(tree, modulePath, changes);
|
|
33
|
+
}
|
|
34
|
+
function getTranslationFilesFromAssets(host, translationsPath) {
|
|
35
|
+
const langFiles = host.root.dir(translationsPath).subfiles;
|
|
36
|
+
return Array.from(new Set(langFiles.map((file) => file.split('.')[0])));
|
|
37
|
+
}
|
|
38
|
+
function getTranslationFiles(options, host, translationsPath) {
|
|
39
|
+
return (options.langs ||
|
|
40
|
+
(0, config_1.getConfig)().langs ||
|
|
41
|
+
getTranslationFilesFromAssets(host, translationsPath));
|
|
42
|
+
}
|
|
43
|
+
function addInlineLoader(tree, modulePath, name, langs) {
|
|
44
|
+
const loader = `export const loader = [${(0, array_1.stringifyList)((0, array_1.coerceArray)(langs))}].reduce((acc: any, lang: string) => {
|
|
45
|
+
acc[lang] = () => import(\`./i18n/\${lang}.json\`);
|
|
46
|
+
return acc;
|
|
47
|
+
}, {});
|
|
48
|
+
|
|
49
|
+
`;
|
|
50
|
+
const path = (0, node_path_1.join)((0, node_path_1.dirname)(modulePath), 'transloco.loader.ts');
|
|
51
|
+
tree.create(path, loader);
|
|
52
|
+
}
|
|
53
|
+
function createTranslationFiles(options, rootPath, modulePath, host) {
|
|
54
|
+
if (options.skipCreation) {
|
|
55
|
+
return (0, schematics_1.empty)();
|
|
56
|
+
}
|
|
57
|
+
const defaultPath = options.inlineLoader
|
|
58
|
+
? (0, node_path_1.join)((0, node_path_1.dirname)(modulePath), 'i18n')
|
|
59
|
+
: (0, node_path_1.join)(rootPath, 'assets', 'i18n', (0, strings_1.dasherize)(options.name));
|
|
60
|
+
const translationsPath = options.translationPath
|
|
61
|
+
? (0, node_path_1.join)(rootPath, options.translationPath)
|
|
62
|
+
: defaultPath;
|
|
63
|
+
return (0, translations_1.createTranslateFilesFromOptions)(host, options, translationsPath);
|
|
64
|
+
}
|
|
65
|
+
function extractModuleOptions({ path, project, routing, flat, commonModule, }) {
|
|
66
|
+
return { path, project, routing, flat, commonModule };
|
|
67
|
+
}
|
|
68
|
+
function default_1(options) {
|
|
69
|
+
return (host, context) => {
|
|
70
|
+
const project = (0, projects_1.getProject)(host, options.project);
|
|
71
|
+
const rootPath = project?.sourceRoot ?? 'src';
|
|
72
|
+
const assetsPath = (0, node_path_1.join)(rootPath, 'assets', 'i18n');
|
|
73
|
+
options.langs = getTranslationFiles(options, host, assetsPath);
|
|
74
|
+
if (options.module) {
|
|
75
|
+
const projectPath = (0, projects_1.getProjectPath)(host, project, options);
|
|
76
|
+
const modulePath = (0, find_module_1.findModuleFromOptions)(host, options, projectPath);
|
|
77
|
+
if (options.inlineLoader) {
|
|
78
|
+
addInlineLoader(host, modulePath, options.name, options.langs);
|
|
79
|
+
}
|
|
80
|
+
if (modulePath) {
|
|
81
|
+
addScopeToModule(host, modulePath, options);
|
|
82
|
+
return (0, schematics_1.mergeWith)(createTranslationFiles(options, rootPath, modulePath, host))(host, context);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
return (0, schematics_1.chain)([
|
|
86
|
+
(0, schematics_1.externalSchematic)('@schematics/angular', 'module', extractModuleOptions(options)),
|
|
87
|
+
(tree) => {
|
|
88
|
+
const modulePath = tree.actions.find((action) => !!action.path.match(/\.module\.ts/) &&
|
|
89
|
+
!action.path.match(/-routing\.module\.ts/)).path;
|
|
90
|
+
addScopeToModule(tree, modulePath, options);
|
|
91
|
+
if (options.inlineLoader) {
|
|
92
|
+
addInlineLoader(tree, modulePath, options.name, options.langs);
|
|
93
|
+
}
|
|
94
|
+
const translationRule = createTranslationFiles(options, rootPath, modulePath, host);
|
|
95
|
+
return (0, schematics_1.mergeWith)(translationRule);
|
|
96
|
+
},
|
|
97
|
+
]);
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
exports.default = default_1;
|
|
101
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../libs/transloco-schematics/src/scope/index.ts"],"names":[],"mappings":";;AAAA,yCAA0C;AAE1C,oEAAmE;AACnE,2DAQoC;AACpC,2CAA4D;AAC5D,qEAI+C;AAC/C,sEAAiF;AAGjF,4DAAgD;AAChD,0CAA4D;AAC5D,sDAA6D;AAC7D,gDAA+D;AAC/D,wDAAwE;AACxE,4CAA4C;AAI5C,SAAS,gBAAgB,CAAC,OAAsB;IAC9C,MAAM,IAAI,GAAG,IAAA,mBAAS,EAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IACrC,IAAI,CAAC,OAAO,CAAC,YAAY;QAAE,OAAO,IAAI,IAAI,GAAG,CAAC;IAC9C,OAAO,aAAa,IAAI,aAAa,CAAC;AACxC,CAAC;AAED,SAAS,gBAAgB,CACvB,IAAU,EACV,UAAkB,EAClB,OAAsB;IAEtB,MAAM,MAAM,GAAG,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;IAErC,MAAM,YAAY,GAAG,IAAA,6BAAgB,EACnC,UAAU,EACV,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,EACxB,yBAAY,CAAC,MAAM,EACnB,IAAI,CACL,CAAC;IACF,MAAM,QAAQ,GAAG,yBAAyB,gBAAgB,CAAC,OAAO,CAAC,GAAG,CAAC;IACvE,MAAM,OAAO,GAAa,EAAE,CAAC;IAC7B,OAAO,CAAC,IAAI,CACV,IAAA,+BAAmB,EAAC,YAAY,EAAE,UAAU,EAAE,QAAQ,EAAE,4BAAQ,CAAC,CAAC,CAAC,CAAC,CACrE,CAAC;IACF,OAAO,CAAC,IAAI,CACV,IAAA,6BAAiB,EAAC,YAAY,EAAE,UAAU,EAAE,iBAAiB,EAAE,4BAAQ,CAAC,CAAC,CAAC,CAAC,CAC5E,CAAC;IACF,OAAO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,CACL,CAAC;gBAEF,OAAO,IAAA,sBAAS,EAAC,eAAe,CAAC,CAAC;YACpC,CAAC;SACF,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC;AA/CD,4BA+CC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { Schema } from '@schematics/angular/module/schema';
|
|
2
|
+
export interface SchemaOptions extends Schema {
|
|
3
|
+
name: string;
|
|
4
|
+
/**
|
|
5
|
+
* The languages of the project.
|
|
6
|
+
*/
|
|
7
|
+
langs: string | string[];
|
|
8
|
+
/**
|
|
9
|
+
* Skip the creation of the translation files.
|
|
10
|
+
*/
|
|
11
|
+
skipCreation: boolean;
|
|
12
|
+
/**
|
|
13
|
+
* The path of the translation files.
|
|
14
|
+
*/
|
|
15
|
+
translationPath: string;
|
|
16
|
+
/**
|
|
17
|
+
* Specification of the declaring module..
|
|
18
|
+
*/
|
|
19
|
+
module: string;
|
|
20
|
+
/**
|
|
21
|
+
* The root project name.
|
|
22
|
+
*/
|
|
23
|
+
project: string;
|
|
24
|
+
/**
|
|
25
|
+
* Should create scope with inline loader.
|
|
26
|
+
*/
|
|
27
|
+
inlineLoader: boolean;
|
|
28
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../../../../../../libs/transloco-schematics/src/scope/schema.ts"],"names":[],"mappings":""}
|