@powerlines/plugin-i18next 0.1.14 → 0.1.16

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 rolldown:runtime
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
- const e=require(`../_virtual/rolldown_runtime.cjs`);let t=require(`@stryke/path/correct-path`);function n(e,n,r){if(!e)return(0,t.correctPath)(`locales/${n}/${r??`translation`}.json`);if(typeof e==`function`)try{return(0,t.correctPath)(String(e(n,r)).replace(/\/{2,}/g,`/`))}catch{return(0,t.correctPath)(`locales/${n}/${r??`translation`}.json`)}let i=String(e);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,t.correctPath)(i)}exports.getOutputPath=n;
1
+ const require_rolldown_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 +1,30 @@
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 };
package/dist/index.cjs CHANGED
@@ -1,6 +1,109 @@
1
- Object.defineProperty(exports,`__esModule`,{value:!0});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);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.projectRoot,`locales/${e}/${t}.json`),primaryLanguage:this.workspaceConfig.locale}},{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},{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.projectRoot),(0,d.mergeResourcesAsInterface)(a,{optimize:!!this.config.i18next.types.enableSelector,indentation:this.config.i18next.types.indentation})):o=`${e}
1
+ Object.defineProperty(exports, '__esModule', { value: true });
2
+ const require_rolldown_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_rolldown_runtime.__toESM(defu);
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: {
33
+ output: (language, namespace = "translation") => (0, __stryke_path_join.joinPaths)(this.config.projectRoot, `locales/${language}/${namespace}.json`),
34
+ primaryLanguage: this.workspaceConfig.locale
35
+ } }, {
36
+ extract: {
37
+ input: [
38
+ "src/**/*.ts",
39
+ "src/**/*.tsx",
40
+ "src/**/*.js",
41
+ "src/**/*.jsx"
42
+ ],
43
+ indentation: 2,
44
+ defaultNS: "translation",
45
+ mergeNamespaces: true,
46
+ nsSeparator: ":",
47
+ keySeparator: ".",
48
+ primaryLanguage: options.locales && options.locales.length > 0 ? options.locales[0] : "en"
49
+ },
50
+ types: { enableSelector: false },
51
+ locales: []
52
+ });
53
+ if (!i18next.locales || i18next.locales.length === 0) i18next.locales = [i18next.extract.primaryLanguage || "en"];
54
+ if (!(0, __stryke_type_checks_is_set.isSet)(i18next.types.indentation)) i18next.types.indentation = i18next.extract.indentation;
55
+ return { i18next };
56
+ },
57
+ async configResolved() {},
58
+ async prepare() {
59
+ await (0, i18next_cli.runExtractor)(this.config.i18next, {
60
+ isWatchMode: false,
61
+ isDryRun: false,
62
+ syncAll: true,
63
+ syncPrimaryWithDefaults: true
64
+ }, {
65
+ info: (message) => {
66
+ this.info(message);
67
+ },
68
+ warn: (message, _more) => {
69
+ this.warn(message);
70
+ },
71
+ error: (message) => {
72
+ this.error(message);
73
+ }
74
+ });
75
+ },
76
+ async types(code) {
77
+ const resources = [];
78
+ 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, "*"))) {
79
+ const namespace = (0, __stryke_path_file_path_fns.findFileName)(file, { withExtension: false });
80
+ const parsedContent = await this.resolver.import(file);
81
+ if (this.config.i18next.extract.mergeNamespaces && (0, __stryke_type_checks_is_set_object.isSetObject)(parsedContent)) {
82
+ if (Object.keys(parsedContent).filter((k) => (0, __stryke_type_checks_is_set_object.isSetObject)(parsedContent[k])).length > 0) {
83
+ for (const nsName of Object.keys(parsedContent).filter((k) => (0, __stryke_type_checks_is_set_object.isSetObject)(parsedContent[k]))) resources.push({
84
+ name: nsName,
85
+ resources: parsedContent[nsName]
86
+ });
87
+ 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.`);
88
+ continue;
89
+ }
90
+ }
91
+ resources.push({
92
+ name: namespace,
93
+ resources: parsedContent
94
+ });
95
+ }
96
+ let result;
97
+ 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.projectRoot), (0, i18next_resources_for_ts.mergeResourcesAsInterface)(resources, {
98
+ optimize: !!this.config.i18next.types.enableSelector,
99
+ indentation: this.config.i18next.types.indentation
100
+ }));
101
+ else result = `${code}
102
+
103
+ ${(0, i18next_resources_for_ts.mergeResourcesAsInterface)(resources, {
104
+ optimize: !!this.config.i18next.types.enableSelector,
105
+ indentation: this.config.i18next.types.indentation
106
+ })}
4
107
 
5
108
  /**
6
109
  * i18next Custom Type Options
@@ -9,9 +112,18 @@ ${(0,d.mergeResourcesAsInterface)(a,{optimize:!!this.config.i18next.types.enable
9
112
  */
10
113
  declare module 'i18next' {
11
114
  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`}'`};
115
+ enableSelector: ${(0, __stryke_type_checks_is_string.isString)(this.config.i18next.types.enableSelector) ? `"${this.config.i18next.types.enableSelector}"` : this.config.i18next.types.enableSelector};
116
+ defaultNS: ${this.config.i18next.extract.defaultNS === false ? "false" : `'${this.config.i18next.extract.defaultNS || "translation"}'`};
14
117
  resources: Resources;
15
118
  }
16
119
  }
17
- `,o}});var p=f;exports.default=p,exports.plugin=f;
120
+ `;
121
+ return result;
122
+ }
123
+ };
124
+ };
125
+ var src_default = plugin;
126
+
127
+ //#endregion
128
+ exports.default = src_default;
129
+ exports.plugin = plugin;
package/dist/index.mjs CHANGED
@@ -1,6 +1,106 @@
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.projectRoot,`locales/${e}/${t}.json`),primaryLanguage:this.workspaceConfig.locale}},{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},{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.projectRoot),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: {
30
+ output: (language, namespace = "translation") => joinPaths(this.config.projectRoot, `locales/${language}/${namespace}.json`),
31
+ primaryLanguage: this.workspaceConfig.locale
32
+ } }, {
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 (!isSet(i18next.types.indentation)) i18next.types.indentation = i18next.extract.indentation;
52
+ return { i18next };
53
+ },
54
+ async configResolved() {},
55
+ async prepare() {
56
+ await runExtractor(this.config.i18next, {
57
+ isWatchMode: false,
58
+ isDryRun: false,
59
+ syncAll: true,
60
+ syncPrimaryWithDefaults: true
61
+ }, {
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
+ async types(code) {
74
+ const resources = [];
75
+ for (const file of await listFiles(getOutputPath(this.config.i18next.extract.output, this.config.i18next.extract.primaryLanguage, "*"))) {
76
+ const namespace = findFileName(file, { withExtension: false });
77
+ const parsedContent = await this.resolver.import(file);
78
+ if (this.config.i18next.extract.mergeNamespaces && isSetObject(parsedContent)) {
79
+ if (Object.keys(parsedContent).filter((k) => isSetObject(parsedContent[k])).length > 0) {
80
+ for (const nsName of Object.keys(parsedContent).filter((k) => isSetObject(parsedContent[k]))) resources.push({
81
+ name: nsName,
82
+ resources: parsedContent[nsName]
83
+ });
84
+ 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.`);
85
+ continue;
86
+ }
87
+ }
88
+ resources.push({
89
+ name: namespace,
90
+ resources: parsedContent
91
+ });
92
+ }
93
+ let result;
94
+ if (this.config.i18next.types.resourcesFile) await this.fs.write(appendPath(this.config.i18next.types.resourcesFile, this.config.i18next.types.output || this.config.projectRoot), mergeResourcesAsInterface(resources, {
95
+ optimize: !!this.config.i18next.types.enableSelector,
96
+ indentation: this.config.i18next.types.indentation
97
+ }));
98
+ else result = `${code}
99
+
100
+ ${mergeResourcesAsInterface(resources, {
101
+ optimize: !!this.config.i18next.types.enableSelector,
102
+ indentation: this.config.i18next.types.indentation
103
+ })}
4
104
 
5
105
  /**
6
106
  * i18next Custom Type Options
@@ -9,9 +109,17 @@ ${u(a,{optimize:!!this.config.i18next.types.enableSelector,indentation:this.conf
9
109
  */
10
110
  declare module 'i18next' {
11
111
  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`}'`};
112
+ enableSelector: ${isString(this.config.i18next.types.enableSelector) ? `"${this.config.i18next.types.enableSelector}"` : this.config.i18next.types.enableSelector};
113
+ defaultNS: ${this.config.i18next.extract.defaultNS === false ? "false" : `'${this.config.i18next.extract.defaultNS || "translation"}'`};
14
114
  resources: Resources;
15
115
  }
16
116
  }
17
- `,c}});var f=d;export{f as default,d as plugin};
117
+ `;
118
+ return result;
119
+ }
120
+ };
121
+ };
122
+ var src_default = plugin;
123
+
124
+ //#endregion
125
+ export { src_default as default, plugin };
@@ -78,10 +78,18 @@ interface ParseOptions extends ParserOptions {
78
78
  */
79
79
  allowReturnOutsideFunction?: boolean;
80
80
  }
81
+ interface EmitOptions extends WriteOptions {
82
+ /**
83
+ * If true, will emit the file using {@link UnpluginBuildContext.emitFile | the bundler's emit function}.
84
+ */
85
+ emitWithBundler?: boolean;
86
+ needsCodeReference?: Parameters<UnpluginBuildContext["emitFile"]>[0]["needsCodeReference"];
87
+ originalFileName?: Parameters<UnpluginBuildContext["emitFile"]>[0]["originalFileName"];
88
+ }
81
89
  /**
82
90
  * Options for emitting entry virtual files
83
91
  */
84
- type EmitEntryOptions = WriteOptions & Omit<ResolvedEntryTypeDefinition, "file">;
92
+ type EmitEntryOptions = EmitOptions & Omit<ResolvedEntryTypeDefinition, "file">;
85
93
  /**
86
94
  * The unresolved Powerlines context.
87
95
  *
@@ -292,6 +300,22 @@ interface UnresolvedContext<TResolvedConfig extends ResolvedConfig = ResolvedCon
292
300
  * The Powerlines builtin virtual files
293
301
  */
294
302
  getBuiltins: () => Promise<VirtualFile[]>;
303
+ /**
304
+ * Resolves a file and writes it to the VFS if it does not already exist
305
+ *
306
+ * @param code - The source code of the file
307
+ * @param path - The path to write the file to
308
+ * @param options - Additional options for writing the file
309
+ */
310
+ emit: (code: string, path: string, options?: EmitOptions) => Promise<void>;
311
+ /**
312
+ * Synchronously resolves a file and writes it to the VFS if it does not already exist
313
+ *
314
+ * @param code - The source code of the file
315
+ * @param path - The path to write the file to
316
+ * @param options - Additional options for writing the file
317
+ */
318
+ emitSync: (code: string, path: string, options?: EmitOptions) => void;
295
319
  /**
296
320
  * Resolves a builtin virtual file and writes it to the VFS if it does not already exist
297
321
  *
@@ -300,7 +324,7 @@ interface UnresolvedContext<TResolvedConfig extends ResolvedConfig = ResolvedCon
300
324
  * @param path - An optional path to write the builtin file to
301
325
  * @param options - Additional options for writing the builtin file
302
326
  */
303
- emitBuiltin: (code: string, id: string, path?: string, options?: WriteOptions) => Promise<void>;
327
+ emitBuiltin: (code: string, id: string, path?: string, options?: EmitOptions) => Promise<void>;
304
328
  /**
305
329
  * Synchronously resolves a builtin virtual file and writes it to the VFS if it does not already exist
306
330
  *
@@ -309,7 +333,7 @@ interface UnresolvedContext<TResolvedConfig extends ResolvedConfig = ResolvedCon
309
333
  * @param path - An optional path to write the builtin file to
310
334
  * @param options - Additional options for writing the builtin file
311
335
  */
312
- emitBuiltinSync: (code: string, id: string, path?: string, options?: WriteOptions) => void;
336
+ emitBuiltinSync: (code: string, id: string, path?: string, options?: EmitOptions) => void;
313
337
  /**
314
338
  * Resolves a entry virtual file and writes it to the VFS if it does not already exist
315
339
  *
@@ -78,10 +78,18 @@ interface ParseOptions extends ParserOptions {
78
78
  */
79
79
  allowReturnOutsideFunction?: boolean;
80
80
  }
81
+ interface EmitOptions extends WriteOptions {
82
+ /**
83
+ * If true, will emit the file using {@link UnpluginBuildContext.emitFile | the bundler's emit function}.
84
+ */
85
+ emitWithBundler?: boolean;
86
+ needsCodeReference?: Parameters<UnpluginBuildContext["emitFile"]>[0]["needsCodeReference"];
87
+ originalFileName?: Parameters<UnpluginBuildContext["emitFile"]>[0]["originalFileName"];
88
+ }
81
89
  /**
82
90
  * Options for emitting entry virtual files
83
91
  */
84
- type EmitEntryOptions = WriteOptions & Omit<ResolvedEntryTypeDefinition, "file">;
92
+ type EmitEntryOptions = EmitOptions & Omit<ResolvedEntryTypeDefinition, "file">;
85
93
  /**
86
94
  * The unresolved Powerlines context.
87
95
  *
@@ -292,6 +300,22 @@ interface UnresolvedContext<TResolvedConfig extends ResolvedConfig = ResolvedCon
292
300
  * The Powerlines builtin virtual files
293
301
  */
294
302
  getBuiltins: () => Promise<VirtualFile[]>;
303
+ /**
304
+ * Resolves a file and writes it to the VFS if it does not already exist
305
+ *
306
+ * @param code - The source code of the file
307
+ * @param path - The path to write the file to
308
+ * @param options - Additional options for writing the file
309
+ */
310
+ emit: (code: string, path: string, options?: EmitOptions) => Promise<void>;
311
+ /**
312
+ * Synchronously resolves a file and writes it to the VFS if it does not already exist
313
+ *
314
+ * @param code - The source code of the file
315
+ * @param path - The path to write the file to
316
+ * @param options - Additional options for writing the file
317
+ */
318
+ emitSync: (code: string, path: string, options?: EmitOptions) => void;
295
319
  /**
296
320
  * Resolves a builtin virtual file and writes it to the VFS if it does not already exist
297
321
  *
@@ -300,7 +324,7 @@ interface UnresolvedContext<TResolvedConfig extends ResolvedConfig = ResolvedCon
300
324
  * @param path - An optional path to write the builtin file to
301
325
  * @param options - Additional options for writing the builtin file
302
326
  */
303
- emitBuiltin: (code: string, id: string, path?: string, options?: WriteOptions) => Promise<void>;
327
+ emitBuiltin: (code: string, id: string, path?: string, options?: EmitOptions) => Promise<void>;
304
328
  /**
305
329
  * Synchronously resolves a builtin virtual file and writes it to the VFS if it does not already exist
306
330
  *
@@ -309,7 +333,7 @@ interface UnresolvedContext<TResolvedConfig extends ResolvedConfig = ResolvedCon
309
333
  * @param path - An optional path to write the builtin file to
310
334
  * @param options - Additional options for writing the builtin file
311
335
  */
312
- emitBuiltinSync: (code: string, id: string, path?: string, options?: WriteOptions) => void;
336
+ emitBuiltinSync: (code: string, id: string, path?: string, options?: EmitOptions) => void;
313
337
  /**
314
338
  * Resolves a entry virtual file and writes it to the VFS if it does not already exist
315
339
  *
@@ -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.14",
3
+ "version": "0.1.16",
4
4
  "type": "module",
5
5
  "description": "A Powerlines plugin to use i18next for internationalization.",
6
6
  "repository": {
@@ -117,19 +117,19 @@
117
117
  "files": ["dist/**/*"],
118
118
  "keywords": ["i18next", "powerlines", "storm-software", "powerlines-plugin"],
119
119
  "dependencies": {
120
- "@stryke/fs": "^0.33.26",
121
- "@stryke/path": "^0.24.0",
122
- "@stryke/types": "^0.10.28",
120
+ "@stryke/fs": "^0.33.27",
121
+ "@stryke/path": "^0.24.1",
122
+ "@stryke/types": "^0.10.29",
123
123
  "defu": "^6.1.4",
124
- "powerlines": "^0.36.22"
124
+ "powerlines": "^0.36.24"
125
125
  },
126
126
  "devDependencies": {
127
- "@powerlines/nx": "^0.11.48",
128
- "@powerlines/plugin-plugin": "^0.12.69",
127
+ "@powerlines/nx": "^0.11.50",
128
+ "@powerlines/plugin-plugin": "^0.12.71",
129
129
  "@types/node": "^24.10.4",
130
130
  "i18next-cli": "^1.33.5",
131
131
  "i18next-resources-for-ts": "^2.0.0"
132
132
  },
133
133
  "publishConfig": { "access": "public" },
134
- "gitHead": "f88fe8eb30f96536b83fc9af884972d48e31e63a"
134
+ "gitHead": "4b695d4b3476fd9dd79521f92258d52dab2b8d72"
135
135
  }