i18next-cli 0.9.8 → 0.9.10
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 +11 -1
- package/README.md +69 -0
- package/dist/cjs/cli.js +1 -1
- package/dist/cjs/extractor/core/extractor.js +1 -1
- package/dist/cjs/extractor/core/translation-manager.js +1 -1
- package/dist/cjs/extractor/parsers/ast-visitors.js +1 -1
- package/dist/cjs/extractor/parsers/jsx-parser.js +1 -1
- package/dist/cjs/heuristic-config.js +1 -1
- package/dist/cjs/status.js +1 -1
- package/dist/cjs/syncer.js +1 -1
- package/dist/cjs/utils/file-utils.js +1 -1
- package/dist/esm/cli.js +1 -1
- package/dist/esm/extractor/core/extractor.js +1 -1
- package/dist/esm/extractor/core/translation-manager.js +1 -1
- package/dist/esm/extractor/parsers/ast-visitors.js +1 -1
- package/dist/esm/extractor/parsers/jsx-parser.js +1 -1
- package/dist/esm/heuristic-config.js +1 -1
- package/dist/esm/status.js +1 -1
- package/dist/esm/syncer.js +1 -1
- package/dist/esm/utils/file-utils.js +1 -1
- package/package.json +1 -1
- package/src/cli.ts +1 -1
- package/src/extractor/core/extractor.ts +13 -7
- package/src/extractor/core/translation-manager.ts +38 -21
- package/src/extractor/parsers/ast-visitors.ts +123 -53
- package/src/extractor/parsers/jsx-parser.ts +11 -1
- package/src/heuristic-config.ts +14 -3
- package/src/status.ts +21 -13
- package/src/syncer.ts +77 -67
- package/src/types.ts +22 -1
- package/src/utils/file-utils.ts +54 -1
- package/types/extractor/core/extractor.d.ts.map +1 -1
- package/types/extractor/core/translation-manager.d.ts.map +1 -1
- package/types/extractor/parsers/ast-visitors.d.ts +33 -15
- package/types/extractor/parsers/ast-visitors.d.ts.map +1 -1
- package/types/extractor/parsers/jsx-parser.d.ts.map +1 -1
- package/types/heuristic-config.d.ts.map +1 -1
- package/types/status.d.ts.map +1 -1
- package/types/syncer.d.ts.map +1 -1
- package/types/types.d.ts +19 -1
- package/types/types.d.ts.map +1 -1
- package/types/utils/file-utils.d.ts +16 -1
- package/types/utils/file-utils.d.ts.map +1 -1
package/src/types.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Node } from '@swc/core'
|
|
1
|
+
import type { Node, Expression } from '@swc/core'
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Main configuration interface for the i18next toolkit.
|
|
@@ -83,6 +83,24 @@ export interface I18nextToolkitConfig {
|
|
|
83
83
|
|
|
84
84
|
/** Secondary languages that get empty values initially */
|
|
85
85
|
secondaryLanguages?: string[];
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* The format of the output translation files.
|
|
89
|
+
* 'json': Standard JSON file (default)
|
|
90
|
+
* 'js': JavaScript file with ES Module syntax (export default)
|
|
91
|
+
* 'js-esm': JavaScript file with ES Module syntax (export default)
|
|
92
|
+
* 'js-cjs': JavaScript file with CommonJS syntax (module.exports)
|
|
93
|
+
* 'ts': TypeScript file with ES Module syntax and `as const` for type safety
|
|
94
|
+
*/
|
|
95
|
+
outputFormat?: 'json' | 'js' | 'js-esm' | 'js-esm' | 'js-cjs' | 'ts';
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* If true, all namespaces will be merged into a single file per language.
|
|
99
|
+
* The `output` path should not contain the `{{namespace}}` placeholder.
|
|
100
|
+
* Example output: `locales/en.js`
|
|
101
|
+
* (default: false)
|
|
102
|
+
*/
|
|
103
|
+
mergeNamespaces?: boolean;
|
|
86
104
|
};
|
|
87
105
|
|
|
88
106
|
/** Configuration options for TypeScript type generation */
|
|
@@ -223,6 +241,9 @@ export interface ExtractedKey {
|
|
|
223
241
|
|
|
224
242
|
/** Whether this key is used with pluralization (count parameter) */
|
|
225
243
|
hasCount?: boolean;
|
|
244
|
+
|
|
245
|
+
/** hold the raw context expression from the AST */
|
|
246
|
+
contextExpression?: Expression;
|
|
226
247
|
}
|
|
227
248
|
|
|
228
249
|
/**
|
package/src/utils/file-utils.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { mkdir, readFile, writeFile } from 'node:fs/promises'
|
|
2
2
|
import { dirname } from 'node:path'
|
|
3
|
+
import { createJiti } from 'jiti'
|
|
4
|
+
import type { I18nextToolkitConfig } from '../types'
|
|
3
5
|
|
|
4
6
|
/**
|
|
5
7
|
* Ensures that the directory for a given file path exists.
|
|
@@ -73,9 +75,60 @@ export async function writeFileAsync (filePath: string, data: string): Promise<v
|
|
|
73
75
|
export function getOutputPath (
|
|
74
76
|
template: string,
|
|
75
77
|
locale: string,
|
|
76
|
-
namespace: string
|
|
78
|
+
namespace: string = ''
|
|
77
79
|
): string {
|
|
78
80
|
return template
|
|
79
81
|
.replace('{{language}}', locale).replace('{{lng}}', locale)
|
|
80
82
|
.replace('{{namespace}}', namespace).replace('{{ns}}', namespace)
|
|
81
83
|
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Dynamically loads a translation file, supporting .json, .js, and .ts formats.
|
|
87
|
+
* @param filePath - The path to the translation file.
|
|
88
|
+
* @returns The parsed content of the file, or null if not found or failed to parse.
|
|
89
|
+
*/
|
|
90
|
+
export async function loadTranslationFile (filePath: string): Promise<Record<string, any> | null> {
|
|
91
|
+
try {
|
|
92
|
+
if (filePath.endsWith('.json')) {
|
|
93
|
+
const content = await readFile(filePath, 'utf-8')
|
|
94
|
+
return JSON.parse(content)
|
|
95
|
+
} else if (filePath.endsWith('.ts') || filePath.endsWith('.js')) {
|
|
96
|
+
const jiti = createJiti(import.meta.url)
|
|
97
|
+
const module = await jiti.import(filePath, { default: true })
|
|
98
|
+
return module as Record<string, any> | null
|
|
99
|
+
}
|
|
100
|
+
} catch (e) {
|
|
101
|
+
// File not found or parse error
|
|
102
|
+
return null
|
|
103
|
+
}
|
|
104
|
+
return null
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Serializes a translation object into a string based on the desired format.
|
|
109
|
+
* @param data - The translation data object.
|
|
110
|
+
* @param format - The desired output format ('json', 'js-esm', etc.).
|
|
111
|
+
* @param indentation - The number of spaces for indentation.
|
|
112
|
+
* @returns The serialized file content as a string.
|
|
113
|
+
*/
|
|
114
|
+
export function serializeTranslationFile (
|
|
115
|
+
data: Record<string, any>,
|
|
116
|
+
format: I18nextToolkitConfig['extract']['outputFormat'] = 'json',
|
|
117
|
+
indentation: number = 2
|
|
118
|
+
): string {
|
|
119
|
+
const jsonString = JSON.stringify(data, null, indentation)
|
|
120
|
+
|
|
121
|
+
switch (format) {
|
|
122
|
+
case 'js':
|
|
123
|
+
case 'js-esm':
|
|
124
|
+
return `export default ${jsonString};\n`
|
|
125
|
+
case 'js-cjs':
|
|
126
|
+
return `module.exports = ${jsonString};\n`
|
|
127
|
+
case 'ts':
|
|
128
|
+
// Using `as const` provides better type inference for TypeScript users
|
|
129
|
+
return `export default ${jsonString} as const;\n`
|
|
130
|
+
case 'json':
|
|
131
|
+
default:
|
|
132
|
+
return jsonString
|
|
133
|
+
}
|
|
134
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"extractor.d.ts","sourceRoot":"","sources":["../../../src/extractor/core/extractor.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,MAAM,EAAE,YAAY,EAAiB,oBAAoB,EAAE,MAAM,aAAa,CAAA;AAM5F,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAA;
|
|
1
|
+
{"version":3,"file":"extractor.d.ts","sourceRoot":"","sources":["../../../src/extractor/core/extractor.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,MAAM,EAAE,YAAY,EAAiB,oBAAoB,EAAE,MAAM,aAAa,CAAA;AAM5F,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAA;AAIrD;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAsB,YAAY,CAChC,MAAM,EAAE,oBAAoB,EAC5B,MAAM,GAAE,MAA4B,GACnC,OAAO,CAAC,OAAO,CAAC,CAoClB;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAsB,WAAW,CAC/B,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,oBAAoB,EAC5B,OAAO,EAAE,GAAG,CAAC,MAAM,EAAE,YAAY,CAAC,EAClC,WAAW,EAAE,WAAW,EACxB,MAAM,GAAE,MAA4B,GACnC,OAAO,CAAC,IAAI,CAAC,CA6Bf;AAmCD;;;;;;;;;;;;;;GAcG;AACH,wBAAsB,OAAO,CAAE,MAAM,EAAE,oBAAoB,sDAO1D"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"translation-manager.d.ts","sourceRoot":"","sources":["../../../src/extractor/core/translation-manager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,YAAY,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAA;
|
|
1
|
+
{"version":3,"file":"translation-manager.d.ts","sourceRoot":"","sources":["../../../src/extractor/core/translation-manager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,YAAY,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAA;AAgBnF;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,wBAAsB,eAAe,CACnC,IAAI,EAAE,GAAG,CAAC,MAAM,EAAE,YAAY,CAAC,EAC/B,UAAU,EAAE,GAAG,CAAC,MAAM,CAAC,EACvB,MAAM,EAAE,oBAAoB,GAC3B,OAAO,CAAC,iBAAiB,EAAE,CAAC,CAyF9B"}
|
|
@@ -163,21 +163,6 @@ export declare class ASTVisitors {
|
|
|
163
163
|
* @private
|
|
164
164
|
*/
|
|
165
165
|
private handlePluralKeys;
|
|
166
|
-
/**
|
|
167
|
-
* Extracts default value from translation function call arguments.
|
|
168
|
-
*
|
|
169
|
-
* Supports multiple patterns:
|
|
170
|
-
* - String as second argument: `t('key', 'Default')`
|
|
171
|
-
* - Object with defaultValue: `t('key', { defaultValue: 'Default' })`
|
|
172
|
-
* - Falls back to the key itself if no default found
|
|
173
|
-
*
|
|
174
|
-
* @param node - Call expression node
|
|
175
|
-
* @param fallback - Fallback value if no default found
|
|
176
|
-
* @returns Extracted default value
|
|
177
|
-
*
|
|
178
|
-
* @private
|
|
179
|
-
*/
|
|
180
|
-
private getDefaultValue;
|
|
181
166
|
/**
|
|
182
167
|
* Processes JSX elements to extract translation keys from Trans components.
|
|
183
168
|
*
|
|
@@ -232,5 +217,38 @@ export declare class ASTVisitors {
|
|
|
232
217
|
* @private
|
|
233
218
|
*/
|
|
234
219
|
private extractKeyFromSelector;
|
|
220
|
+
/**
|
|
221
|
+
* Resolves an expression to one or more possible string values that can be
|
|
222
|
+
* determined statically from the AST.
|
|
223
|
+
*
|
|
224
|
+
* Supports:
|
|
225
|
+
* - StringLiteral -> single value
|
|
226
|
+
* - ConditionalExpression (ternary) -> union of consequent and alternate resolved values
|
|
227
|
+
* - The identifier `undefined` -> empty array
|
|
228
|
+
*
|
|
229
|
+
* For any other expression types (identifiers, function calls, member expressions,
|
|
230
|
+
* etc.) the value cannot be determined statically and an empty array is returned.
|
|
231
|
+
*
|
|
232
|
+
* @private
|
|
233
|
+
* @param expression - The SWC AST expression node to resolve
|
|
234
|
+
* @returns An array of possible string values that the expression may produce.
|
|
235
|
+
*/
|
|
236
|
+
private resolvePossibleStringValues;
|
|
237
|
+
/**
|
|
238
|
+
* Finds and returns the full property node (KeyValueProperty) for the given
|
|
239
|
+
* property name from an ObjectExpression.
|
|
240
|
+
*
|
|
241
|
+
* Matches both identifier keys (e.g., { ns: 'value' }) and string literal keys
|
|
242
|
+
* (e.g., { 'ns': 'value' }).
|
|
243
|
+
*
|
|
244
|
+
* This helper returns the full property node rather than just its primitive
|
|
245
|
+
* value so callers can inspect expression types (ConditionalExpression, etc.).
|
|
246
|
+
*
|
|
247
|
+
* @private
|
|
248
|
+
* @param object - The SWC ObjectExpression to search
|
|
249
|
+
* @param propName - The property name to locate
|
|
250
|
+
* @returns The matching KeyValueProperty node if found, otherwise undefined.
|
|
251
|
+
*/
|
|
252
|
+
private getObjectProperty;
|
|
235
253
|
}
|
|
236
254
|
//# sourceMappingURL=ast-visitors.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ast-visitors.d.ts","sourceRoot":"","sources":["../../../src/extractor/parsers/ast-visitors.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"ast-visitors.d.ts","sourceRoot":"","sources":["../../../src/extractor/parsers/ast-visitors.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAA+G,MAAM,WAAW,CAAA;AACpJ,OAAO,KAAK,EAAE,aAAa,EAAE,oBAAoB,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AAc9E;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,qBAAa,WAAW;IACtB,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAe;IAC7C,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAsB;IAC7C,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAQ;IAC/B,OAAO,CAAC,UAAU,CAAoC;IAE/C,UAAU,cAAoB;IAErC;;;;;;OAMG;gBAED,MAAM,EAAE,oBAAoB,EAC5B,aAAa,EAAE,aAAa,EAC5B,MAAM,EAAE,MAAM;IAOhB;;;;;OAKG;IACI,KAAK,CAAE,IAAI,EAAE,MAAM,GAAG,IAAI;IAMjC;;;;;;;;;;;;OAYG;IACH,OAAO,CAAC,IAAI;IAiDZ;;;;;OAKG;IACH,OAAO,CAAC,UAAU;IAIlB;;;;;OAKG;IACH,OAAO,CAAC,SAAS;IAIjB;;;;;;;;OAQG;IACH,OAAO,CAAC,aAAa;IAMrB;;;;;;;;OAQG;IACH,OAAO,CAAC,eAAe;IASvB;;;;;;;;;;;;OAYG;IACH,OAAO,CAAC,wBAAwB;IAqBhC;;;;;;;;;;;;;OAaG;IACH,OAAO,CAAC,8BAA8B;IAkDtC;;;;;;;;;;;OAWG;IACH,OAAO,CAAC,yBAAyB;IAoBjC;;;;;;;;;;;;;;OAcG;IACH,OAAO,CAAC,oBAAoB;IA4H5B;;;;;;;;;;;;OAYG;IACH,OAAO,CAAC,gBAAgB;IAmBxB;;;;;;;;;OASG;IACH,OAAO,CAAC,gBAAgB;IAuDxB;;;;;;;;;;;OAWG;IACH,OAAO,CAAC,cAAc;IAgBtB;;;;;;;;;;;OAWG;IACH,OAAO,CAAC,kBAAkB;IA6B1B;;;;;;;;;;;;;;;OAeG;IACH,OAAO,CAAC,sBAAsB;IA2C9B;;;;;;;;;;;;;;;OAeG;IACH,OAAO,CAAC,2BAA2B;IAmBnC;;;;;;;;;;;;;;OAcG;IACH,OAAO,CAAC,iBAAiB;CAU1B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jsx-parser.d.ts","sourceRoot":"","sources":["../../../src/extractor/parsers/jsx-parser.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,WAAW,CAAA;AAC3C,OAAO,KAAK,EAAE,YAAY,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAA;AAErE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,wBAAgB,yBAAyB,CAAE,IAAI,EAAE,UAAU,EAAE,MAAM,EAAE,oBAAoB,GAAG,YAAY,GAAG,IAAI,
|
|
1
|
+
{"version":3,"file":"jsx-parser.d.ts","sourceRoot":"","sources":["../../../src/extractor/parsers/jsx-parser.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,WAAW,CAAA;AAC3C,OAAO,KAAK,EAAE,YAAY,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAA;AAErE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,wBAAgB,yBAAyB,CAAE,IAAI,EAAE,UAAU,EAAE,MAAM,EAAE,oBAAoB,GAAG,YAAY,GAAG,IAAI,CA4D9G"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"heuristic-config.d.ts","sourceRoot":"","sources":["../src/heuristic-config.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAA;AAiBnD;;;;;;GAMG;AACH,wBAAsB,YAAY,IAAK,OAAO,CAAC,OAAO,CAAC,oBAAoB,CAAC,GAAG,IAAI,CAAC,
|
|
1
|
+
{"version":3,"file":"heuristic-config.d.ts","sourceRoot":"","sources":["../src/heuristic-config.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAA;AAiBnD;;;;;;GAMG;AACH,wBAAsB,YAAY,IAAK,OAAO,CAAC,OAAO,CAAC,oBAAoB,CAAC,GAAG,IAAI,CAAC,CAuDnF"}
|
package/types/status.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"status.d.ts","sourceRoot":"","sources":["../src/status.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"status.d.ts","sourceRoot":"","sources":["../src/status.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,oBAAoB,EAAgB,MAAM,SAAS,CAAA;AAGjE;;GAEG;AACH,UAAU,aAAa;IACrB,0EAA0E;IAC1E,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,wCAAwC;IACxC,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AA0BD;;;;;;;;;;;;;GAaG;AACH,wBAAsB,SAAS,CAAE,MAAM,EAAE,oBAAoB,EAAE,OAAO,GAAE,aAAkB,iBAYzF"}
|
package/types/syncer.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"syncer.d.ts","sourceRoot":"","sources":["../src/syncer.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"syncer.d.ts","sourceRoot":"","sources":["../src/syncer.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAA;AAInD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,wBAAsB,SAAS,CAAE,MAAM,EAAE,oBAAoB,iBA8E5D"}
|
package/types/types.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Node } from '@swc/core';
|
|
1
|
+
import type { Node, Expression } from '@swc/core';
|
|
2
2
|
/**
|
|
3
3
|
* Main configuration interface for the i18next toolkit.
|
|
4
4
|
* Defines all available options for extraction, type generation, synchronization, and integrations.
|
|
@@ -63,6 +63,22 @@ export interface I18nextToolkitConfig {
|
|
|
63
63
|
primaryLanguage?: string;
|
|
64
64
|
/** Secondary languages that get empty values initially */
|
|
65
65
|
secondaryLanguages?: string[];
|
|
66
|
+
/**
|
|
67
|
+
* The format of the output translation files.
|
|
68
|
+
* 'json': Standard JSON file (default)
|
|
69
|
+
* 'js': JavaScript file with ES Module syntax (export default)
|
|
70
|
+
* 'js-esm': JavaScript file with ES Module syntax (export default)
|
|
71
|
+
* 'js-cjs': JavaScript file with CommonJS syntax (module.exports)
|
|
72
|
+
* 'ts': TypeScript file with ES Module syntax and `as const` for type safety
|
|
73
|
+
*/
|
|
74
|
+
outputFormat?: 'json' | 'js' | 'js-esm' | 'js-esm' | 'js-cjs' | 'ts';
|
|
75
|
+
/**
|
|
76
|
+
* If true, all namespaces will be merged into a single file per language.
|
|
77
|
+
* The `output` path should not contain the `{{namespace}}` placeholder.
|
|
78
|
+
* Example output: `locales/en.js`
|
|
79
|
+
* (default: false)
|
|
80
|
+
*/
|
|
81
|
+
mergeNamespaces?: boolean;
|
|
66
82
|
};
|
|
67
83
|
/** Configuration options for TypeScript type generation */
|
|
68
84
|
types?: {
|
|
@@ -185,6 +201,8 @@ export interface ExtractedKey {
|
|
|
185
201
|
ns?: string;
|
|
186
202
|
/** Whether this key is used with pluralization (count parameter) */
|
|
187
203
|
hasCount?: boolean;
|
|
204
|
+
/** hold the raw context expression from the AST */
|
|
205
|
+
contextExpression?: Expression;
|
|
188
206
|
}
|
|
189
207
|
/**
|
|
190
208
|
* Result of processing translation files for a specific locale and namespace.
|
package/types/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,WAAW,CAAA;AAEjD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,WAAW,oBAAoB;IACnC,iEAAiE;IACjE,OAAO,EAAE,MAAM,EAAE,CAAC;IAElB,2DAA2D;IAC3D,OAAO,EAAE;QACP,oEAAoE;QACpE,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;QAEzB,mGAAmG;QACnG,MAAM,EAAE,MAAM,CAAC;QAEf,wEAAwE;QACxE,SAAS,CAAC,EAAE,MAAM,CAAC;QAEnB,uEAAuE;QACvE,YAAY,CAAC,EAAE,MAAM,GAAG,KAAK,GAAG,IAAI,CAAC;QAErC,8EAA8E;QAC9E,WAAW,CAAC,EAAE,MAAM,GAAG,KAAK,GAAG,IAAI,CAAC;QAEpC,oDAAoD;QACpD,gBAAgB,CAAC,EAAE,MAAM,CAAC;QAE1B,mDAAmD;QACnD,eAAe,CAAC,EAAE,MAAM,CAAC;QAEzB,wEAAwE;QACxE,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;QAErB,4EAA4E;QAC5E,eAAe,CAAC,EAAE,MAAM,EAAE,CAAC;QAE3B,0GAA0G;QAC1G,mBAAmB,CAAC,EAAE,MAAM,EAAE,CAAC;QAE/B,kFAAkF;QAClF,iBAAiB,CAAC,EAAE,MAAM,EAAE,CAAC;QAE7B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DAA+D;IAC/D,OAAO,EAAE,OAAO,CAAC;IAEjB,2DAA2D;IAC3D,eAAe,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAErC,kEAAkE;IAClE,oBAAoB,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CAC3C;AAED;;;;;;;;;;;;GAYG;AACH,MAAM,WAAW,MAAM;IACrB;;;OAGG;IACH,IAAI,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IAE5B;;;OAGG;IACH,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,GAAG,GAAG,IAAI,CAAC;IAExC;;;OAGG;IACH,KAAK,CAAC,OAAO,EAAE,MAAM,GAAG,GAAG,GAAG,IAAI,CAAC;CACpC;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,WAAW,aAAa;IAC5B;;;;;OAKG;IACH,MAAM,EAAE,CAAC,OAAO,EAAE,YAAY,KAAK,IAAI,CAAC;CACzC"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { I18nextToolkitConfig } from '../types';
|
|
1
2
|
/**
|
|
2
3
|
* Ensures that the directory for a given file path exists.
|
|
3
4
|
* Creates all necessary parent directories recursively if they don't exist.
|
|
@@ -57,5 +58,19 @@ export declare function writeFileAsync(filePath: string, data: string): Promise<
|
|
|
57
58
|
* // Returns: 'locales/en/common.json'
|
|
58
59
|
* ```
|
|
59
60
|
*/
|
|
60
|
-
export declare function getOutputPath(template: string, locale: string, namespace
|
|
61
|
+
export declare function getOutputPath(template: string, locale: string, namespace?: string): string;
|
|
62
|
+
/**
|
|
63
|
+
* Dynamically loads a translation file, supporting .json, .js, and .ts formats.
|
|
64
|
+
* @param filePath - The path to the translation file.
|
|
65
|
+
* @returns The parsed content of the file, or null if not found or failed to parse.
|
|
66
|
+
*/
|
|
67
|
+
export declare function loadTranslationFile(filePath: string): Promise<Record<string, any> | null>;
|
|
68
|
+
/**
|
|
69
|
+
* Serializes a translation object into a string based on the desired format.
|
|
70
|
+
* @param data - The translation data object.
|
|
71
|
+
* @param format - The desired output format ('json', 'js-esm', etc.).
|
|
72
|
+
* @param indentation - The number of spaces for indentation.
|
|
73
|
+
* @returns The serialized file content as a string.
|
|
74
|
+
*/
|
|
75
|
+
export declare function serializeTranslationFile(data: Record<string, any>, format?: I18nextToolkitConfig['extract']['outputFormat'], indentation?: number): string;
|
|
61
76
|
//# sourceMappingURL=file-utils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"file-utils.d.ts","sourceRoot":"","sources":["../../src/utils/file-utils.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;GAWG;AACH,wBAAsB,qBAAqB,CAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAG5E;AAED;;;;;;;;;;;GAWG;AACH,wBAAsB,aAAa,CAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAEtE;AAED;;;;;;;;;;;GAWG;AACH,wBAAsB,cAAc,CAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAEnF;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,aAAa,CAC3B,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"file-utils.d.ts","sourceRoot":"","sources":["../../src/utils/file-utils.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAA;AAEpD;;;;;;;;;;;GAWG;AACH,wBAAsB,qBAAqB,CAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAG5E;AAED;;;;;;;;;;;GAWG;AACH,wBAAsB,aAAa,CAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CA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