i18next-cli 1.66.0 → 1.66.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/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.0'); // This string is replaced with the actual version at build time by rollup
40
+ .version('1.66.1'); // 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
@@ -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) { console.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) { console.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.0'); // This string is replaced with the actual version at build time by rollup
34
+ .version('1.66.1'); // 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
@@ -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) { console.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) { console.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,6 +1,6 @@
1
1
  {
2
2
  "name": "i18next-cli",
3
- "version": "1.66.0",
3
+ "version": "1.66.1",
4
4
  "description": "A unified, high-performance i18next CLI.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -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: string): void;
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;;;;OAIG;IACH,IAAI,CAAE,OAAO,EAAE,MAAM,GAAG,IAAI;IAE5B;;;;OAIG;IACH,KAAK,CAAE,OAAO,EAAE,MAAM,GAAG,IAAI;CAC9B"}
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"}