i18next-cli 1.66.0 → 1.66.2
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/README.md +37 -0
- package/dist/cjs/cli.js +1 -1
- package/dist/cjs/extractor/parsers/jsx-parser.js +2 -0
- package/dist/cjs/utils/logger.js +19 -2
- package/dist/esm/cli.js +1 -1
- package/dist/esm/extractor/parsers/jsx-parser.js +2 -0
- package/dist/esm/utils/logger.js +19 -2
- package/package.json +1 -1
- package/types/extractor/parsers/jsx-parser.d.ts.map +1 -1
- package/types/utils/logger.d.ts +5 -2
- package/types/utils/logger.d.ts.map +1 -1
package/README.md
CHANGED
|
@@ -1433,6 +1433,43 @@ button:
|
|
|
1433
1433
|
|
|
1434
1434
|
> **💡 Note:** Both `.yaml` and `.yml` extensions are supported and preserved. The `outputFormat: 'yaml'` option is optional when using these extensions - the format is automatically inferred from the file extension.
|
|
1435
1435
|
|
|
1436
|
+
### Code-Splitting Translations (one namespace per route)
|
|
1437
|
+
|
|
1438
|
+
A common concern with runtime i18n is "you ship every language and every namespace to the client". You don't have to: the i18next runtime loads translations **per namespace, per language**, so namespace granularity is your code-splitting boundary. The runtime core itself is ~13.5 kB gzipped; what grows with your app is translation payload, and that is entirely controlled by how you slice namespaces.
|
|
1439
|
+
|
|
1440
|
+
The recipe:
|
|
1441
|
+
|
|
1442
|
+
1. **One namespace per route/feature** — scope keys via `useTranslation('checkout')`, `t('checkout:title')`, or the `ns` option. The extractor detects the namespace from your code and writes one file per namespace and language:
|
|
1443
|
+
|
|
1444
|
+
```typescript
|
|
1445
|
+
export default defineConfig({
|
|
1446
|
+
locales: ['en', 'de'],
|
|
1447
|
+
extract: {
|
|
1448
|
+
input: 'src/**/*.{ts,tsx}',
|
|
1449
|
+
output: 'src/locales/{{language}}/{{namespace}}.json',
|
|
1450
|
+
}
|
|
1451
|
+
});
|
|
1452
|
+
```
|
|
1453
|
+
|
|
1454
|
+
2. **Lazy-load namespaces with dynamic imports** — each namespace + language pair becomes its own chunk that the bundler code-splits automatically:
|
|
1455
|
+
|
|
1456
|
+
```javascript
|
|
1457
|
+
import i18next from 'i18next';
|
|
1458
|
+
import resourcesToBackend from 'i18next-resources-to-backend';
|
|
1459
|
+
|
|
1460
|
+
i18next
|
|
1461
|
+
.use(resourcesToBackend((lng, ns) => import(`./locales/${lng}/${ns}.json`)))
|
|
1462
|
+
.init({
|
|
1463
|
+
fallbackLng: 'en',
|
|
1464
|
+
defaultNS: 'app',
|
|
1465
|
+
ns: ['app'], // only the app-shell namespace loads upfront
|
|
1466
|
+
});
|
|
1467
|
+
```
|
|
1468
|
+
|
|
1469
|
+
3. **Load on demand** — `useTranslation('checkout')` (react-i18next) or `i18next.loadNamespaces('checkout')` fetches exactly that chunk when the route renders. The initial payload contains only the namespaces the entry route uses, in the active language; other languages transfer nothing until switched to.
|
|
1470
|
+
|
|
1471
|
+
Prefer not to bundle translations at all? Serve the same per-namespace files from any static host/CDN via [`i18next-http-backend`](https://github.com/i18next/i18next-http-backend), or directly from the Locize CDN via [`i18next-locize-backend`](https://github.com/locize/i18next-locize-backend) — same wire profile, plus translation updates without redeploying.
|
|
1472
|
+
|
|
1436
1473
|
### Merging Namespaces
|
|
1437
1474
|
|
|
1438
1475
|
You can also combine all namespaces into a single file per language. This is useful for reducing the number of network requests in some application setups.
|
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.66.
|
|
40
|
+
.version('1.66.2'); // This string is replaced with the actual version at build time by rollup
|
|
41
41
|
// new: global config override option
|
|
42
42
|
program.option('-c, --config <path>', 'Path to i18next-cli config file (overrides detection)');
|
|
43
43
|
program
|
|
@@ -266,6 +266,8 @@ function extractFromTransComponent(node, config) {
|
|
|
266
266
|
if (!keyExpression)
|
|
267
267
|
return null;
|
|
268
268
|
}
|
|
269
|
+
if (!keyExpression && !serialized.trim())
|
|
270
|
+
return null;
|
|
269
271
|
// If no explicit defaults provided and we have a processed key, use it as default value
|
|
270
272
|
// This matches the behavior of other similar tests in the codebase
|
|
271
273
|
if (!defaultsAttr && processedKeyValue && !serialized.trim()) {
|
package/dist/cjs/utils/logger.js
CHANGED
|
@@ -23,14 +23,31 @@ class ConsoleLogger {
|
|
|
23
23
|
* Logs a warning message to the console.
|
|
24
24
|
*
|
|
25
25
|
* @param message - The warning message to log
|
|
26
|
+
* @param more - Optional additional detail (e.g. a caught error). Forwarded to
|
|
27
|
+
* `console.warn` so thrown errors surfaced by plugin hooks are not swallowed.
|
|
26
28
|
*/
|
|
27
|
-
warn(message) {
|
|
29
|
+
warn(message, more) {
|
|
30
|
+
if (more === undefined) {
|
|
31
|
+
console.warn(message);
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
console.warn(message, more);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
28
37
|
/**
|
|
29
38
|
* Logs an error message to the console.
|
|
30
39
|
*
|
|
31
40
|
* @param message - The error message to log
|
|
41
|
+
* @param more - Optional additional detail (e.g. a caught error).
|
|
32
42
|
*/
|
|
33
|
-
error(message) {
|
|
43
|
+
error(message, more) {
|
|
44
|
+
if (more === undefined) {
|
|
45
|
+
console.error(message);
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
console.error(message, more);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
34
51
|
}
|
|
35
52
|
|
|
36
53
|
exports.ConsoleLogger = ConsoleLogger;
|
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.66.
|
|
34
|
+
.version('1.66.2'); // This string is replaced with the actual version at build time by rollup
|
|
35
35
|
// new: global config override option
|
|
36
36
|
program.option('-c, --config <path>', 'Path to i18next-cli config file (overrides detection)');
|
|
37
37
|
program
|
|
@@ -263,6 +263,8 @@ function extractFromTransComponent(node, config) {
|
|
|
263
263
|
if (!keyExpression)
|
|
264
264
|
return null;
|
|
265
265
|
}
|
|
266
|
+
if (!keyExpression && !serialized.trim())
|
|
267
|
+
return null;
|
|
266
268
|
// If no explicit defaults provided and we have a processed key, use it as default value
|
|
267
269
|
// This matches the behavior of other similar tests in the codebase
|
|
268
270
|
if (!defaultsAttr && processedKeyValue && !serialized.trim()) {
|
package/dist/esm/utils/logger.js
CHANGED
|
@@ -21,14 +21,31 @@ class ConsoleLogger {
|
|
|
21
21
|
* Logs a warning message to the console.
|
|
22
22
|
*
|
|
23
23
|
* @param message - The warning message to log
|
|
24
|
+
* @param more - Optional additional detail (e.g. a caught error). Forwarded to
|
|
25
|
+
* `console.warn` so thrown errors surfaced by plugin hooks are not swallowed.
|
|
24
26
|
*/
|
|
25
|
-
warn(message) {
|
|
27
|
+
warn(message, more) {
|
|
28
|
+
if (more === undefined) {
|
|
29
|
+
console.warn(message);
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
console.warn(message, more);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
26
35
|
/**
|
|
27
36
|
* Logs an error message to the console.
|
|
28
37
|
*
|
|
29
38
|
* @param message - The error message to log
|
|
39
|
+
* @param more - Optional additional detail (e.g. a caught error).
|
|
30
40
|
*/
|
|
31
|
-
error(message) {
|
|
41
|
+
error(message, more) {
|
|
42
|
+
if (more === undefined) {
|
|
43
|
+
console.error(message);
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
console.error(message, more);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
32
49
|
}
|
|
33
50
|
|
|
34
51
|
export { ConsoleLogger };
|
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jsx-parser.d.ts","sourceRoot":"","sources":["../../../src/extractor/parsers/jsx-parser.ts"],"names":[],"mappings":"AAAA,OAAO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AAE,CAAC,EAAE,MAAM,CAAC;IAEZ,oEAAoE;IACpE,QAAQ,CAAC,EAAE,OAAO,CAAC;IAEnB,0DAA0D;IAC1D,SAAS,CAAC,EAAE,OAAO,CAAC;IAEpB,8EAA8E;IAC9E,WAAW,CAAC,EAAE,gBAAgB,CAAC;IAE/B,mDAAmD;IACnD,iBAAiB,CAAC,EAAE,UAAU,CAAC;IAE/B,kHAAkH;IAClH,eAAe,CAAC,EAAE,OAAO,CAAC;CAC3B;AA4BD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,wBAAgB,yBAAyB,CAAE,IAAI,EAAE,UAAU,EAAE,MAAM,EAAE,oBAAoB,GAAG,sBAAsB,GAAG,IAAI,CAoMxH"}
|
package/types/utils/logger.d.ts
CHANGED
|
@@ -22,13 +22,16 @@ export declare class ConsoleLogger implements Logger {
|
|
|
22
22
|
* Logs a warning message to the console.
|
|
23
23
|
*
|
|
24
24
|
* @param message - The warning message to log
|
|
25
|
+
* @param more - Optional additional detail (e.g. a caught error). Forwarded to
|
|
26
|
+
* `console.warn` so thrown errors surfaced by plugin hooks are not swallowed.
|
|
25
27
|
*/
|
|
26
|
-
warn(message: string): void;
|
|
28
|
+
warn(message: string, more?: unknown): void;
|
|
27
29
|
/**
|
|
28
30
|
* Logs an error message to the console.
|
|
29
31
|
*
|
|
30
32
|
* @param message - The error message to log
|
|
33
|
+
* @param more - Optional additional detail (e.g. a caught error).
|
|
31
34
|
*/
|
|
32
|
-
error(message:
|
|
35
|
+
error(message: unknown, more?: unknown): void;
|
|
33
36
|
}
|
|
34
37
|
//# sourceMappingURL=logger.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../src/utils/logger.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AAEzC;;;;;;;;;;;GAWG;AACH,qBAAa,aAAc,YAAW,MAAM;IAC1C;;;;OAIG;IACH,IAAI,CAAE,OAAO,EAAE,MAAM,GAAG,IAAI;IAE5B
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../src/utils/logger.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AAEzC;;;;;;;;;;;GAWG;AACH,qBAAa,aAAc,YAAW,MAAM;IAC1C;;;;OAIG;IACH,IAAI,CAAE,OAAO,EAAE,MAAM,GAAG,IAAI;IAE5B;;;;;;OAMG;IACH,IAAI,CAAE,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,GAAG,IAAI;IAI5C;;;;;OAKG;IACH,KAAK,CAAE,OAAO,EAAE,OAAO,EAAE,IAAI,CAAC,EAAE,OAAO,GAAG,IAAI;CAG/C"}
|