i18next-cli 1.73.0 → 1.73.1
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/parsers/jsx-handler.js +51 -29
- package/dist/esm/cli.js +1 -1
- package/dist/esm/extractor/parsers/jsx-handler.js +52 -30
- package/package.json +1 -1
- package/types/extractor/parsers/jsx-handler.d.ts +14 -8
- package/types/extractor/parsers/jsx-handler.d.ts.map +1 -1
package/dist/cjs/cli.js
CHANGED
|
@@ -37,7 +37,7 @@ const program = new commander.Command();
|
|
|
37
37
|
program
|
|
38
38
|
.name('i18next-cli')
|
|
39
39
|
.description('A unified, high-performance i18next CLI.')
|
|
40
|
-
.version('1.73.
|
|
40
|
+
.version('1.73.1') // This string is replaced with the actual version at build time by rollup
|
|
41
41
|
.addHelpText('after', '\nUsing an AI coding agent? Install the i18next-localization skill: npx skills add i18next/i18next-cli\n');
|
|
42
42
|
// new: global config override option
|
|
43
43
|
program.option('-c, --config <path>', 'Path to i18next-cli config file (overrides detection)');
|
|
@@ -31,13 +31,19 @@ class JSXHandler {
|
|
|
31
31
|
return astUtils.lineColumnFromOffset(this.getCurrentCode(), node.span.start);
|
|
32
32
|
}
|
|
33
33
|
/**
|
|
34
|
-
* Emits an error for `<Trans
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
34
|
+
* Emits an error for `<Trans>` children that the serializer cannot turn
|
|
35
|
+
* into the string react-i18next builds at runtime:
|
|
36
|
+
*
|
|
37
|
+
* - `{name}` (a bare identifier): react-i18next inlines the value, but the
|
|
38
|
+
* extractor serialises the identifier name as `{{name}}`.
|
|
39
|
+
* - `{table.name}`, `{fn()}`, `` {`a ${b}`} `` and any other expression
|
|
40
|
+
* (the fallback in `swcExpressionToReactNode`): react-i18next inlines the
|
|
41
|
+
* value, but the extractor emits an empty `<1></1>` placeholder.
|
|
42
|
+
*
|
|
43
|
+
* Either way the extracted key never matches the runtime key. The fix is
|
|
44
|
+
* the `{{name}}` / `{{name: table.name}}` object form, which both sides
|
|
45
|
+
* serialise as `{{name}}`; react-i18next reads the value from that object
|
|
46
|
+
* child, so no `values` prop is needed.
|
|
41
47
|
*
|
|
42
48
|
* We keep the existing extraction behaviour so projects that already rely
|
|
43
49
|
* on the `{{name}}` output (with a matching `values` prop) aren't broken,
|
|
@@ -45,36 +51,52 @@ class JSXHandler {
|
|
|
45
51
|
* Emitted via `logger.error` with an `Error:` prefix so build tooling that
|
|
46
52
|
* watches for errors (see #200) can treat this as fatal if desired.
|
|
47
53
|
*/
|
|
48
|
-
|
|
49
|
-
const
|
|
54
|
+
warnOnUnrepresentableTransChildren(node, elementName) {
|
|
55
|
+
const code = this.getCurrentCode();
|
|
56
|
+
const emit = this.pluginContext?.logger?.error?.bind(this.pluginContext.logger) ??
|
|
57
|
+
console.error.bind(console);
|
|
58
|
+
const check = (expr, span) => {
|
|
59
|
+
const inner = this.unwrapExpression(expr);
|
|
60
|
+
if (!inner)
|
|
61
|
+
return;
|
|
62
|
+
switch (inner.type) {
|
|
63
|
+
// The shapes swcExpressionToReactNode serialises faithfully.
|
|
64
|
+
case 'StringLiteral':
|
|
65
|
+
case 'ObjectExpression':
|
|
66
|
+
return;
|
|
67
|
+
case 'TemplateLiteral':
|
|
68
|
+
if (astUtils.isSimpleTemplateLiteral(inner))
|
|
69
|
+
return;
|
|
70
|
+
break;
|
|
71
|
+
case 'ConditionalExpression':
|
|
72
|
+
check(inner.consequent, span);
|
|
73
|
+
check(inner.alternate, span);
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
const { span: s } = inner; // ponytail: JSXMemberExpression lacks span in the SWC union; real children always have one
|
|
77
|
+
const text = code.slice(s.start, s.end);
|
|
78
|
+
const isIdentifier = inner.type === 'Identifier';
|
|
79
|
+
const produced = isIdentifier ? `"{{${text}}}"` : 'an empty "<1></1>" placeholder';
|
|
80
|
+
const name = inner.type === 'MemberExpression' && inner.property.type === 'Identifier' ? inner.property.value : 'value';
|
|
81
|
+
const suggestion = isIdentifier ? `{{${text}}}` : `{{${name}: ${text}}}`;
|
|
82
|
+
const loc = astUtils.lineColumnFromOffset(code, span.start);
|
|
83
|
+
const where = loc
|
|
84
|
+
? `${this.getCurrentFile()}:${loc.line}:${loc.column}`
|
|
85
|
+
: this.getCurrentFile();
|
|
86
|
+
emit(`Error: <${elementName}> child {${text}} at ${where} won't match at runtime: react-i18next inlines the value, but extraction produces ${produced}. Use ${suggestion} (double braces) for interpolation.`);
|
|
87
|
+
};
|
|
50
88
|
const visit = (children) => {
|
|
51
89
|
for (const child of children) {
|
|
52
90
|
if (child.type === 'JSXExpressionContainer') {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
bareIdentifiers.push({ name: inner.value, span: child.span });
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
else if (child.type === 'JSXElement') {
|
|
59
|
-
visit(child.children);
|
|
91
|
+
if (child.expression.type !== 'JSXEmptyExpression')
|
|
92
|
+
check(child.expression, child.span);
|
|
60
93
|
}
|
|
61
|
-
else if (child.type === 'JSXFragment') {
|
|
94
|
+
else if (child.type === 'JSXElement' || child.type === 'JSXFragment') {
|
|
62
95
|
visit(child.children);
|
|
63
96
|
}
|
|
64
97
|
}
|
|
65
98
|
};
|
|
66
99
|
visit(node.children);
|
|
67
|
-
if (bareIdentifiers.length === 0)
|
|
68
|
-
return;
|
|
69
|
-
const emit = this.pluginContext?.logger?.error?.bind(this.pluginContext.logger) ??
|
|
70
|
-
console.error.bind(console);
|
|
71
|
-
for (const { name, span } of bareIdentifiers) {
|
|
72
|
-
const loc = astUtils.lineColumnFromOffset(this.getCurrentCode(), span.start);
|
|
73
|
-
const where = loc
|
|
74
|
-
? `${this.getCurrentFile()}:${loc.line}:${loc.column}`
|
|
75
|
-
: this.getCurrentFile();
|
|
76
|
-
emit(`Error: <${elementName}> child {${name}} at ${where} won't match at runtime — react-i18next inlines the value (e.g. "<1>meow</1>"), but extraction produces "<1>{{${name}}}</1>". Use {{${name}}} (double braces) with values={{ ${name} }} for interpolation.`);
|
|
77
|
-
}
|
|
78
100
|
}
|
|
79
101
|
/**
|
|
80
102
|
* Unwraps TS type-assertion and parenthesis wrappers so we can inspect the
|
|
@@ -103,7 +125,7 @@ class JSXHandler {
|
|
|
103
125
|
handleJSXElement(node, getScopeInfo) {
|
|
104
126
|
const elementName = this.getElementName(node);
|
|
105
127
|
if (elementName && (this.config.extract.transComponents || ['Trans']).includes(elementName)) {
|
|
106
|
-
this.
|
|
128
|
+
this.warnOnUnrepresentableTransChildren(node, elementName);
|
|
107
129
|
let extractedAttributes = null;
|
|
108
130
|
try {
|
|
109
131
|
extractedAttributes = jsxParser.extractFromTransComponent(node, this.config);
|
package/dist/esm/cli.js
CHANGED
|
@@ -31,7 +31,7 @@ const program = new Command();
|
|
|
31
31
|
program
|
|
32
32
|
.name('i18next-cli')
|
|
33
33
|
.description('A unified, high-performance i18next CLI.')
|
|
34
|
-
.version('1.73.
|
|
34
|
+
.version('1.73.1') // This string is replaced with the actual version at build time by rollup
|
|
35
35
|
.addHelpText('after', '\nUsing an AI coding agent? Install the i18next-localization skill: npx skills add i18next/i18next-cli\n');
|
|
36
36
|
// new: global config override option
|
|
37
37
|
program.option('-c, --config <path>', 'Path to i18next-cli config file (overrides detection)');
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { safePluralRules } from '../../utils/plural-rules.js';
|
|
2
2
|
import { extractFromTransComponent } from './jsx-parser.js';
|
|
3
|
-
import { lineColumnFromOffset, getObjectPropValue } from './ast-utils.js';
|
|
3
|
+
import { lineColumnFromOffset, getObjectPropValue, isSimpleTemplateLiteral } from './ast-utils.js';
|
|
4
4
|
|
|
5
5
|
// Checks if a string looks like natural language (contains spaces, punctuation, etc.)
|
|
6
6
|
const naturalLanguageChars = /[ ,?!;]/;
|
|
@@ -29,13 +29,19 @@ class JSXHandler {
|
|
|
29
29
|
return lineColumnFromOffset(this.getCurrentCode(), node.span.start);
|
|
30
30
|
}
|
|
31
31
|
/**
|
|
32
|
-
* Emits an error for `<Trans
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
32
|
+
* Emits an error for `<Trans>` children that the serializer cannot turn
|
|
33
|
+
* into the string react-i18next builds at runtime:
|
|
34
|
+
*
|
|
35
|
+
* - `{name}` (a bare identifier): react-i18next inlines the value, but the
|
|
36
|
+
* extractor serialises the identifier name as `{{name}}`.
|
|
37
|
+
* - `{table.name}`, `{fn()}`, `` {`a ${b}`} `` and any other expression
|
|
38
|
+
* (the fallback in `swcExpressionToReactNode`): react-i18next inlines the
|
|
39
|
+
* value, but the extractor emits an empty `<1></1>` placeholder.
|
|
40
|
+
*
|
|
41
|
+
* Either way the extracted key never matches the runtime key. The fix is
|
|
42
|
+
* the `{{name}}` / `{{name: table.name}}` object form, which both sides
|
|
43
|
+
* serialise as `{{name}}`; react-i18next reads the value from that object
|
|
44
|
+
* child, so no `values` prop is needed.
|
|
39
45
|
*
|
|
40
46
|
* We keep the existing extraction behaviour so projects that already rely
|
|
41
47
|
* on the `{{name}}` output (with a matching `values` prop) aren't broken,
|
|
@@ -43,36 +49,52 @@ class JSXHandler {
|
|
|
43
49
|
* Emitted via `logger.error` with an `Error:` prefix so build tooling that
|
|
44
50
|
* watches for errors (see #200) can treat this as fatal if desired.
|
|
45
51
|
*/
|
|
46
|
-
|
|
47
|
-
const
|
|
52
|
+
warnOnUnrepresentableTransChildren(node, elementName) {
|
|
53
|
+
const code = this.getCurrentCode();
|
|
54
|
+
const emit = this.pluginContext?.logger?.error?.bind(this.pluginContext.logger) ??
|
|
55
|
+
console.error.bind(console);
|
|
56
|
+
const check = (expr, span) => {
|
|
57
|
+
const inner = this.unwrapExpression(expr);
|
|
58
|
+
if (!inner)
|
|
59
|
+
return;
|
|
60
|
+
switch (inner.type) {
|
|
61
|
+
// The shapes swcExpressionToReactNode serialises faithfully.
|
|
62
|
+
case 'StringLiteral':
|
|
63
|
+
case 'ObjectExpression':
|
|
64
|
+
return;
|
|
65
|
+
case 'TemplateLiteral':
|
|
66
|
+
if (isSimpleTemplateLiteral(inner))
|
|
67
|
+
return;
|
|
68
|
+
break;
|
|
69
|
+
case 'ConditionalExpression':
|
|
70
|
+
check(inner.consequent, span);
|
|
71
|
+
check(inner.alternate, span);
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
const { span: s } = inner; // ponytail: JSXMemberExpression lacks span in the SWC union; real children always have one
|
|
75
|
+
const text = code.slice(s.start, s.end);
|
|
76
|
+
const isIdentifier = inner.type === 'Identifier';
|
|
77
|
+
const produced = isIdentifier ? `"{{${text}}}"` : 'an empty "<1></1>" placeholder';
|
|
78
|
+
const name = inner.type === 'MemberExpression' && inner.property.type === 'Identifier' ? inner.property.value : 'value';
|
|
79
|
+
const suggestion = isIdentifier ? `{{${text}}}` : `{{${name}: ${text}}}`;
|
|
80
|
+
const loc = lineColumnFromOffset(code, span.start);
|
|
81
|
+
const where = loc
|
|
82
|
+
? `${this.getCurrentFile()}:${loc.line}:${loc.column}`
|
|
83
|
+
: this.getCurrentFile();
|
|
84
|
+
emit(`Error: <${elementName}> child {${text}} at ${where} won't match at runtime: react-i18next inlines the value, but extraction produces ${produced}. Use ${suggestion} (double braces) for interpolation.`);
|
|
85
|
+
};
|
|
48
86
|
const visit = (children) => {
|
|
49
87
|
for (const child of children) {
|
|
50
88
|
if (child.type === 'JSXExpressionContainer') {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
bareIdentifiers.push({ name: inner.value, span: child.span });
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
else if (child.type === 'JSXElement') {
|
|
57
|
-
visit(child.children);
|
|
89
|
+
if (child.expression.type !== 'JSXEmptyExpression')
|
|
90
|
+
check(child.expression, child.span);
|
|
58
91
|
}
|
|
59
|
-
else if (child.type === 'JSXFragment') {
|
|
92
|
+
else if (child.type === 'JSXElement' || child.type === 'JSXFragment') {
|
|
60
93
|
visit(child.children);
|
|
61
94
|
}
|
|
62
95
|
}
|
|
63
96
|
};
|
|
64
97
|
visit(node.children);
|
|
65
|
-
if (bareIdentifiers.length === 0)
|
|
66
|
-
return;
|
|
67
|
-
const emit = this.pluginContext?.logger?.error?.bind(this.pluginContext.logger) ??
|
|
68
|
-
console.error.bind(console);
|
|
69
|
-
for (const { name, span } of bareIdentifiers) {
|
|
70
|
-
const loc = lineColumnFromOffset(this.getCurrentCode(), span.start);
|
|
71
|
-
const where = loc
|
|
72
|
-
? `${this.getCurrentFile()}:${loc.line}:${loc.column}`
|
|
73
|
-
: this.getCurrentFile();
|
|
74
|
-
emit(`Error: <${elementName}> child {${name}} at ${where} won't match at runtime — react-i18next inlines the value (e.g. "<1>meow</1>"), but extraction produces "<1>{{${name}}}</1>". Use {{${name}}} (double braces) with values={{ ${name} }} for interpolation.`);
|
|
75
|
-
}
|
|
76
98
|
}
|
|
77
99
|
/**
|
|
78
100
|
* Unwraps TS type-assertion and parenthesis wrappers so we can inspect the
|
|
@@ -101,7 +123,7 @@ class JSXHandler {
|
|
|
101
123
|
handleJSXElement(node, getScopeInfo) {
|
|
102
124
|
const elementName = this.getElementName(node);
|
|
103
125
|
if (elementName && (this.config.extract.transComponents || ['Trans']).includes(elementName)) {
|
|
104
|
-
this.
|
|
126
|
+
this.warnOnUnrepresentableTransChildren(node, elementName);
|
|
105
127
|
let extractedAttributes = null;
|
|
106
128
|
try {
|
|
107
129
|
extractedAttributes = extractFromTransComponent(node, this.config);
|
package/package.json
CHANGED
|
@@ -15,13 +15,19 @@ export declare class JSXHandler {
|
|
|
15
15
|
*/
|
|
16
16
|
private getLocationFromNode;
|
|
17
17
|
/**
|
|
18
|
-
* Emits an error for `<Trans
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
18
|
+
* Emits an error for `<Trans>` children that the serializer cannot turn
|
|
19
|
+
* into the string react-i18next builds at runtime:
|
|
20
|
+
*
|
|
21
|
+
* - `{name}` (a bare identifier): react-i18next inlines the value, but the
|
|
22
|
+
* extractor serialises the identifier name as `{{name}}`.
|
|
23
|
+
* - `{table.name}`, `{fn()}`, `` {`a ${b}`} `` and any other expression
|
|
24
|
+
* (the fallback in `swcExpressionToReactNode`): react-i18next inlines the
|
|
25
|
+
* value, but the extractor emits an empty `<1></1>` placeholder.
|
|
26
|
+
*
|
|
27
|
+
* Either way the extracted key never matches the runtime key. The fix is
|
|
28
|
+
* the `{{name}}` / `{{name: table.name}}` object form, which both sides
|
|
29
|
+
* serialise as `{{name}}`; react-i18next reads the value from that object
|
|
30
|
+
* child, so no `values` prop is needed.
|
|
25
31
|
*
|
|
26
32
|
* We keep the existing extraction behaviour so projects that already rely
|
|
27
33
|
* on the `{{name}}` output (with a matching `values` prop) aren't broken,
|
|
@@ -29,7 +35,7 @@ export declare class JSXHandler {
|
|
|
29
35
|
* Emitted via `logger.error` with an `Error:` prefix so build tooling that
|
|
30
36
|
* watches for errors (see #200) can treat this as fatal if desired.
|
|
31
37
|
*/
|
|
32
|
-
private
|
|
38
|
+
private warnOnUnrepresentableTransChildren;
|
|
33
39
|
/**
|
|
34
40
|
* Unwraps TS type-assertion and parenthesis wrappers so we can inspect the
|
|
35
41
|
* underlying expression type (mirrors behaviour in jsx-parser).
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jsx-handler.d.ts","sourceRoot":"","sources":["../../../src/extractor/parsers/jsx-handler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAc,UAAU,EAAqC,MAAM,WAAW,CAAA;AAC1F,OAAO,KAAK,EAAE,aAAa,EAAE,oBAAoB,EAAgB,MAAM,gBAAgB,CAAA;AACvF,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAA;AAS7D,qBAAa,UAAU;IACrB,OAAO,CAAC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