@powerlines/plugin-i18next 0.1.354 → 0.1.356

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.
@@ -1 +1,29 @@
1
- var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},s=(n,r,a)=>(a=n==null?{}:e(i(n)),o(r||!n||!n.__esModule?t(a,`default`,{value:n,enumerable:!0}):a,n));exports.__toESM=s;
1
+ //#region \0rolldown/runtime.js
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __copyProps = (to, from, except, desc) => {
9
+ if (from && typeof from === "object" || typeof from === "function") {
10
+ for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
11
+ key = keys[i];
12
+ if (!__hasOwnProp.call(to, key) && key !== except) {
13
+ __defProp(to, key, {
14
+ get: ((k) => from[k]).bind(null, key),
15
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
16
+ });
17
+ }
18
+ }
19
+ }
20
+ return to;
21
+ };
22
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
23
+ value: mod,
24
+ enumerable: true
25
+ }) : target, mod));
26
+
27
+ //#endregion
28
+
29
+ exports.__toESM = __toESM;
@@ -1 +1,31 @@
1
- require(`../_virtual/_rolldown/runtime.cjs`);let e=require(`@stryke/path/correct-path`);function t(t,n,r){if(!t)return(0,e.correctPath)(`locales/${n}/${r??`translation`}.json`);if(typeof t==`function`)try{return(0,e.correctPath)(String(t(n,r)).replace(/\/{2,}/g,`/`))}catch{return(0,e.correctPath)(`locales/${n}/${r??`translation`}.json`)}let i=String(t);return i=i.replace(/\{\{language\}\}|\{\{lng\}\}/g,n),i=r==null?i.replace(/\/?\{\{namespace\}\}/g,``):i.replace(/\{\{namespace\}\}/g,r),i=i.replace(/\/{2,}/g,`/`),(0,e.correctPath)(i)}exports.getOutputPath=t;
1
+ const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
2
+ let _stryke_path_correct_path = require("@stryke/path/correct-path");
3
+
4
+ //#region src/helpers/config-utils.ts
5
+ /**
6
+ * Resolve an output template (string or function) into an actual path string.
7
+ *
8
+ * @remarks
9
+ * - If `outputTemplate` is a function, call it with (language, namespace)
10
+ * - If it's a string, replace placeholders:
11
+ * - \{\{language\}\} or \{\{lng\}\} -\> language
12
+ * - \{\{namespace\}\} -\> namespace (or removed if namespace is undefined)
13
+ * - Normalizes duplicate slashes and returns a platform-correct path.
14
+ */
15
+ function getOutputPath(outputTemplate, language, namespace) {
16
+ if (!outputTemplate) return (0, _stryke_path_correct_path.correctPath)(`locales/${language}/${namespace ?? "translation"}.json`);
17
+ if (typeof outputTemplate === "function") try {
18
+ return (0, _stryke_path_correct_path.correctPath)(String(outputTemplate(language, namespace)).replace(/\/{2,}/g, "/"));
19
+ } catch {
20
+ return (0, _stryke_path_correct_path.correctPath)(`locales/${language}/${namespace ?? "translation"}.json`);
21
+ }
22
+ let out = String(outputTemplate);
23
+ out = out.replace(/\{\{language\}\}|\{\{lng\}\}/g, language);
24
+ if (namespace !== void 0 && namespace !== null) out = out.replace(/\{\{namespace\}\}/g, namespace);
25
+ else out = out.replace(/\/?\{\{namespace\}\}/g, "");
26
+ out = out.replace(/\/{2,}/g, "/");
27
+ return (0, _stryke_path_correct_path.correctPath)(out);
28
+ }
29
+
30
+ //#endregion
31
+ exports.getOutputPath = getOutputPath;
@@ -1,2 +1,31 @@
1
- import{correctPath as e}from"@stryke/path/correct-path";function t(t,n,r){if(!t)return e(`locales/${n}/${r??`translation`}.json`);if(typeof t==`function`)try{return e(String(t(n,r)).replace(/\/{2,}/g,`/`))}catch{return e(`locales/${n}/${r??`translation`}.json`)}let i=String(t);return i=i.replace(/\{\{language\}\}|\{\{lng\}\}/g,n),i=r==null?i.replace(/\/?\{\{namespace\}\}/g,``):i.replace(/\{\{namespace\}\}/g,r),i=i.replace(/\/{2,}/g,`/`),e(i)}export{t as getOutputPath};
1
+ import { correctPath } from "@stryke/path/correct-path";
2
+
3
+ //#region src/helpers/config-utils.ts
4
+ /**
5
+ * Resolve an output template (string or function) into an actual path string.
6
+ *
7
+ * @remarks
8
+ * - If `outputTemplate` is a function, call it with (language, namespace)
9
+ * - If it's a string, replace placeholders:
10
+ * - \{\{language\}\} or \{\{lng\}\} -\> language
11
+ * - \{\{namespace\}\} -\> namespace (or removed if namespace is undefined)
12
+ * - Normalizes duplicate slashes and returns a platform-correct path.
13
+ */
14
+ function getOutputPath(outputTemplate, language, namespace) {
15
+ if (!outputTemplate) return correctPath(`locales/${language}/${namespace ?? "translation"}.json`);
16
+ if (typeof outputTemplate === "function") try {
17
+ return correctPath(String(outputTemplate(language, namespace)).replace(/\/{2,}/g, "/"));
18
+ } catch {
19
+ return correctPath(`locales/${language}/${namespace ?? "translation"}.json`);
20
+ }
21
+ let out = String(outputTemplate);
22
+ out = out.replace(/\{\{language\}\}|\{\{lng\}\}/g, language);
23
+ if (namespace !== void 0 && namespace !== null) out = out.replace(/\{\{namespace\}\}/g, namespace);
24
+ else out = out.replace(/\/?\{\{namespace\}\}/g, "");
25
+ out = out.replace(/\/{2,}/g, "/");
26
+ return correctPath(out);
27
+ }
28
+
29
+ //#endregion
30
+ export { getOutputPath };
2
31
  //# sourceMappingURL=config-utils.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"config-utils.mjs","names":[],"sources":["../../src/helpers/config-utils.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Powerlines\n\n This code was released as part of the Powerlines project. Powerlines\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/powerlines.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/powerlines\n Documentation: https://docs.stormsoftware.com/projects/powerlines\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { correctPath } from \"@stryke/path/correct-path\";\n\n/**\n * Resolve an output template (string or function) into an actual path string.\n *\n * @remarks\n * - If `outputTemplate` is a function, call it with (language, namespace)\n * - If it's a string, replace placeholders:\n * - \\{\\{language\\}\\} or \\{\\{lng\\}\\} -\\> language\n * - \\{\\{namespace\\}\\} -\\> namespace (or removed if namespace is undefined)\n * - Normalizes duplicate slashes and returns a platform-correct path.\n */\nexport function getOutputPath(\n outputTemplate:\n | string\n | ((language: string, namespace?: string) => string)\n | undefined,\n language: string,\n namespace?: string\n): string {\n if (!outputTemplate) {\n // Fallback to a sensible default\n return correctPath(\n `locales/${language}/${namespace ?? \"translation\"}.json`\n );\n }\n\n if (typeof outputTemplate === \"function\") {\n try {\n const result = String(outputTemplate(language, namespace));\n\n return correctPath(result.replace(/\\/{2,}/g, \"/\"));\n } catch {\n // If user function throws, fallback to default path\n return correctPath(\n `locales/${language}/${namespace ?? \"translation\"}.json`\n );\n }\n }\n\n // It's a string template\n let out = String(outputTemplate);\n out = out.replace(/\\{\\{language\\}\\}|\\{\\{lng\\}\\}/g, language);\n\n if (namespace !== undefined && namespace !== null) {\n out = out.replace(/\\{\\{namespace\\}\\}/g, namespace);\n } else {\n // remove any occurrences of /{{namespace}} or {{namespace}} (keeping surrounding slashes tidy)\n out = out.replace(/\\/?\\{\\{namespace\\}\\}/g, \"\");\n }\n\n // collapse duplicate slashes and normalize to platform-specific separators\n out = out.replace(/\\/{2,}/g, \"/\");\n return correctPath(out);\n}\n"],"mappings":"wDA8BA,SAAgB,EACd,EAIA,EACA,EACQ,CACR,GAAI,CAAC,EAEH,OAAO,EACL,WAAW,EAAS,GAAG,GAAa,cAAc,OACnD,CAGH,GAAI,OAAO,GAAmB,WAC5B,GAAI,CAGF,OAAO,EAFQ,OAAO,EAAe,EAAU,EAAU,CAEhC,CAAC,QAAQ,UAAW,IAAI,CAAC,MAC5C,CAEN,OAAO,EACL,WAAW,EAAS,GAAG,GAAa,cAAc,OACnD,CAKL,IAAI,EAAM,OAAO,EAAe,CAYhC,MAXA,GAAM,EAAI,QAAQ,gCAAiC,EAAS,CAE5D,AACE,EADE,GAAyC,KAIrC,EAAI,QAAQ,wBAAyB,GAAG,CAHxC,EAAI,QAAQ,qBAAsB,EAAU,CAOpD,EAAM,EAAI,QAAQ,UAAW,IAAI,CAC1B,EAAY,EAAI"}
1
+ {"version":3,"file":"config-utils.mjs","names":[],"sources":["../../src/helpers/config-utils.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Powerlines\n\n This code was released as part of the Powerlines project. Powerlines\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/powerlines.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/powerlines\n Documentation: https://docs.stormsoftware.com/projects/powerlines\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { correctPath } from \"@stryke/path/correct-path\";\n\n/**\n * Resolve an output template (string or function) into an actual path string.\n *\n * @remarks\n * - If `outputTemplate` is a function, call it with (language, namespace)\n * - If it's a string, replace placeholders:\n * - \\{\\{language\\}\\} or \\{\\{lng\\}\\} -\\> language\n * - \\{\\{namespace\\}\\} -\\> namespace (or removed if namespace is undefined)\n * - Normalizes duplicate slashes and returns a platform-correct path.\n */\nexport function getOutputPath(\n outputTemplate:\n | string\n | ((language: string, namespace?: string) => string)\n | undefined,\n language: string,\n namespace?: string\n): string {\n if (!outputTemplate) {\n // Fallback to a sensible default\n return correctPath(\n `locales/${language}/${namespace ?? \"translation\"}.json`\n );\n }\n\n if (typeof outputTemplate === \"function\") {\n try {\n const result = String(outputTemplate(language, namespace));\n\n return correctPath(result.replace(/\\/{2,}/g, \"/\"));\n } catch {\n // If user function throws, fallback to default path\n return correctPath(\n `locales/${language}/${namespace ?? \"translation\"}.json`\n );\n }\n }\n\n // It's a string template\n let out = String(outputTemplate);\n out = out.replace(/\\{\\{language\\}\\}|\\{\\{lng\\}\\}/g, language);\n\n if (namespace !== undefined && namespace !== null) {\n out = out.replace(/\\{\\{namespace\\}\\}/g, namespace);\n } else {\n // remove any occurrences of /{{namespace}} or {{namespace}} (keeping surrounding slashes tidy)\n out = out.replace(/\\/?\\{\\{namespace\\}\\}/g, \"\");\n }\n\n // collapse duplicate slashes and normalize to platform-specific separators\n out = out.replace(/\\/{2,}/g, \"/\");\n return correctPath(out);\n}\n"],"mappings":";;;;;;;;;;;;;AA8BA,SAAgB,cACd,gBAIA,UACA,WACQ;AACR,KAAI,CAAC,eAEH,QAAO,YACL,WAAW,SAAS,GAAG,aAAa,cAAc,OACnD;AAGH,KAAI,OAAO,mBAAmB,WAC5B,KAAI;AAGF,SAAO,YAFQ,OAAO,eAAe,UAAU,UAAU,CAEhC,CAAC,QAAQ,WAAW,IAAI,CAAC;SAC5C;AAEN,SAAO,YACL,WAAW,SAAS,GAAG,aAAa,cAAc,OACnD;;CAKL,IAAI,MAAM,OAAO,eAAe;AAChC,OAAM,IAAI,QAAQ,iCAAiC,SAAS;AAE5D,KAAI,cAAc,UAAa,cAAc,KAC3C,OAAM,IAAI,QAAQ,sBAAsB,UAAU;KAGlD,OAAM,IAAI,QAAQ,yBAAyB,GAAG;AAIhD,OAAM,IAAI,QAAQ,WAAW,IAAI;AACjC,QAAO,YAAY,IAAI"}
package/dist/index.cjs CHANGED
@@ -1,6 +1,107 @@
1
- Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});const e=require(`./_virtual/_rolldown/runtime.cjs`),t=require(`./helpers/config-utils.cjs`);let n=require(`@stryke/fs/list-files`),r=require(`@stryke/path/append`),i=require(`@stryke/path/file-path-fns`),a=require(`@stryke/path/join`),o=require(`@stryke/type-checks/is-set`),s=require(`@stryke/type-checks/is-set-object`),c=require(`@stryke/type-checks/is-string`),l=require(`defu`);l=e.__toESM(l,1);let u=require(`i18next-cli`),d=require(`i18next-resources-for-ts`);const f=(e={})=>({name:`i18next`,async config(){let t=(0,l.default)(e,{extract:{output:(e,t=`translation`)=>(0,a.joinPaths)(this.config.root,`locales/${e}/${t}.json`)}},{extract:{input:[`src/**/*.ts`,`src/**/*.tsx`,`src/**/*.js`,`src/**/*.jsx`],indentation:2,defaultNS:`translation`,mergeNamespaces:!0,nsSeparator:`:`,keySeparator:`.`,primaryLanguage:e.locales&&e.locales.length>0?e.locales[0]:`en`},types:{enableSelector:!1},locales:[]});return(!t.locales||t.locales.length===0)&&(t.locales=[t.extract.primaryLanguage||`en`]),(0,o.isSet)(t.types.indentation)||(t.types.indentation=t.extract.indentation),{i18next:t}},async configResolved(){},async prepare(){await(0,u.runExtractor)(this.config.i18next,{isWatchMode:!1,isDryRun:!1,syncAll:!0,syncPrimaryWithDefaults:!0,logger:{info:e=>{this.info(e)},warn:(e,t)=>{this.warn(e)},error:e=>{this.error(e)}}})},async types(e){let a=[];for(let e of await(0,n.listFiles)(t.getOutputPath(this.config.i18next.extract.output,this.config.i18next.extract.primaryLanguage,`*`))){let t=(0,i.findFileName)(e,{withExtension:!1}),n=await this.resolver.import(e);if(this.config.i18next.extract.mergeNamespaces&&(0,s.isSetObject)(n)&&Object.keys(n).filter(e=>(0,s.isSetObject)(n[e])).length>0){for(let e of Object.keys(n).filter(e=>(0,s.isSetObject)(n[e])))a.push({name:e,resources:n[e]});Object.keys(n).filter(e=>!(0,s.isSetObject)(n[e])).length>0&&this.warn(`The file ${e} contains top-level keys that are not objects (${Object.keys(n).filter(e=>!(0,s.isSetObject)(n[e])).join(`, `)}). When 'mergeNamespaces' is enabled, top-level keys are treated as namespaces. These keys will be ignored.`);continue}a.push({name:t,resources:n})}let o;return this.config.i18next.types.resourcesFile?await this.fs.write((0,r.appendPath)(this.config.i18next.types.resourcesFile,this.config.i18next.types.output||this.config.root),(0,d.mergeResourcesAsInterface)(a,{optimize:!!this.config.i18next.types.enableSelector,indentation:this.config.i18next.types.indentation})):o=`${e}
1
+ Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
2
+ const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
3
+ const require_config_utils = require('./helpers/config-utils.cjs');
4
+ let _stryke_fs_list_files = require("@stryke/fs/list-files");
5
+ let _stryke_path_append = require("@stryke/path/append");
6
+ let _stryke_path_file_path_fns = require("@stryke/path/file-path-fns");
7
+ let _stryke_path_join = require("@stryke/path/join");
8
+ let _stryke_type_checks_is_set = require("@stryke/type-checks/is-set");
9
+ let _stryke_type_checks_is_set_object = require("@stryke/type-checks/is-set-object");
10
+ let _stryke_type_checks_is_string = require("@stryke/type-checks/is-string");
11
+ let defu = require("defu");
12
+ defu = require_runtime.__toESM(defu, 1);
13
+ let i18next_cli = require("i18next-cli");
14
+ let i18next_resources_for_ts = require("i18next-resources-for-ts");
2
15
 
3
- ${(0,d.mergeResourcesAsInterface)(a,{optimize:!!this.config.i18next.types.enableSelector,indentation:this.config.i18next.types.indentation})}
16
+ //#region src/index.ts
17
+ /**
18
+ * i18next Plugin
19
+ *
20
+ * @remarks
21
+ * A Powerlines plugin to use the i18next internationalization framework during the prepare task.
22
+ *
23
+ * @see https://i18next.com
24
+ *
25
+ * @param options - The plugin options.
26
+ * @returns A Powerlines plugin instance.
27
+ */
28
+ const plugin = (options = {}) => {
29
+ return {
30
+ name: "i18next",
31
+ async config() {
32
+ const i18next = (0, defu.default)(options, { extract: { output: (language, namespace = "translation") => (0, _stryke_path_join.joinPaths)(this.config.root, `locales/${language}/${namespace}.json`) } }, {
33
+ extract: {
34
+ input: [
35
+ "src/**/*.ts",
36
+ "src/**/*.tsx",
37
+ "src/**/*.js",
38
+ "src/**/*.jsx"
39
+ ],
40
+ indentation: 2,
41
+ defaultNS: "translation",
42
+ mergeNamespaces: true,
43
+ nsSeparator: ":",
44
+ keySeparator: ".",
45
+ primaryLanguage: options.locales && options.locales.length > 0 ? options.locales[0] : "en"
46
+ },
47
+ types: { enableSelector: false },
48
+ locales: []
49
+ });
50
+ if (!i18next.locales || i18next.locales.length === 0) i18next.locales = [i18next.extract.primaryLanguage || "en"];
51
+ if (!(0, _stryke_type_checks_is_set.isSet)(i18next.types.indentation)) i18next.types.indentation = i18next.extract.indentation;
52
+ return { i18next };
53
+ },
54
+ async configResolved() {},
55
+ async prepare() {
56
+ await (0, i18next_cli.runExtractor)(this.config.i18next, {
57
+ isWatchMode: false,
58
+ isDryRun: false,
59
+ syncAll: true,
60
+ syncPrimaryWithDefaults: true,
61
+ logger: {
62
+ info: (message) => {
63
+ this.info(message);
64
+ },
65
+ warn: (message, _more) => {
66
+ this.warn(message);
67
+ },
68
+ error: (message) => {
69
+ this.error(message);
70
+ }
71
+ }
72
+ });
73
+ },
74
+ async types(code) {
75
+ const resources = [];
76
+ for (const file of await (0, _stryke_fs_list_files.listFiles)(require_config_utils.getOutputPath(this.config.i18next.extract.output, this.config.i18next.extract.primaryLanguage, "*"))) {
77
+ const namespace = (0, _stryke_path_file_path_fns.findFileName)(file, { withExtension: false });
78
+ const parsedContent = await this.resolver.import(file);
79
+ if (this.config.i18next.extract.mergeNamespaces && (0, _stryke_type_checks_is_set_object.isSetObject)(parsedContent)) {
80
+ if (Object.keys(parsedContent).filter((k) => (0, _stryke_type_checks_is_set_object.isSetObject)(parsedContent[k])).length > 0) {
81
+ for (const nsName of Object.keys(parsedContent).filter((k) => (0, _stryke_type_checks_is_set_object.isSetObject)(parsedContent[k]))) resources.push({
82
+ name: nsName,
83
+ resources: parsedContent[nsName]
84
+ });
85
+ if (Object.keys(parsedContent).filter((k) => !(0, _stryke_type_checks_is_set_object.isSetObject)(parsedContent[k])).length > 0) this.warn(`The file ${file} contains top-level keys that are not objects (${Object.keys(parsedContent).filter((k) => !(0, _stryke_type_checks_is_set_object.isSetObject)(parsedContent[k])).join(", ")}). When 'mergeNamespaces' is enabled, top-level keys are treated as namespaces. These keys will be ignored.`);
86
+ continue;
87
+ }
88
+ }
89
+ resources.push({
90
+ name: namespace,
91
+ resources: parsedContent
92
+ });
93
+ }
94
+ let result;
95
+ if (this.config.i18next.types.resourcesFile) await this.fs.write((0, _stryke_path_append.appendPath)(this.config.i18next.types.resourcesFile, this.config.i18next.types.output || this.config.root), (0, i18next_resources_for_ts.mergeResourcesAsInterface)(resources, {
96
+ optimize: !!this.config.i18next.types.enableSelector,
97
+ indentation: this.config.i18next.types.indentation
98
+ }));
99
+ else result = `${code}
100
+
101
+ ${(0, i18next_resources_for_ts.mergeResourcesAsInterface)(resources, {
102
+ optimize: !!this.config.i18next.types.enableSelector,
103
+ indentation: this.config.i18next.types.indentation
104
+ })}
4
105
 
5
106
  /**
6
107
  * i18next Custom Type Options
@@ -9,9 +110,17 @@ ${(0,d.mergeResourcesAsInterface)(a,{optimize:!!this.config.i18next.types.enable
9
110
  */
10
111
  declare module 'i18next' {
11
112
  interface CustomTypeOptions {
12
- enableSelector: ${(0,c.isString)(this.config.i18next.types.enableSelector)?`"${this.config.i18next.types.enableSelector}"`:this.config.i18next.types.enableSelector};
13
- defaultNS: ${this.config.i18next.extract.defaultNS===!1?`false`:`'${this.config.i18next.extract.defaultNS||`translation`}'`};
113
+ enableSelector: ${(0, _stryke_type_checks_is_string.isString)(this.config.i18next.types.enableSelector) ? `"${this.config.i18next.types.enableSelector}"` : this.config.i18next.types.enableSelector};
114
+ defaultNS: ${this.config.i18next.extract.defaultNS === false ? "false" : `'${this.config.i18next.extract.defaultNS || "translation"}'`};
14
115
  resources: Resources;
15
116
  }
16
117
  }
17
- `,o}});exports.default=f,exports.plugin=f;
118
+ `;
119
+ return result;
120
+ }
121
+ };
122
+ };
123
+
124
+ //#endregion
125
+ exports.default = plugin;
126
+ exports.plugin = plugin;
package/dist/index.mjs CHANGED
@@ -1,6 +1,104 @@
1
- import{getOutputPath as e}from"./helpers/config-utils.mjs";import{listFiles as t}from"@stryke/fs/list-files";import{appendPath as n}from"@stryke/path/append";import{findFileName as r}from"@stryke/path/file-path-fns";import{joinPaths as i}from"@stryke/path/join";import{isSet as a}from"@stryke/type-checks/is-set";import{isSetObject as o}from"@stryke/type-checks/is-set-object";import{isString as s}from"@stryke/type-checks/is-string";import c from"defu";import{runExtractor as l}from"i18next-cli";import{mergeResourcesAsInterface as u}from"i18next-resources-for-ts";const d=(d={})=>({name:`i18next`,async config(){let e=c(d,{extract:{output:(e,t=`translation`)=>i(this.config.root,`locales/${e}/${t}.json`)}},{extract:{input:[`src/**/*.ts`,`src/**/*.tsx`,`src/**/*.js`,`src/**/*.jsx`],indentation:2,defaultNS:`translation`,mergeNamespaces:!0,nsSeparator:`:`,keySeparator:`.`,primaryLanguage:d.locales&&d.locales.length>0?d.locales[0]:`en`},types:{enableSelector:!1},locales:[]});return(!e.locales||e.locales.length===0)&&(e.locales=[e.extract.primaryLanguage||`en`]),a(e.types.indentation)||(e.types.indentation=e.extract.indentation),{i18next:e}},async configResolved(){},async prepare(){await l(this.config.i18next,{isWatchMode:!1,isDryRun:!1,syncAll:!0,syncPrimaryWithDefaults:!0,logger:{info:e=>{this.info(e)},warn:(e,t)=>{this.warn(e)},error:e=>{this.error(e)}}})},async types(i){let a=[];for(let n of await t(e(this.config.i18next.extract.output,this.config.i18next.extract.primaryLanguage,`*`))){let e=r(n,{withExtension:!1}),t=await this.resolver.import(n);if(this.config.i18next.extract.mergeNamespaces&&o(t)&&Object.keys(t).filter(e=>o(t[e])).length>0){for(let e of Object.keys(t).filter(e=>o(t[e])))a.push({name:e,resources:t[e]});Object.keys(t).filter(e=>!o(t[e])).length>0&&this.warn(`The file ${n} contains top-level keys that are not objects (${Object.keys(t).filter(e=>!o(t[e])).join(`, `)}). When 'mergeNamespaces' is enabled, top-level keys are treated as namespaces. These keys will be ignored.`);continue}a.push({name:e,resources:t})}let c;return this.config.i18next.types.resourcesFile?await this.fs.write(n(this.config.i18next.types.resourcesFile,this.config.i18next.types.output||this.config.root),u(a,{optimize:!!this.config.i18next.types.enableSelector,indentation:this.config.i18next.types.indentation})):c=`${i}
1
+ import { getOutputPath } from "./helpers/config-utils.mjs";
2
+ import { listFiles } from "@stryke/fs/list-files";
3
+ import { appendPath } from "@stryke/path/append";
4
+ import { findFileName } from "@stryke/path/file-path-fns";
5
+ import { joinPaths } from "@stryke/path/join";
6
+ import { isSet } from "@stryke/type-checks/is-set";
7
+ import { isSetObject } from "@stryke/type-checks/is-set-object";
8
+ import { isString } from "@stryke/type-checks/is-string";
9
+ import defu from "defu";
10
+ import { runExtractor } from "i18next-cli";
11
+ import { mergeResourcesAsInterface } from "i18next-resources-for-ts";
2
12
 
3
- ${u(a,{optimize:!!this.config.i18next.types.enableSelector,indentation:this.config.i18next.types.indentation})}
13
+ //#region src/index.ts
14
+ /**
15
+ * i18next Plugin
16
+ *
17
+ * @remarks
18
+ * A Powerlines plugin to use the i18next internationalization framework during the prepare task.
19
+ *
20
+ * @see https://i18next.com
21
+ *
22
+ * @param options - The plugin options.
23
+ * @returns A Powerlines plugin instance.
24
+ */
25
+ const plugin = (options = {}) => {
26
+ return {
27
+ name: "i18next",
28
+ async config() {
29
+ const i18next = defu(options, { extract: { output: (language, namespace = "translation") => joinPaths(this.config.root, `locales/${language}/${namespace}.json`) } }, {
30
+ extract: {
31
+ input: [
32
+ "src/**/*.ts",
33
+ "src/**/*.tsx",
34
+ "src/**/*.js",
35
+ "src/**/*.jsx"
36
+ ],
37
+ indentation: 2,
38
+ defaultNS: "translation",
39
+ mergeNamespaces: true,
40
+ nsSeparator: ":",
41
+ keySeparator: ".",
42
+ primaryLanguage: options.locales && options.locales.length > 0 ? options.locales[0] : "en"
43
+ },
44
+ types: { enableSelector: false },
45
+ locales: []
46
+ });
47
+ if (!i18next.locales || i18next.locales.length === 0) i18next.locales = [i18next.extract.primaryLanguage || "en"];
48
+ if (!isSet(i18next.types.indentation)) i18next.types.indentation = i18next.extract.indentation;
49
+ return { i18next };
50
+ },
51
+ async configResolved() {},
52
+ async prepare() {
53
+ await runExtractor(this.config.i18next, {
54
+ isWatchMode: false,
55
+ isDryRun: false,
56
+ syncAll: true,
57
+ syncPrimaryWithDefaults: true,
58
+ logger: {
59
+ info: (message) => {
60
+ this.info(message);
61
+ },
62
+ warn: (message, _more) => {
63
+ this.warn(message);
64
+ },
65
+ error: (message) => {
66
+ this.error(message);
67
+ }
68
+ }
69
+ });
70
+ },
71
+ async types(code) {
72
+ const resources = [];
73
+ for (const file of await listFiles(getOutputPath(this.config.i18next.extract.output, this.config.i18next.extract.primaryLanguage, "*"))) {
74
+ const namespace = findFileName(file, { withExtension: false });
75
+ const parsedContent = await this.resolver.import(file);
76
+ if (this.config.i18next.extract.mergeNamespaces && isSetObject(parsedContent)) {
77
+ if (Object.keys(parsedContent).filter((k) => isSetObject(parsedContent[k])).length > 0) {
78
+ for (const nsName of Object.keys(parsedContent).filter((k) => isSetObject(parsedContent[k]))) resources.push({
79
+ name: nsName,
80
+ resources: parsedContent[nsName]
81
+ });
82
+ if (Object.keys(parsedContent).filter((k) => !isSetObject(parsedContent[k])).length > 0) this.warn(`The file ${file} contains top-level keys that are not objects (${Object.keys(parsedContent).filter((k) => !isSetObject(parsedContent[k])).join(", ")}). When 'mergeNamespaces' is enabled, top-level keys are treated as namespaces. These keys will be ignored.`);
83
+ continue;
84
+ }
85
+ }
86
+ resources.push({
87
+ name: namespace,
88
+ resources: parsedContent
89
+ });
90
+ }
91
+ let result;
92
+ if (this.config.i18next.types.resourcesFile) await this.fs.write(appendPath(this.config.i18next.types.resourcesFile, this.config.i18next.types.output || this.config.root), mergeResourcesAsInterface(resources, {
93
+ optimize: !!this.config.i18next.types.enableSelector,
94
+ indentation: this.config.i18next.types.indentation
95
+ }));
96
+ else result = `${code}
97
+
98
+ ${mergeResourcesAsInterface(resources, {
99
+ optimize: !!this.config.i18next.types.enableSelector,
100
+ indentation: this.config.i18next.types.indentation
101
+ })}
4
102
 
5
103
  /**
6
104
  * i18next Custom Type Options
@@ -9,10 +107,17 @@ ${u(a,{optimize:!!this.config.i18next.types.enableSelector,indentation:this.conf
9
107
  */
10
108
  declare module 'i18next' {
11
109
  interface CustomTypeOptions {
12
- enableSelector: ${s(this.config.i18next.types.enableSelector)?`"${this.config.i18next.types.enableSelector}"`:this.config.i18next.types.enableSelector};
13
- defaultNS: ${this.config.i18next.extract.defaultNS===!1?`false`:`'${this.config.i18next.extract.defaultNS||`translation`}'`};
110
+ enableSelector: ${isString(this.config.i18next.types.enableSelector) ? `"${this.config.i18next.types.enableSelector}"` : this.config.i18next.types.enableSelector};
111
+ defaultNS: ${this.config.i18next.extract.defaultNS === false ? "false" : `'${this.config.i18next.extract.defaultNS || "translation"}'`};
14
112
  resources: Resources;
15
113
  }
16
114
  }
17
- `,c}});export{d as default,d as plugin};
115
+ `;
116
+ return result;
117
+ }
118
+ };
119
+ };
120
+
121
+ //#endregion
122
+ export { plugin as default, plugin };
18
123
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","names":[],"sources":["../src/index.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Powerlines\n\n This code was released as part of the Powerlines project. Powerlines\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/powerlines.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/powerlines\n Documentation: https://docs.stormsoftware.com/projects/powerlines\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { listFiles } from \"@stryke/fs/list-files\";\nimport { appendPath } from \"@stryke/path/append\";\nimport { findFileName } from \"@stryke/path/file-path-fns\";\nimport { joinPaths } from \"@stryke/path/join\";\nimport { isSet } from \"@stryke/type-checks/is-set\";\nimport { isSetObject } from \"@stryke/type-checks/is-set-object\";\nimport { isString } from \"@stryke/type-checks/is-string\";\nimport defu from \"defu\";\nimport { I18nextToolkitConfig, runExtractor } from \"i18next-cli\";\nimport { mergeResourcesAsInterface } from \"i18next-resources-for-ts\";\nimport type { Plugin } from \"powerlines\";\nimport { getOutputPath } from \"./helpers/config-utils\";\nimport { Resource, ResourceContent } from \"./types/i18n\";\nimport type {\n I18NextPluginContext,\n I18NextPluginOptions,\n I18NextPluginResolvedConfig\n} from \"./types/plugin\";\n\nexport * from \"./types\";\n\ndeclare module \"powerlines\" {\n interface Config {\n i18next?: I18NextPluginOptions;\n }\n}\n\n/**\n * i18next Plugin\n *\n * @remarks\n * A Powerlines plugin to use the i18next internationalization framework during the prepare task.\n *\n * @see https://i18next.com\n *\n * @param options - The plugin options.\n * @returns A Powerlines plugin instance.\n */\nexport const plugin = <\n TContext extends I18NextPluginContext = I18NextPluginContext\n>(\n options: I18NextPluginOptions = {}\n): Plugin<TContext> => {\n return {\n name: \"i18next\",\n async config() {\n const i18next = defu<\n I18NextPluginResolvedConfig[\"i18next\"],\n I18NextPluginOptions[]\n >(\n options,\n {\n extract: {\n output: (language: string, namespace = \"translation\") =>\n joinPaths(\n this.config.root,\n `locales/${language}/${namespace}.json`\n )\n }\n },\n {\n extract: {\n input: [\n \"src/**/*.ts\",\n \"src/**/*.tsx\",\n \"src/**/*.js\",\n \"src/**/*.jsx\"\n ],\n indentation: 2,\n defaultNS: \"translation\",\n mergeNamespaces: true,\n nsSeparator: \":\",\n keySeparator: \".\",\n primaryLanguage:\n options.locales && options.locales.length > 0\n ? options.locales[0]\n : \"en\"\n },\n types: {\n enableSelector: false\n },\n locales: [] as string[]\n }\n );\n\n if (!i18next.locales || i18next.locales.length === 0) {\n i18next.locales = [i18next.extract.primaryLanguage || \"en\"];\n }\n\n if (!isSet(i18next.types.indentation)) {\n i18next.types.indentation = i18next.extract.indentation;\n }\n\n return {\n i18next\n };\n },\n async configResolved() {},\n async prepare() {\n await runExtractor(this.config.i18next as I18nextToolkitConfig, {\n isWatchMode: false,\n isDryRun: false,\n syncAll: true,\n syncPrimaryWithDefaults: true,\n logger: {\n info: (message: string) => {\n this.info(message);\n },\n warn: (message: string, _more?: any) => {\n this.warn(message);\n },\n error: (message: string | any) => {\n this.error(message);\n }\n }\n });\n },\n async types(code: string) {\n const resources: Resource[] = [];\n for (const file of await listFiles(\n getOutputPath(\n this.config.i18next.extract.output,\n this.config.i18next.extract.primaryLanguage,\n \"*\"\n )\n )) {\n const namespace = findFileName(file, { withExtension: false });\n const parsedContent = await this.resolver.import<ResourceContent>(file);\n\n // If mergeNamespaces is used, a single file can contain multiple namespaces\n // (e.g. { \"translation\": { ... }, \"common\": { ... } } in a per-language file).\n // In that case, expose each top-level key as a namespace entry so the type\n // generator will produce top-level namespace interfaces (not a language wrapper).\n if (\n this.config.i18next.extract.mergeNamespaces &&\n isSetObject(parsedContent)\n ) {\n // If we have at least one object and we are in mergeNamespaces mode, assume it's a merged file\n if (\n Object.keys(parsedContent).filter(k =>\n isSetObject(parsedContent[k])\n ).length > 0\n ) {\n for (const nsName of Object.keys(parsedContent).filter(k =>\n isSetObject(parsedContent[k])\n )) {\n resources.push({\n name: nsName,\n resources: parsedContent[nsName] as ResourceContent\n });\n }\n\n if (\n Object.keys(parsedContent).filter(\n k => !isSetObject(parsedContent[k])\n ).length > 0\n ) {\n this.warn(\n `The file ${file} contains top-level keys that are not objects (${Object.keys(\n parsedContent\n )\n .filter(k => !isSetObject(parsedContent[k]))\n .join(\n \", \"\n )}). When 'mergeNamespaces' is enabled, top-level keys are treated as namespaces. These keys will be ignored.`\n );\n }\n\n continue;\n }\n }\n\n resources.push({ name: namespace, resources: parsedContent });\n }\n\n let result!: string;\n if (this.config.i18next.types.resourcesFile) {\n await this.fs.write(\n appendPath(\n this.config.i18next.types.resourcesFile,\n this.config.i18next.types.output || this.config.root\n ),\n mergeResourcesAsInterface(resources, {\n optimize: !!this.config.i18next.types.enableSelector,\n indentation: this.config.i18next.types.indentation\n })\n );\n } else {\n result = `${code}\n\n${mergeResourcesAsInterface(resources, {\n optimize: !!this.config.i18next.types.enableSelector,\n indentation: this.config.i18next.types.indentation\n})}\n\n/**\n * i18next Custom Type Options\n *\n * @see https://www.i18next.com/overview/typescript#custom-type-options\n */\ndeclare module 'i18next' {\n interface CustomTypeOptions {\n enableSelector: ${isString(this.config.i18next.types.enableSelector) ? `\"${this.config.i18next.types.enableSelector}\"` : this.config.i18next.types.enableSelector};\n defaultNS: ${\n this.config.i18next.extract.defaultNS === false\n ? \"false\"\n : `'${this.config.i18next.extract.defaultNS || \"translation\"}'`\n };\n resources: Resources;\n }\n}\n`;\n }\n\n return result;\n }\n };\n};\n\nexport default plugin;\n"],"mappings":"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"}
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../src/index.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Powerlines\n\n This code was released as part of the Powerlines project. Powerlines\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/powerlines.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/powerlines\n Documentation: https://docs.stormsoftware.com/projects/powerlines\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { listFiles } from \"@stryke/fs/list-files\";\nimport { appendPath } from \"@stryke/path/append\";\nimport { findFileName } from \"@stryke/path/file-path-fns\";\nimport { joinPaths } from \"@stryke/path/join\";\nimport { isSet } from \"@stryke/type-checks/is-set\";\nimport { isSetObject } from \"@stryke/type-checks/is-set-object\";\nimport { isString } from \"@stryke/type-checks/is-string\";\nimport defu from \"defu\";\nimport { I18nextToolkitConfig, runExtractor } from \"i18next-cli\";\nimport { mergeResourcesAsInterface } from \"i18next-resources-for-ts\";\nimport type { Plugin } from \"powerlines\";\nimport { getOutputPath } from \"./helpers/config-utils\";\nimport { Resource, ResourceContent } from \"./types/i18n\";\nimport type {\n I18NextPluginContext,\n I18NextPluginOptions,\n I18NextPluginResolvedConfig\n} from \"./types/plugin\";\n\nexport * from \"./types\";\n\ndeclare module \"powerlines\" {\n interface Config {\n i18next?: I18NextPluginOptions;\n }\n}\n\n/**\n * i18next Plugin\n *\n * @remarks\n * A Powerlines plugin to use the i18next internationalization framework during the prepare task.\n *\n * @see https://i18next.com\n *\n * @param options - The plugin options.\n * @returns A Powerlines plugin instance.\n */\nexport const plugin = <\n TContext extends I18NextPluginContext = I18NextPluginContext\n>(\n options: I18NextPluginOptions = {}\n): Plugin<TContext> => {\n return {\n name: \"i18next\",\n async config() {\n const i18next = defu<\n I18NextPluginResolvedConfig[\"i18next\"],\n I18NextPluginOptions[]\n >(\n options,\n {\n extract: {\n output: (language: string, namespace = \"translation\") =>\n joinPaths(\n this.config.root,\n `locales/${language}/${namespace}.json`\n )\n }\n },\n {\n extract: {\n input: [\n \"src/**/*.ts\",\n \"src/**/*.tsx\",\n \"src/**/*.js\",\n \"src/**/*.jsx\"\n ],\n indentation: 2,\n defaultNS: \"translation\",\n mergeNamespaces: true,\n nsSeparator: \":\",\n keySeparator: \".\",\n primaryLanguage:\n options.locales && options.locales.length > 0\n ? options.locales[0]\n : \"en\"\n },\n types: {\n enableSelector: false\n },\n locales: [] as string[]\n }\n );\n\n if (!i18next.locales || i18next.locales.length === 0) {\n i18next.locales = [i18next.extract.primaryLanguage || \"en\"];\n }\n\n if (!isSet(i18next.types.indentation)) {\n i18next.types.indentation = i18next.extract.indentation;\n }\n\n return {\n i18next\n };\n },\n async configResolved() {},\n async prepare() {\n await runExtractor(this.config.i18next as I18nextToolkitConfig, {\n isWatchMode: false,\n isDryRun: false,\n syncAll: true,\n syncPrimaryWithDefaults: true,\n logger: {\n info: (message: string) => {\n this.info(message);\n },\n warn: (message: string, _more?: any) => {\n this.warn(message);\n },\n error: (message: string | any) => {\n this.error(message);\n }\n }\n });\n },\n async types(code: string) {\n const resources: Resource[] = [];\n for (const file of await listFiles(\n getOutputPath(\n this.config.i18next.extract.output,\n this.config.i18next.extract.primaryLanguage,\n \"*\"\n )\n )) {\n const namespace = findFileName(file, { withExtension: false });\n const parsedContent = await this.resolver.import<ResourceContent>(file);\n\n // If mergeNamespaces is used, a single file can contain multiple namespaces\n // (e.g. { \"translation\": { ... }, \"common\": { ... } } in a per-language file).\n // In that case, expose each top-level key as a namespace entry so the type\n // generator will produce top-level namespace interfaces (not a language wrapper).\n if (\n this.config.i18next.extract.mergeNamespaces &&\n isSetObject(parsedContent)\n ) {\n // If we have at least one object and we are in mergeNamespaces mode, assume it's a merged file\n if (\n Object.keys(parsedContent).filter(k =>\n isSetObject(parsedContent[k])\n ).length > 0\n ) {\n for (const nsName of Object.keys(parsedContent).filter(k =>\n isSetObject(parsedContent[k])\n )) {\n resources.push({\n name: nsName,\n resources: parsedContent[nsName] as ResourceContent\n });\n }\n\n if (\n Object.keys(parsedContent).filter(\n k => !isSetObject(parsedContent[k])\n ).length > 0\n ) {\n this.warn(\n `The file ${file} contains top-level keys that are not objects (${Object.keys(\n parsedContent\n )\n .filter(k => !isSetObject(parsedContent[k]))\n .join(\n \", \"\n )}). When 'mergeNamespaces' is enabled, top-level keys are treated as namespaces. These keys will be ignored.`\n );\n }\n\n continue;\n }\n }\n\n resources.push({ name: namespace, resources: parsedContent });\n }\n\n let result!: string;\n if (this.config.i18next.types.resourcesFile) {\n await this.fs.write(\n appendPath(\n this.config.i18next.types.resourcesFile,\n this.config.i18next.types.output || this.config.root\n ),\n mergeResourcesAsInterface(resources, {\n optimize: !!this.config.i18next.types.enableSelector,\n indentation: this.config.i18next.types.indentation\n })\n );\n } else {\n result = `${code}\n\n${mergeResourcesAsInterface(resources, {\n optimize: !!this.config.i18next.types.enableSelector,\n indentation: this.config.i18next.types.indentation\n})}\n\n/**\n * i18next Custom Type Options\n *\n * @see https://www.i18next.com/overview/typescript#custom-type-options\n */\ndeclare module 'i18next' {\n interface CustomTypeOptions {\n enableSelector: ${isString(this.config.i18next.types.enableSelector) ? `\"${this.config.i18next.types.enableSelector}\"` : this.config.i18next.types.enableSelector};\n defaultNS: ${\n this.config.i18next.extract.defaultNS === false\n ? \"false\"\n : `'${this.config.i18next.extract.defaultNS || \"translation\"}'`\n };\n resources: Resources;\n }\n}\n`;\n }\n\n return result;\n }\n };\n};\n\nexport default plugin;\n"],"mappings":"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"}
@@ -1 +1 @@
1
- export{};
1
+ export { };
@@ -1 +1 @@
1
- export{};
1
+ export { };
@@ -1 +1 @@
1
- export{};
1
+ export { };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@powerlines/plugin-i18next",
3
- "version": "0.1.354",
3
+ "version": "0.1.356",
4
4
  "private": false,
5
5
  "description": "A Powerlines plugin to use i18next for internationalization.",
6
6
  "keywords": ["i18next", "powerlines", "storm-software", "powerlines-plugin"],
@@ -111,12 +111,12 @@
111
111
  "defu": "^6.1.7",
112
112
  "i18next-cli": "^1.56.9",
113
113
  "i18next-resources-for-ts": "^2.1.0",
114
- "powerlines": "^0.46.4"
114
+ "powerlines": "^0.46.6"
115
115
  },
116
116
  "devDependencies": {
117
- "@powerlines/plugin-plugin": "^0.12.408",
117
+ "@powerlines/plugin-plugin": "^0.12.410",
118
118
  "@types/node": "^25.6.0"
119
119
  },
120
120
  "publishConfig": { "access": "public" },
121
- "gitHead": "2e5eff0d36cb4a1a54242017a16c5af5d9ce2cc3"
121
+ "gitHead": "610c4c943933458c5f433b9002d8c187625b2d3f"
122
122
  }