i18next-cli 1.5.5 → 1.5.6
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 +4 -0
- package/README.md +75 -0
- package/dist/cjs/cli.js +1 -1
- package/dist/cjs/index.js +1 -1
- package/dist/esm/cli.js +1 -1
- package/dist/esm/index.js +1 -1
- package/package.json +1 -1
- package/src/cli.ts +1 -1
- package/src/index.ts +6 -1
- package/types/index.d.ts +4 -1
- package/types/index.d.ts.map +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## [1.5.6](https://github.com/i18next/i18next-cli/compare/v1.5.5...v1.5.6) - 2025-10-03
|
|
9
|
+
|
|
10
|
+
- **Programmatic API:** Exported `runExtractor`, `runLinter`, `runSyncer`, and `runStatus` functions for programmatic usage. You can now use `i18next-cli` directly in your build scripts, Gulp tasks, or any Node.js application without running the CLI commands. [#30](https://github.com/i18next/i18next-cli/issues/30)
|
|
11
|
+
|
|
8
12
|
## [1.5.5](https://github.com/i18next/i18next-cli/compare/v1.5.4...v1.5.5) - 2025-10-03
|
|
9
13
|
|
|
10
14
|
- **Extractor:** Fixed a regression where existing nested translation objects were being replaced with string values when extracted with regular `t()` calls. The extractor now preserves existing nested objects when no explicit default value is provided, ensuring compatibility with global `returnObjects: true` configurations and preventing data loss during extraction. [#29](https://github.com/i18next/i18next-cli/issues/29)
|
package/README.md
CHANGED
|
@@ -669,6 +669,81 @@ const fixedT = getFixedT('en', 'namespace');
|
|
|
669
669
|
fixedT('key');
|
|
670
670
|
```
|
|
671
671
|
|
|
672
|
+
## Programmatic Usage
|
|
673
|
+
|
|
674
|
+
In addition to the CLI commands, `i18next-cli` can be used programmatically in your build scripts, Gulp tasks, or any Node.js application:
|
|
675
|
+
|
|
676
|
+
### Basic Programmatic Usage
|
|
677
|
+
|
|
678
|
+
```typescript
|
|
679
|
+
import { runExtractor, runLinter, runSyncer, runStatus } from 'i18next-cli';
|
|
680
|
+
import type { I18nextToolkitConfig } from 'i18next-cli';
|
|
681
|
+
|
|
682
|
+
const config: I18nextToolkitConfig = {
|
|
683
|
+
locales: ['en', 'de'],
|
|
684
|
+
extract: {
|
|
685
|
+
input: ['src/**/*.{ts,tsx,js,jsx}'],
|
|
686
|
+
output: 'locales/{{language}}/{{namespace}}.json',
|
|
687
|
+
},
|
|
688
|
+
};
|
|
689
|
+
|
|
690
|
+
// Run the complete extraction process
|
|
691
|
+
const wasUpdated = await runExtractor(config);
|
|
692
|
+
console.log('Files updated:', wasUpdated);
|
|
693
|
+
|
|
694
|
+
// Check translation status programmatically
|
|
695
|
+
const statusResults = await runStatus(config);
|
|
696
|
+
|
|
697
|
+
// Run linting
|
|
698
|
+
const lintResults = await runLinter(config);
|
|
699
|
+
|
|
700
|
+
// Sync translation files
|
|
701
|
+
const syncResults = await runSyncer(config);
|
|
702
|
+
```
|
|
703
|
+
|
|
704
|
+
### Build Tool Integration
|
|
705
|
+
|
|
706
|
+
**Gulp Example:**
|
|
707
|
+
|
|
708
|
+
```typescript
|
|
709
|
+
import gulp from 'gulp';
|
|
710
|
+
import { runExtractor } from 'i18next-cli';
|
|
711
|
+
|
|
712
|
+
gulp.task('i18next-extract', async () => {
|
|
713
|
+
const config = {
|
|
714
|
+
locales: ['en', 'de', 'fr'],
|
|
715
|
+
extract: {
|
|
716
|
+
input: ['src/**/*.{ts,tsx,js,jsx}'],
|
|
717
|
+
output: 'public/locales/{{language}}/{{namespace}}.json',
|
|
718
|
+
},
|
|
719
|
+
};
|
|
720
|
+
|
|
721
|
+
await runExtractor(config);
|
|
722
|
+
});
|
|
723
|
+
```
|
|
724
|
+
|
|
725
|
+
**Webpack Plugin Example:**
|
|
726
|
+
|
|
727
|
+
```typescript
|
|
728
|
+
class I18nextExtractionPlugin {
|
|
729
|
+
apply(compiler) {
|
|
730
|
+
compiler.hooks.afterEmit.tapAsync('I18nextExtractionPlugin', async (compilation, callback) => {
|
|
731
|
+
await runExtractor(config);
|
|
732
|
+
callback();
|
|
733
|
+
});
|
|
734
|
+
}
|
|
735
|
+
}
|
|
736
|
+
```
|
|
737
|
+
|
|
738
|
+
### Available Functions
|
|
739
|
+
|
|
740
|
+
- `runExtractor(config, options?)` - Complete extraction with file writing
|
|
741
|
+
- `runLinter(config)` - Run linting analysis
|
|
742
|
+
- `runSyncer(config)` - Sync translation files
|
|
743
|
+
- `runStatus(config, options?)` - Get translation status
|
|
744
|
+
|
|
745
|
+
This programmatic API gives you the same power as the CLI but with full control over when and how it runs in your build process.
|
|
746
|
+
|
|
672
747
|
---
|
|
673
748
|
|
|
674
749
|
<h3 align="center">Gold Sponsors</h3>
|
package/dist/cjs/cli.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
"use strict";var e=require("commander"),t=require("chokidar"),n=require("glob"),o=require("chalk"),i=require("./config.js"),a=require("./heuristic-config.js"),r=require("./extractor/core/extractor.js");require("node:path"),require("node:fs/promises"),require("jiti");var c=require("./types-generator.js"),s=require("./syncer.js"),l=require("./migrator.js"),u=require("./init.js"),d=require("./linter.js"),g=require("./status.js"),p=require("./locize.js");const f=new e.Command;f.name("i18next-cli").description("A unified, high-performance i18next CLI.").version("1.5.
|
|
2
|
+
"use strict";var e=require("commander"),t=require("chokidar"),n=require("glob"),o=require("chalk"),i=require("./config.js"),a=require("./heuristic-config.js"),r=require("./extractor/core/extractor.js");require("node:path"),require("node:fs/promises"),require("jiti");var c=require("./types-generator.js"),s=require("./syncer.js"),l=require("./migrator.js"),u=require("./init.js"),d=require("./linter.js"),g=require("./status.js"),p=require("./locize.js");const f=new e.Command;f.name("i18next-cli").description("A unified, high-performance i18next CLI.").version("1.5.6"),f.command("extract").description("Extract translation keys from source files and update resource files.").option("-w, --watch","Watch for file changes and re-run the extractor.").option("--ci","Exit with a non-zero status code if any files are updated.").option("--dry-run","Run the extractor without writing any files to disk.").action(async e=>{const a=await i.ensureConfig(),c=async()=>{const t=await r.runExtractor(a,{isWatchMode:e.watch,isDryRun:e.dryRun});e.ci&&t&&(console.error(o.red.bold("\n[CI Mode] Error: Translation files were updated. Please commit the changes.")),console.log(o.yellow("💡 Tip: Tired of committing JSON files? locize syncs your team automatically => https://www.locize.com/docs/getting-started")),console.log(` Learn more: ${o.cyan("npx i18next-cli locize-sync")}`),process.exit(1))};if(await c(),e.watch){console.log("\nWatching for changes...");t.watch(await n.glob(a.extract.input),{ignored:/node_modules/,persistent:!0}).on("change",e=>{console.log(`\nFile changed: ${e}`),c()})}}),f.command("status [locale]").description("Display translation status. Provide a locale for a detailed key-by-key view.").option("-n, --namespace <ns>","Filter the status report by a specific namespace").action(async(e,t)=>{let n=await i.loadConfig();if(!n){console.log(o.blue("No config file found. Attempting to detect project structure..."));const e=await a.detectConfig();e||(console.error(o.red("Could not automatically detect your project structure.")),console.log(`Please create a config file first by running: ${o.cyan("npx i18next-cli init")}`),process.exit(1)),console.log(o.green("Project structure detected successfully!")),n=e}await g.runStatus(n,{detail:e,namespace:t.namespace})}),f.command("types").description("Generate TypeScript definitions from translation resource files.").option("-w, --watch","Watch for file changes and re-run the type generator.").action(async e=>{const o=await i.ensureConfig(),a=()=>c.runTypesGenerator(o);if(await a(),e.watch){console.log("\nWatching for changes...");t.watch(await n.glob(o.types?.input||[]),{persistent:!0}).on("change",e=>{console.log(`\nFile changed: ${e}`),a()})}}),f.command("sync").description("Synchronize secondary language files with the primary language file.").action(async()=>{const e=await i.ensureConfig();await s.runSyncer(e)}),f.command("migrate-config").description("Migrate a legacy i18next-parser.config.js to the new format.").action(async()=>{await l.runMigrator()}),f.command("init").description("Create a new i18next.config.ts/js file with an interactive setup wizard.").action(u.runInit),f.command("lint").description("Find potential issues like hardcoded strings in your codebase.").option("-w, --watch","Watch for file changes and re-run the linter.").action(async e=>{const r=async()=>{let e=await i.loadConfig();if(!e){console.log(o.blue("No config file found. Attempting to detect project structure..."));const t=await a.detectConfig();t||(console.error(o.red("Could not automatically detect your project structure.")),console.log(`Please create a config file first by running: ${o.cyan("npx i18next-cli init")}`),process.exit(1)),console.log(o.green("Project structure detected successfully!")),e=t}await d.runLinter(e)};if(await r(),e.watch){console.log("\nWatching for changes...");const e=await i.loadConfig();if(e?.extract?.input){t.watch(await n.glob(e.extract.input),{ignored:/node_modules/,persistent:!0}).on("change",e=>{console.log(`\nFile changed: ${e}`),r()})}}}),f.command("locize-sync").description("Synchronize local translations with your locize project.").option("--update-values","Update values of existing translations on locize.").option("--src-lng-only","Check for changes in source language only.").option("--compare-mtime","Compare modification times when syncing.").option("--dry-run","Run the command without making any changes.").action(async e=>{const t=await i.ensureConfig();await p.runLocizeSync(t,e)}),f.command("locize-download").description("Download all translations from your locize project.").action(async e=>{const t=await i.ensureConfig();await p.runLocizeDownload(t,e)}),f.command("locize-migrate").description("Migrate local translation files to a new locize project.").action(async e=>{const t=await i.ensureConfig();await p.runLocizeMigrate(t,e)}),f.parse(process.argv);
|
package/dist/cjs/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var r=require("./config.js"),e=require("./extractor/core/extractor.js"),t=require("./extractor/core/key-finder.js"),n=require("./extractor/core/translation-manager.js"),s=require("./linter.js"),o=require("./syncer.js"),i=require("./status.js");exports.defineConfig=r.defineConfig,exports.extract=e.extract,exports.runExtractor=e.runExtractor,exports.findKeys=t.findKeys,exports.getTranslations=n.getTranslations,exports.runLinter=s.runLinter,exports.runSyncer=o.runSyncer,exports.runStatus=i.runStatus;
|
package/dist/esm/cli.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{Command as t}from"commander";import o from"chokidar";import{glob as e}from"glob";import n from"chalk";import{ensureConfig as i,loadConfig as a}from"./config.js";import{detectConfig as c}from"./heuristic-config.js";import{runExtractor as r}from"./extractor/core/extractor.js";import"node:path";import"node:fs/promises";import"jiti";import{runTypesGenerator as s}from"./types-generator.js";import{runSyncer as l}from"./syncer.js";import{runMigrator as m}from"./migrator.js";import{runInit as p}from"./init.js";import{runLinter as d}from"./linter.js";import{runStatus as g}from"./status.js";import{runLocizeSync as f,runLocizeDownload as u,runLocizeMigrate as h}from"./locize.js";const w=new t;w.name("i18next-cli").description("A unified, high-performance i18next CLI.").version("1.5.
|
|
2
|
+
import{Command as t}from"commander";import o from"chokidar";import{glob as e}from"glob";import n from"chalk";import{ensureConfig as i,loadConfig as a}from"./config.js";import{detectConfig as c}from"./heuristic-config.js";import{runExtractor as r}from"./extractor/core/extractor.js";import"node:path";import"node:fs/promises";import"jiti";import{runTypesGenerator as s}from"./types-generator.js";import{runSyncer as l}from"./syncer.js";import{runMigrator as m}from"./migrator.js";import{runInit as p}from"./init.js";import{runLinter as d}from"./linter.js";import{runStatus as g}from"./status.js";import{runLocizeSync as f,runLocizeDownload as u,runLocizeMigrate as h}from"./locize.js";const w=new t;w.name("i18next-cli").description("A unified, high-performance i18next CLI.").version("1.5.6"),w.command("extract").description("Extract translation keys from source files and update resource files.").option("-w, --watch","Watch for file changes and re-run the extractor.").option("--ci","Exit with a non-zero status code if any files are updated.").option("--dry-run","Run the extractor without writing any files to disk.").action(async t=>{const a=await i(),c=async()=>{const o=await r(a,{isWatchMode:t.watch,isDryRun:t.dryRun});t.ci&&o&&(console.error(n.red.bold("\n[CI Mode] Error: Translation files were updated. Please commit the changes.")),console.log(n.yellow("💡 Tip: Tired of committing JSON files? locize syncs your team automatically => https://www.locize.com/docs/getting-started")),console.log(` Learn more: ${n.cyan("npx i18next-cli locize-sync")}`),process.exit(1))};if(await c(),t.watch){console.log("\nWatching for changes...");o.watch(await e(a.extract.input),{ignored:/node_modules/,persistent:!0}).on("change",t=>{console.log(`\nFile changed: ${t}`),c()})}}),w.command("status [locale]").description("Display translation status. Provide a locale for a detailed key-by-key view.").option("-n, --namespace <ns>","Filter the status report by a specific namespace").action(async(t,o)=>{let e=await a();if(!e){console.log(n.blue("No config file found. Attempting to detect project structure..."));const t=await c();t||(console.error(n.red("Could not automatically detect your project structure.")),console.log(`Please create a config file first by running: ${n.cyan("npx i18next-cli init")}`),process.exit(1)),console.log(n.green("Project structure detected successfully!")),e=t}await g(e,{detail:t,namespace:o.namespace})}),w.command("types").description("Generate TypeScript definitions from translation resource files.").option("-w, --watch","Watch for file changes and re-run the type generator.").action(async t=>{const n=await i(),a=()=>s(n);if(await a(),t.watch){console.log("\nWatching for changes...");o.watch(await e(n.types?.input||[]),{persistent:!0}).on("change",t=>{console.log(`\nFile changed: ${t}`),a()})}}),w.command("sync").description("Synchronize secondary language files with the primary language file.").action(async()=>{const t=await i();await l(t)}),w.command("migrate-config").description("Migrate a legacy i18next-parser.config.js to the new format.").action(async()=>{await m()}),w.command("init").description("Create a new i18next.config.ts/js file with an interactive setup wizard.").action(p),w.command("lint").description("Find potential issues like hardcoded strings in your codebase.").option("-w, --watch","Watch for file changes and re-run the linter.").action(async t=>{const i=async()=>{let t=await a();if(!t){console.log(n.blue("No config file found. Attempting to detect project structure..."));const o=await c();o||(console.error(n.red("Could not automatically detect your project structure.")),console.log(`Please create a config file first by running: ${n.cyan("npx i18next-cli init")}`),process.exit(1)),console.log(n.green("Project structure detected successfully!")),t=o}await d(t)};if(await i(),t.watch){console.log("\nWatching for changes...");const t=await a();if(t?.extract?.input){o.watch(await e(t.extract.input),{ignored:/node_modules/,persistent:!0}).on("change",t=>{console.log(`\nFile changed: ${t}`),i()})}}}),w.command("locize-sync").description("Synchronize local translations with your locize project.").option("--update-values","Update values of existing translations on locize.").option("--src-lng-only","Check for changes in source language only.").option("--compare-mtime","Compare modification times when syncing.").option("--dry-run","Run the command without making any changes.").action(async t=>{const o=await i();await f(o,t)}),w.command("locize-download").description("Download all translations from your locize project.").action(async t=>{const o=await i();await u(o,t)}),w.command("locize-migrate").description("Migrate local translation files to a new locize project.").action(async t=>{const o=await i();await h(o,t)}),w.parse(process.argv);
|
package/dist/esm/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export{defineConfig}from"./config.js";export{extract}from"./extractor/core/extractor.js";export{findKeys}from"./extractor/core/key-finder.js";export{getTranslations}from"./extractor/core/translation-manager.js";
|
|
1
|
+
export{defineConfig}from"./config.js";export{extract,runExtractor}from"./extractor/core/extractor.js";export{findKeys}from"./extractor/core/key-finder.js";export{getTranslations}from"./extractor/core/translation-manager.js";export{runLinter}from"./linter.js";export{runSyncer}from"./syncer.js";export{runStatus}from"./status.js";
|
package/package.json
CHANGED
package/src/cli.ts
CHANGED
package/src/index.ts
CHANGED
|
@@ -8,5 +8,10 @@ export { defineConfig } from './config'
|
|
|
8
8
|
export {
|
|
9
9
|
extract,
|
|
10
10
|
findKeys,
|
|
11
|
-
getTranslations
|
|
11
|
+
getTranslations,
|
|
12
|
+
runExtractor
|
|
12
13
|
} from './extractor'
|
|
14
|
+
|
|
15
|
+
export { runLinter } from './linter'
|
|
16
|
+
export { runSyncer } from './syncer'
|
|
17
|
+
export { runStatus } from './status'
|
package/types/index.d.ts
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
export type { I18nextToolkitConfig, Plugin, PluginContext, ExtractedKey } from './types';
|
|
2
2
|
export { defineConfig } from './config';
|
|
3
|
-
export { extract, findKeys, getTranslations } from './extractor';
|
|
3
|
+
export { extract, findKeys, getTranslations, runExtractor } from './extractor';
|
|
4
|
+
export { runLinter } from './linter';
|
|
5
|
+
export { runSyncer } from './syncer';
|
|
6
|
+
export { runStatus } from './status';
|
|
4
7
|
//# sourceMappingURL=index.d.ts.map
|
package/types/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,oBAAoB,EACpB,MAAM,EACN,aAAa,EACb,YAAY,EACb,MAAM,SAAS,CAAA;AAChB,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAA;AACvC,OAAO,EACL,OAAO,EACP,QAAQ,EACR,eAAe,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,oBAAoB,EACpB,MAAM,EACN,aAAa,EACb,YAAY,EACb,MAAM,SAAS,CAAA;AAChB,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAA;AACvC,OAAO,EACL,OAAO,EACP,QAAQ,EACR,eAAe,EACf,YAAY,EACb,MAAM,aAAa,CAAA;AAEpB,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAA;AACpC,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAA;AACpC,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAA"}
|