i18next-cli 1.42.8 → 1.42.9
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/dist/cjs/cli.js +1 -1
- package/dist/cjs/extractor/core/translation-manager.js +2 -8
- package/dist/cjs/utils/file-utils.js +0 -38
- package/dist/esm/cli.js +1 -1
- package/dist/esm/extractor/core/translation-manager.js +4 -10
- package/dist/esm/utils/file-utils.js +1 -38
- package/package.json +1 -1
- package/types/extractor/core/translation-manager.d.ts.map +1 -1
- package/types/utils/file-utils.d.ts +0 -16
- package/types/utils/file-utils.d.ts.map +1 -1
package/dist/cjs/cli.js
CHANGED
|
@@ -28,7 +28,7 @@ const program = new commander.Command();
|
|
|
28
28
|
program
|
|
29
29
|
.name('i18next-cli')
|
|
30
30
|
.description('A unified, high-performance i18next CLI.')
|
|
31
|
-
.version('1.42.
|
|
31
|
+
.version('1.42.9'); // This string is replaced with the actual version at build time by rollup
|
|
32
32
|
// new: global config override option
|
|
33
33
|
program.option('-c, --config <path>', 'Path to i18next-cli config file (overrides detection)');
|
|
34
34
|
program
|
|
@@ -826,19 +826,13 @@ async function getTranslations(keys, objectKeys, config, { syncPrimaryWithDefaul
|
|
|
826
826
|
}
|
|
827
827
|
else {
|
|
828
828
|
// Find all namespaces that exist on disk for this locale.
|
|
829
|
-
// Use '**' so the glob crosses directory boundaries — namespaces
|
|
830
|
-
// can contain '/' and span multiple directory levels.
|
|
831
829
|
const namespacesToProcess = new Set(keysByNS.keys());
|
|
832
|
-
const existingNsPattern = fileUtils.getOutputPath(config.extract.output, locale, '
|
|
830
|
+
const existingNsPattern = fileUtils.getOutputPath(config.extract.output, locale, '*');
|
|
833
831
|
// Ensure glob receives POSIX-style separators so pattern matching works cross-platform (Windows -> backslashes)
|
|
834
832
|
const existingNsGlobPattern = existingNsPattern.replace(/\\/g, '/');
|
|
835
833
|
const existingNsFiles = await glob.glob(existingNsGlobPattern, { ignore: userIgnore });
|
|
836
834
|
for (const file of existingNsFiles) {
|
|
837
|
-
|
|
838
|
-
// by matching it against the output template.
|
|
839
|
-
const ns = typeof config.extract.output === 'string'
|
|
840
|
-
? fileUtils.extractNamespaceFromPath(config.extract.output, locale, file)
|
|
841
|
-
: undefined;
|
|
835
|
+
const ns = node_path.basename(file, node_path.extname(file));
|
|
842
836
|
if (ns) {
|
|
843
837
|
namespacesToProcess.add(ns);
|
|
844
838
|
}
|
|
@@ -45,43 +45,6 @@ function getOutputPath(outputTemplate, language, namespace) {
|
|
|
45
45
|
out = out.replace(/\/\/+/g, '/');
|
|
46
46
|
return node_path.normalize(out);
|
|
47
47
|
}
|
|
48
|
-
/**
|
|
49
|
-
* Extracts the namespace value from a concrete file path by matching it against
|
|
50
|
-
* the output template.
|
|
51
|
-
*
|
|
52
|
-
* Given a template like `src/{{namespace}}/locales/{{language}}.json` and a file
|
|
53
|
-
* path like `src/widgets/component/locales/en.json`, this returns `widgets/component`.
|
|
54
|
-
*
|
|
55
|
-
* This handles multi-segment namespaces (namespaces containing `/`) which
|
|
56
|
-
* `basename()` cannot recover.
|
|
57
|
-
*
|
|
58
|
-
* @param outputTemplate - The output path template string (must contain `{{namespace}}`)
|
|
59
|
-
* @param language - The language value used when the file was generated
|
|
60
|
-
* @param filePath - The concrete file path to extract the namespace from
|
|
61
|
-
* @returns The namespace string, or `undefined` if the path doesn't match the template
|
|
62
|
-
*/
|
|
63
|
-
function extractNamespaceFromPath(outputTemplate, language, filePath) {
|
|
64
|
-
// Build a regex from the template by escaping everything except the placeholders.
|
|
65
|
-
// Replace {{language}}/{{lng}} with the literal language value and
|
|
66
|
-
// {{namespace}} with a named capture group that matches one or more path segments.
|
|
67
|
-
const pattern = outputTemplate
|
|
68
|
-
// Normalise to forward slashes for matching
|
|
69
|
-
.replace(/\\/g, '/');
|
|
70
|
-
// Escape regex-special characters (but keep our placeholders intact first)
|
|
71
|
-
const nsPlaceholder = '{{namespace}}';
|
|
72
|
-
const parts = pattern.split(nsPlaceholder);
|
|
73
|
-
// Escape each part individually then rejoin with the capture group
|
|
74
|
-
const escaped = parts.map(p => p
|
|
75
|
-
.replace(/\{\{language\}\}|\{\{lng\}\}/g, () => escapeForRegex(language))
|
|
76
|
-
.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'));
|
|
77
|
-
// Don't anchor the start — the glob may return absolute or prefixed paths.
|
|
78
|
-
// Anchor only the end so that the namespace capture is unambiguous.
|
|
79
|
-
const regexStr = escaped.join('(.+)') + '$';
|
|
80
|
-
const normalized = filePath.replace(/\\/g, '/');
|
|
81
|
-
const m = new RegExp(regexStr).exec(normalized);
|
|
82
|
-
return m?.[1];
|
|
83
|
-
}
|
|
84
|
-
const escapeForRegex = (s) => s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
85
48
|
/**
|
|
86
49
|
* Dynamically loads a translation file, supporting .json, .js, and .ts formats.
|
|
87
50
|
* @param filePath - The path to the translation file.
|
|
@@ -193,7 +156,6 @@ function inferFormatFromPath(filePath, defaultFormat = 'json') {
|
|
|
193
156
|
return defaultFormat || 'json';
|
|
194
157
|
}
|
|
195
158
|
|
|
196
|
-
exports.extractNamespaceFromPath = extractNamespaceFromPath;
|
|
197
159
|
exports.getOutputPath = getOutputPath;
|
|
198
160
|
exports.inferFormatFromPath = inferFormatFromPath;
|
|
199
161
|
exports.loadRawJson5Content = loadRawJson5Content;
|
package/dist/esm/cli.js
CHANGED
|
@@ -26,7 +26,7 @@ const program = new Command();
|
|
|
26
26
|
program
|
|
27
27
|
.name('i18next-cli')
|
|
28
28
|
.description('A unified, high-performance i18next CLI.')
|
|
29
|
-
.version('1.42.
|
|
29
|
+
.version('1.42.9'); // This string is replaced with the actual version at build time by rollup
|
|
30
30
|
// new: global config override option
|
|
31
31
|
program.option('-c, --config <path>', 'Path to i18next-cli config file (overrides detection)');
|
|
32
32
|
program
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { resolve } from 'node:path';
|
|
1
|
+
import { resolve, basename, extname } from 'node:path';
|
|
2
2
|
import { glob } from 'glob';
|
|
3
3
|
import { getNestedKeys, getNestedValue, setNestedValue } from '../../utils/nested-object.js';
|
|
4
|
-
import { getOutputPath, loadTranslationFile
|
|
4
|
+
import { getOutputPath, loadTranslationFile } from '../../utils/file-utils.js';
|
|
5
5
|
import { resolveDefaultValue } from '../../utils/default-value.js';
|
|
6
6
|
|
|
7
7
|
// used for natural language check
|
|
@@ -824,19 +824,13 @@ async function getTranslations(keys, objectKeys, config, { syncPrimaryWithDefaul
|
|
|
824
824
|
}
|
|
825
825
|
else {
|
|
826
826
|
// Find all namespaces that exist on disk for this locale.
|
|
827
|
-
// Use '**' so the glob crosses directory boundaries — namespaces
|
|
828
|
-
// can contain '/' and span multiple directory levels.
|
|
829
827
|
const namespacesToProcess = new Set(keysByNS.keys());
|
|
830
|
-
const existingNsPattern = getOutputPath(config.extract.output, locale, '
|
|
828
|
+
const existingNsPattern = getOutputPath(config.extract.output, locale, '*');
|
|
831
829
|
// Ensure glob receives POSIX-style separators so pattern matching works cross-platform (Windows -> backslashes)
|
|
832
830
|
const existingNsGlobPattern = existingNsPattern.replace(/\\/g, '/');
|
|
833
831
|
const existingNsFiles = await glob(existingNsGlobPattern, { ignore: userIgnore });
|
|
834
832
|
for (const file of existingNsFiles) {
|
|
835
|
-
|
|
836
|
-
// by matching it against the output template.
|
|
837
|
-
const ns = typeof config.extract.output === 'string'
|
|
838
|
-
? extractNamespaceFromPath(config.extract.output, locale, file)
|
|
839
|
-
: undefined;
|
|
833
|
+
const ns = basename(file, extname(file));
|
|
840
834
|
if (ns) {
|
|
841
835
|
namespacesToProcess.add(ns);
|
|
842
836
|
}
|
|
@@ -43,43 +43,6 @@ function getOutputPath(outputTemplate, language, namespace) {
|
|
|
43
43
|
out = out.replace(/\/\/+/g, '/');
|
|
44
44
|
return normalize(out);
|
|
45
45
|
}
|
|
46
|
-
/**
|
|
47
|
-
* Extracts the namespace value from a concrete file path by matching it against
|
|
48
|
-
* the output template.
|
|
49
|
-
*
|
|
50
|
-
* Given a template like `src/{{namespace}}/locales/{{language}}.json` and a file
|
|
51
|
-
* path like `src/widgets/component/locales/en.json`, this returns `widgets/component`.
|
|
52
|
-
*
|
|
53
|
-
* This handles multi-segment namespaces (namespaces containing `/`) which
|
|
54
|
-
* `basename()` cannot recover.
|
|
55
|
-
*
|
|
56
|
-
* @param outputTemplate - The output path template string (must contain `{{namespace}}`)
|
|
57
|
-
* @param language - The language value used when the file was generated
|
|
58
|
-
* @param filePath - The concrete file path to extract the namespace from
|
|
59
|
-
* @returns The namespace string, or `undefined` if the path doesn't match the template
|
|
60
|
-
*/
|
|
61
|
-
function extractNamespaceFromPath(outputTemplate, language, filePath) {
|
|
62
|
-
// Build a regex from the template by escaping everything except the placeholders.
|
|
63
|
-
// Replace {{language}}/{{lng}} with the literal language value and
|
|
64
|
-
// {{namespace}} with a named capture group that matches one or more path segments.
|
|
65
|
-
const pattern = outputTemplate
|
|
66
|
-
// Normalise to forward slashes for matching
|
|
67
|
-
.replace(/\\/g, '/');
|
|
68
|
-
// Escape regex-special characters (but keep our placeholders intact first)
|
|
69
|
-
const nsPlaceholder = '{{namespace}}';
|
|
70
|
-
const parts = pattern.split(nsPlaceholder);
|
|
71
|
-
// Escape each part individually then rejoin with the capture group
|
|
72
|
-
const escaped = parts.map(p => p
|
|
73
|
-
.replace(/\{\{language\}\}|\{\{lng\}\}/g, () => escapeForRegex(language))
|
|
74
|
-
.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'));
|
|
75
|
-
// Don't anchor the start — the glob may return absolute or prefixed paths.
|
|
76
|
-
// Anchor only the end so that the namespace capture is unambiguous.
|
|
77
|
-
const regexStr = escaped.join('(.+)') + '$';
|
|
78
|
-
const normalized = filePath.replace(/\\/g, '/');
|
|
79
|
-
const m = new RegExp(regexStr).exec(normalized);
|
|
80
|
-
return m?.[1];
|
|
81
|
-
}
|
|
82
|
-
const escapeForRegex = (s) => s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
83
46
|
/**
|
|
84
47
|
* Dynamically loads a translation file, supporting .json, .js, and .ts formats.
|
|
85
48
|
* @param filePath - The path to the translation file.
|
|
@@ -191,4 +154,4 @@ function inferFormatFromPath(filePath, defaultFormat = 'json') {
|
|
|
191
154
|
return defaultFormat || 'json';
|
|
192
155
|
}
|
|
193
156
|
|
|
194
|
-
export {
|
|
157
|
+
export { getOutputPath, inferFormatFromPath, loadRawJson5Content, loadTranslationFile, serializeTranslationFile };
|
package/package.json
CHANGED
|
@@ -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;AAgyBnF;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,wBAAsB,eAAe,CACnC,IAAI,EAAE,GAAG,CAAC,MAAM,EAAE,YAAY,CAAC,EAC/B,UAAU,EAAE,GAAG,CAAC,MAAM,CAAC,EACvB,MAAM,EAAE,oBAAoB,EAC5B,EACE,uBAA+B,EAC/B,OAAe,EAChB,GAAE;IACD,uBAAuB,CAAC,EAAE,OAAO,CAAC;IAClC,OAAO,CAAC,EAAE,OAAO,CAAA;CACb,GACL,OAAO,CAAC,iBAAiB,EAAE,CAAC,
|
|
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;AAgyBnF;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,wBAAsB,eAAe,CACnC,IAAI,EAAE,GAAG,CAAC,MAAM,EAAE,YAAY,CAAC,EAC/B,UAAU,EAAE,GAAG,CAAC,MAAM,CAAC,EACvB,MAAM,EAAE,oBAAoB,EAC5B,EACE,uBAA+B,EAC/B,OAAe,EAChB,GAAE;IACD,uBAAuB,CAAC,EAAE,OAAO,CAAC;IAClC,OAAO,CAAC,EAAE,OAAO,CAAA;CACb,GACL,OAAO,CAAC,iBAAiB,EAAE,CAAC,CA8J9B"}
|
|
@@ -48,22 +48,6 @@ export declare function writeFileAsync(filePath: string, data: string): Promise<
|
|
|
48
48
|
* - Normalizes duplicate slashes and returns a platform-correct path.
|
|
49
49
|
*/
|
|
50
50
|
export declare function getOutputPath(outputTemplate: string | ((language: string, namespace?: string) => string) | undefined, language: string, namespace?: string): string;
|
|
51
|
-
/**
|
|
52
|
-
* Extracts the namespace value from a concrete file path by matching it against
|
|
53
|
-
* the output template.
|
|
54
|
-
*
|
|
55
|
-
* Given a template like `src/{{namespace}}/locales/{{language}}.json` and a file
|
|
56
|
-
* path like `src/widgets/component/locales/en.json`, this returns `widgets/component`.
|
|
57
|
-
*
|
|
58
|
-
* This handles multi-segment namespaces (namespaces containing `/`) which
|
|
59
|
-
* `basename()` cannot recover.
|
|
60
|
-
*
|
|
61
|
-
* @param outputTemplate - The output path template string (must contain `{{namespace}}`)
|
|
62
|
-
* @param language - The language value used when the file was generated
|
|
63
|
-
* @param filePath - The concrete file path to extract the namespace from
|
|
64
|
-
* @returns The namespace string, or `undefined` if the path doesn't match the template
|
|
65
|
-
*/
|
|
66
|
-
export declare function extractNamespaceFromPath(outputTemplate: string, language: string, filePath: string): string | undefined;
|
|
67
51
|
/**
|
|
68
52
|
* Dynamically loads a translation file, supporting .json, .js, and .ts formats.
|
|
69
53
|
* @param filePath - The path to the translation file.
|
|
@@ -1 +1 @@
|
|
|
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;AAKpD;;;;;;;;;;;GAWG;AACH,wBAAsB,qBAAqB,CAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI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