i18next-cli 1.5.5 → 1.5.7
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 +13 -0
- package/README.md +82 -0
- package/dist/cjs/cli.js +1 -1
- package/dist/cjs/config.js +1 -1
- package/dist/cjs/index.js +1 -1
- package/dist/cjs/migrator.js +1 -1
- package/dist/esm/cli.js +1 -1
- package/dist/esm/config.js +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/migrator.js +1 -1
- package/package.json +1 -1
- package/src/cli.ts +4 -4
- package/src/config.ts +1 -1
- package/src/index.ts +7 -1
- package/src/migrator.ts +112 -48
- package/types/config.d.ts +5 -0
- package/types/config.d.ts.map +1 -1
- package/types/index.d.ts +5 -1
- package/types/index.d.ts.map +1 -1
- package/types/migrator.d.ts +14 -19
- package/types/migrator.d.ts.map +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,19 @@ 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.7](https://github.com/i18next/i18next-cli/compare/v1.5.6...v1.5.7) - 2025-10-04
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
- **Migration:** Added support for custom config file paths in the `migrate-config` command. You can now use a positional argument to specify non-standard config file locations (e.g., `i18next-cli migrate-config my-config.mjs`). [#31](https://github.com/i18next/i18next-cli/issues/31)
|
|
12
|
+
- **Programmatic API:** Exported `runTypesGenerator` function for programmatic usage for build tool integration.
|
|
13
|
+
|
|
14
|
+
### Enhanced
|
|
15
|
+
- **Migration:** Added warning for deprecated `compatibilityJSON: 'v3'` option in legacy configs.
|
|
16
|
+
|
|
17
|
+
## [1.5.6](https://github.com/i18next/i18next-cli/compare/v1.5.5...v1.5.6) - 2025-10-03
|
|
18
|
+
|
|
19
|
+
- **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)
|
|
20
|
+
|
|
8
21
|
## [1.5.5](https://github.com/i18next/i18next-cli/compare/v1.5.4...v1.5.5) - 2025-10-03
|
|
9
22
|
|
|
10
23
|
- **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
|
@@ -201,6 +201,9 @@ Automatically migrates a legacy `i18next-parser.config.js` file to the new `i18n
|
|
|
201
201
|
|
|
202
202
|
```bash
|
|
203
203
|
npx i18next-cli migrate-config
|
|
204
|
+
|
|
205
|
+
# Using custom path for old config
|
|
206
|
+
npx i18next-cli migrate-config i18next-parser.config.mjs
|
|
204
207
|
```
|
|
205
208
|
|
|
206
209
|
### Locize Integration
|
|
@@ -669,6 +672,85 @@ const fixedT = getFixedT('en', 'namespace');
|
|
|
669
672
|
fixedT('key');
|
|
670
673
|
```
|
|
671
674
|
|
|
675
|
+
## Programmatic Usage
|
|
676
|
+
|
|
677
|
+
In addition to the CLI commands, `i18next-cli` can be used programmatically in your build scripts, Gulp tasks, or any Node.js application:
|
|
678
|
+
|
|
679
|
+
### Basic Programmatic Usage
|
|
680
|
+
|
|
681
|
+
```typescript
|
|
682
|
+
import { runExtractor, runLinter, runSyncer, runStatus, runTypesGenerator } from 'i18next-cli';
|
|
683
|
+
import type { I18nextToolkitConfig } from 'i18next-cli';
|
|
684
|
+
|
|
685
|
+
const config: I18nextToolkitConfig = {
|
|
686
|
+
locales: ['en', 'de'],
|
|
687
|
+
extract: {
|
|
688
|
+
input: ['src/**/*.{ts,tsx,js,jsx}'],
|
|
689
|
+
output: 'locales/{{language}}/{{namespace}}.json',
|
|
690
|
+
},
|
|
691
|
+
};
|
|
692
|
+
|
|
693
|
+
// Run the complete extraction process
|
|
694
|
+
const wasUpdated = await runExtractor(config);
|
|
695
|
+
console.log('Files updated:', wasUpdated);
|
|
696
|
+
|
|
697
|
+
// Check translation status programmatically
|
|
698
|
+
await runStatus(config);
|
|
699
|
+
|
|
700
|
+
// Run linting
|
|
701
|
+
await runLinter(config);
|
|
702
|
+
|
|
703
|
+
// Sync translation files
|
|
704
|
+
await runSyncer(config);
|
|
705
|
+
|
|
706
|
+
// types generattion
|
|
707
|
+
await runTypesGenerator(config);
|
|
708
|
+
```
|
|
709
|
+
|
|
710
|
+
### Build Tool Integration
|
|
711
|
+
|
|
712
|
+
**Gulp Example:**
|
|
713
|
+
|
|
714
|
+
```typescript
|
|
715
|
+
import gulp from 'gulp';
|
|
716
|
+
import { runExtractor } from 'i18next-cli';
|
|
717
|
+
|
|
718
|
+
gulp.task('i18next-extract', async () => {
|
|
719
|
+
const config = {
|
|
720
|
+
locales: ['en', 'de', 'fr'],
|
|
721
|
+
extract: {
|
|
722
|
+
input: ['src/**/*.{ts,tsx,js,jsx}'],
|
|
723
|
+
output: 'public/locales/{{language}}/{{namespace}}.json',
|
|
724
|
+
},
|
|
725
|
+
};
|
|
726
|
+
|
|
727
|
+
await runExtractor(config);
|
|
728
|
+
});
|
|
729
|
+
```
|
|
730
|
+
|
|
731
|
+
**Webpack Plugin Example:**
|
|
732
|
+
|
|
733
|
+
```typescript
|
|
734
|
+
class I18nextExtractionPlugin {
|
|
735
|
+
apply(compiler) {
|
|
736
|
+
compiler.hooks.afterEmit.tapAsync('I18nextExtractionPlugin', async (compilation, callback) => {
|
|
737
|
+
await runExtractor(config);
|
|
738
|
+
callback();
|
|
739
|
+
});
|
|
740
|
+
}
|
|
741
|
+
}
|
|
742
|
+
```
|
|
743
|
+
|
|
744
|
+
### Available Functions
|
|
745
|
+
|
|
746
|
+
- `runExtractor(config, options?)` - Complete extraction with file writing
|
|
747
|
+
- `runLinter(config)` - Run linting analysis
|
|
748
|
+
- `runSyncer(config)` - Sync translation files
|
|
749
|
+
- `runStatus(config, options?)` - Get translation status
|
|
750
|
+
- `runTypesGenerator(config)` - Generate types
|
|
751
|
+
|
|
752
|
+
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.
|
|
753
|
+
|
|
672
754
|
---
|
|
673
755
|
|
|
674
756
|
<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.7"),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 [configPath]").description("Migrate a legacy i18next-parser.config.js to the new format.").action(async e=>{await l.runMigrator(e)}),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/config.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var e=require("node:path"),r=require("node:url"),t=require("node:fs/promises"),n=require("jiti"),o=require("jsonc-parser"),i=require("inquirer"),a=require("chalk"),
|
|
1
|
+
"use strict";var e=require("node:path"),r=require("node:url"),t=require("node:fs/promises"),n=require("jiti"),o=require("jsonc-parser"),i=require("inquirer"),a=require("chalk"),s=require("./init.js"),c=require("./utils/logger.js");const u=["i18next.config.ts","i18next.config.js","i18next.config.mjs","i18next.config.cjs"];async function l(o=new c.ConsoleLogger){const i=await async function(){for(const r of u){const n=e.resolve(process.cwd(),r);try{return await t.access(n),n}catch{}}return null}();if(!i)return null;try{let e;if(i.endsWith(".ts")){const r=await f(),t=n.createJiti(process.cwd(),{alias:r,interopDefault:!1}),o=await t.import(i,{default:!0});e=o}else{const t=r.pathToFileURL(i).href,n=await import(`${t}?t=${Date.now()}`);e=n.default}return e?(e.extract||={},e.extract.primaryLanguage||=e.locales[0]||"en",e.extract.secondaryLanguages||=e.locales.filter(r=>r!==e.extract.primaryLanguage),e):(o.error(`Error: No default export found in ${i}`),null)}catch(e){return o.error(`Error loading configuration from ${i}`),o.error(e),null}}async function f(){try{const r=await async function(){let r=process.cwd();for(;;){const n=e.join(r,"tsconfig.json");try{return await t.access(n),n}catch{const t=e.dirname(r);if(t===r)return null;r=t}}}();if(!r)return{};const n=await t.readFile(r,"utf-8"),i=o.parse(n),a=i.compilerOptions?.paths,s=i.compilerOptions?.baseUrl||".";if(!a)return{};const c={};for(const[r,t]of Object.entries(a))if(Array.isArray(t)&&t.length>0){const n=r.replace("/*",""),o=e.resolve(process.cwd(),s,t[0].replace("/*",""));c[n]=o}return c}catch(e){return{}}}exports.defineConfig=function(e){return e},exports.ensureConfig=async function(e=new c.ConsoleLogger){let r=await l();if(r)return r;const{shouldInit:t}=await i.prompt([{type:"confirm",name:"shouldInit",message:a.yellow("Configuration file not found. Would you like to create one now?"),default:!0}]);if(t){if(await s.runInit(),e.info(a.green("Configuration created. Resuming command...")),r=await l(),r)return r;e.error(a.red("Error: Failed to load configuration after creation. Please try running the command again.")),process.exit(1)}else e.info("Operation cancelled. Please create a configuration file to proceed."),process.exit(0)},exports.getTsConfigAliases=f,exports.loadConfig=l;
|
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"),a=require("./status.js"),i=require("./types-generator.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=a.runStatus,exports.runTypesGenerator=i.runTypesGenerator;
|
package/dist/cjs/migrator.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var e=require("node:path"),t=require("node:fs/promises"),n=require("node:url")
|
|
1
|
+
"use strict";var e=require("node:path"),t=require("node:fs/promises"),n=require("node:url"),o=require("jiti"),s=require("./config.js");const r=e.resolve(process.cwd(),"i18next.config.ts"),i=["i18next.config.ts","i18next.config.js","i18next.config.mjs","i18next.config.cjs"],a=[".js",".mjs",".cjs",".ts"];async function c(e){if(a.some(t=>e.endsWith(t)))try{return await t.access(e),e}catch{return null}for(const n of a){const o=`${e}${n}`;try{return await t.access(o),o}catch{}}return null}exports.runMigrator=async function(a){let l;if(a){if(l=await c(e.resolve(process.cwd(),a)),!l)return console.log(`No legacy config file found at or near: ${a}`),void console.log("Tried extensions: .js, .mjs, .cjs, .ts")}else if(l=await c(e.resolve(process.cwd(),"i18next-parser.config")),!l)return console.log("No i18next-parser.config.* found. Nothing to migrate."),void console.log("Tried: i18next-parser.config.js, .mjs, .cjs, .ts");console.log(`Attempting to migrate legacy config from: ${l}...`);for(const n of i)try{const o=e.resolve(process.cwd(),n);return await t.access(o),void console.warn(`Warning: A new configuration file already exists at "${n}". Migration skipped to avoid overwriting.`)}catch(e){}const f=await async function(e){try{let t;if(e.endsWith(".ts")){const n=await s.getTsConfigAliases(),r=o.createJiti(process.cwd(),{alias:n,interopDefault:!1});t=await r.import(e,{default:!0})}else{const o=n.pathToFileURL(e).href;t=(await import(`${o}?t=${Date.now()}`)).default}return t}catch(t){return console.error(`Error loading legacy config from ${e}:`,t),null}}(l);if(!f)return void console.error("Could not read the legacy config file.");const u={locales:f.locales||["en"],extract:{input:f.input||"src/**/*.{js,jsx,ts,tsx}",output:(f.output||"locales/$LOCALE/$NAMESPACE.json").replace("$LOCALE","{{language}}").replace("$NAMESPACE","{{namespace}}"),defaultNS:f.defaultNamespace||"translation",keySeparator:f.keySeparator,nsSeparator:f.namespaceSeparator,contextSeparator:f.contextSeparator,functions:f.lexers?.js?.functions||["t","*.t"],transComponents:f.lexers?.js?.components||["Trans"]},types:{input:["locales/{{language}}/{{namespace}}.json"],output:"src/types/i18next.d.ts"}};u.extract.functions.includes("t")&&!u.extract.functions.includes("*.t")&&u.extract.functions.push("*.t");const p=`\nimport { defineConfig } from 'i18next-cli';\n\nexport default defineConfig(${JSON.stringify(u,null,2)});\n`;await t.writeFile(r,p.trim()),console.log("✅ Success! Migration complete."),console.log(`New configuration file created at: ${r}`),console.warn('\nPlease review the generated file and adjust paths for "types.input" if necessary.'),f.keepRemoved&&console.warn('Warning: The "keepRemoved" option is deprecated. Consider using the "preservePatterns" feature for dynamic keys.'),"v3"===f.i18nextOptions?.compatibilityJSON&&console.warn('Warning: compatibilityJSON "v3" is not supported in i18next-cli. Only i18next v4 format is supported.')};
|
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.7"),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 [configPath]").description("Migrate a legacy i18next-parser.config.js to the new format.").action(async t=>{await m(t)}),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/config.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{resolve as r,join as t,dirname as o}from"node:path";import{pathToFileURL as n}from"node:url";import{access as e,readFile as i}from"node:fs/promises";import{createJiti as a}from"jiti";import{parse as c}from"jsonc-parser";import s from"inquirer";import f from"chalk";import{runInit as l}from"./init.js";import{ConsoleLogger as u}from"./utils/logger.js";const p=["i18next.config.ts","i18next.config.js","i18next.config.mjs","i18next.config.cjs"];function m(r){return r}async function d(
|
|
1
|
+
import{resolve as r,join as t,dirname as o}from"node:path";import{pathToFileURL as n}from"node:url";import{access as e,readFile as i}from"node:fs/promises";import{createJiti as a}from"jiti";import{parse as c}from"jsonc-parser";import s from"inquirer";import f from"chalk";import{runInit as l}from"./init.js";import{ConsoleLogger as u}from"./utils/logger.js";const p=["i18next.config.ts","i18next.config.js","i18next.config.mjs","i18next.config.cjs"];function m(r){return r}async function d(t=new u){const o=await async function(){for(const t of p){const o=r(process.cwd(),t);try{return await e(o),o}catch{}}return null}();if(!o)return null;try{let r;if(o.endsWith(".ts")){const t=await w(),n=a(process.cwd(),{alias:t,interopDefault:!1}),e=await n.import(o,{default:!0});r=e}else{const t=n(o).href,e=await import(`${t}?t=${Date.now()}`);r=e.default}return r?(r.extract||={},r.extract.primaryLanguage||=r.locales[0]||"en",r.extract.secondaryLanguages||=r.locales.filter(t=>t!==r.extract.primaryLanguage),r):(t.error(`Error: No default export found in ${o}`),null)}catch(r){return t.error(`Error loading configuration from ${o}`),t.error(r),null}}async function g(r=new u){let t=await d();if(t)return t;const{shouldInit:o}=await s.prompt([{type:"confirm",name:"shouldInit",message:f.yellow("Configuration file not found. Would you like to create one now?"),default:!0}]);if(o){if(await l(),r.info(f.green("Configuration created. Resuming command...")),t=await d(),t)return t;r.error(f.red("Error: Failed to load configuration after creation. Please try running the command again.")),process.exit(1)}else r.info("Operation cancelled. Please create a configuration file to proceed."),process.exit(0)}async function w(){try{const n=await async function(){let r=process.cwd();for(;;){const n=t(r,"tsconfig.json");try{return await e(n),n}catch{const t=o(r);if(t===r)return null;r=t}}}();if(!n)return{};const a=await i(n,"utf-8"),s=c(a),f=s.compilerOptions?.paths,l=s.compilerOptions?.baseUrl||".";if(!f)return{};const u={};for(const[t,o]of Object.entries(f))if(Array.isArray(o)&&o.length>0){const n=t.replace("/*",""),e=r(process.cwd(),l,o[0].replace("/*",""));u[n]=e}return u}catch(r){return{}}}export{m as defineConfig,g as ensureConfig,w as getTsConfigAliases,d as loadConfig};
|
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";export{runTypesGenerator}from"./types-generator.js";
|
package/dist/esm/migrator.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{resolve as e}from"node:path";import{access as t,writeFile as
|
|
1
|
+
import{resolve as e}from"node:path";import{access as t,writeFile as o}from"node:fs/promises";import{pathToFileURL as n}from"node:url";import{createJiti as i}from"jiti";import{getTsConfigAliases as r}from"./config.js";const s=e(process.cwd(),"i18next.config.ts"),a=["i18next.config.ts","i18next.config.js","i18next.config.mjs","i18next.config.cjs"],c=[".js",".mjs",".cjs",".ts"];async function l(e){if(c.some(t=>e.endsWith(t)))try{return await t(e),e}catch{return null}for(const o of c){const n=`${e}${o}`;try{return await t(n),n}catch{}}return null}async function f(c){let f;if(c){if(f=await l(e(process.cwd(),c)),!f)return console.log(`No legacy config file found at or near: ${c}`),void console.log("Tried extensions: .js, .mjs, .cjs, .ts")}else if(f=await l(e(process.cwd(),"i18next-parser.config")),!f)return console.log("No i18next-parser.config.* found. Nothing to migrate."),void console.log("Tried: i18next-parser.config.js, .mjs, .cjs, .ts");console.log(`Attempting to migrate legacy config from: ${f}...`);for(const o of a)try{const n=e(process.cwd(),o);return await t(n),void console.warn(`Warning: A new configuration file already exists at "${o}". Migration skipped to avoid overwriting.`)}catch(e){}const p=await async function(e){try{let t;if(e.endsWith(".ts")){const o=await r(),n=i(process.cwd(),{alias:o,interopDefault:!1});t=await n.import(e,{default:!0})}else{const o=n(e).href;t=(await import(`${o}?t=${Date.now()}`)).default}return t}catch(t){return console.error(`Error loading legacy config from ${e}:`,t),null}}(f);if(!p)return void console.error("Could not read the legacy config file.");const u={locales:p.locales||["en"],extract:{input:p.input||"src/**/*.{js,jsx,ts,tsx}",output:(p.output||"locales/$LOCALE/$NAMESPACE.json").replace("$LOCALE","{{language}}").replace("$NAMESPACE","{{namespace}}"),defaultNS:p.defaultNamespace||"translation",keySeparator:p.keySeparator,nsSeparator:p.namespaceSeparator,contextSeparator:p.contextSeparator,functions:p.lexers?.js?.functions||["t","*.t"],transComponents:p.lexers?.js?.components||["Trans"]},types:{input:["locales/{{language}}/{{namespace}}.json"],output:"src/types/i18next.d.ts"}};u.extract.functions.includes("t")&&!u.extract.functions.includes("*.t")&&u.extract.functions.push("*.t");const d=`\nimport { defineConfig } from 'i18next-cli';\n\nexport default defineConfig(${JSON.stringify(u,null,2)});\n`;await o(s,d.trim()),console.log("✅ Success! Migration complete."),console.log(`New configuration file created at: ${s}`),console.warn('\nPlease review the generated file and adjust paths for "types.input" if necessary.'),p.keepRemoved&&console.warn('Warning: The "keepRemoved" option is deprecated. Consider using the "preservePatterns" feature for dynamic keys.'),"v3"===p.i18nextOptions?.compatibilityJSON&&console.warn('Warning: compatibilityJSON "v3" is not supported in i18next-cli. Only i18next v4 format is supported.')}export{f as runMigrator};
|
package/package.json
CHANGED
package/src/cli.ts
CHANGED
|
@@ -21,7 +21,7 @@ const program = new Command()
|
|
|
21
21
|
program
|
|
22
22
|
.name('i18next-cli')
|
|
23
23
|
.description('A unified, high-performance i18next CLI.')
|
|
24
|
-
.version('1.5.
|
|
24
|
+
.version('1.5.7')
|
|
25
25
|
|
|
26
26
|
program
|
|
27
27
|
.command('extract')
|
|
@@ -107,10 +107,10 @@ program
|
|
|
107
107
|
})
|
|
108
108
|
|
|
109
109
|
program
|
|
110
|
-
.command('migrate-config')
|
|
110
|
+
.command('migrate-config [configPath]')
|
|
111
111
|
.description('Migrate a legacy i18next-parser.config.js to the new format.')
|
|
112
|
-
.action(async () => {
|
|
113
|
-
await runMigrator()
|
|
112
|
+
.action(async (configPath) => {
|
|
113
|
+
await runMigrator(configPath)
|
|
114
114
|
})
|
|
115
115
|
|
|
116
116
|
program
|
package/src/config.ts
CHANGED
|
@@ -191,7 +191,7 @@ async function findTsConfigFile (): Promise<string | null> {
|
|
|
191
191
|
* Parses the project's tsconfig.json to extract path aliases for jiti.
|
|
192
192
|
* @returns A record of aliases for jiti's configuration.
|
|
193
193
|
*/
|
|
194
|
-
async function getTsConfigAliases (): Promise<Record<string, string>> {
|
|
194
|
+
export async function getTsConfigAliases (): Promise<Record<string, string>> {
|
|
195
195
|
try {
|
|
196
196
|
const tsConfigPath = await findTsConfigFile()
|
|
197
197
|
if (!tsConfigPath) return {}
|
package/src/index.ts
CHANGED
|
@@ -8,5 +8,11 @@ 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'
|
|
18
|
+
export { runTypesGenerator } from './types-generator'
|
package/src/migrator.ts
CHANGED
|
@@ -1,11 +1,8 @@
|
|
|
1
1
|
import { resolve } from 'node:path'
|
|
2
2
|
import { writeFile, access } from 'node:fs/promises'
|
|
3
3
|
import { pathToFileURL } from 'node:url'
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
* Path to the legacy i18next-parser configuration file
|
|
7
|
-
*/
|
|
8
|
-
const oldConfigPath = resolve(process.cwd(), 'i18next-parser.config.js')
|
|
4
|
+
import { createJiti } from 'jiti'
|
|
5
|
+
import { getTsConfigAliases } from './config'
|
|
9
6
|
|
|
10
7
|
/**
|
|
11
8
|
* Path where the new configuration file will be created
|
|
@@ -23,13 +20,76 @@ const POSSIBLE_NEW_CONFIGS = [
|
|
|
23
20
|
]
|
|
24
21
|
|
|
25
22
|
/**
|
|
26
|
-
*
|
|
23
|
+
* List of supported legacy configuration file extensions
|
|
24
|
+
*/
|
|
25
|
+
const LEGACY_CONFIG_EXTENSIONS = ['.js', '.mjs', '.cjs', '.ts']
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Helper function to find a legacy config file with various extensions
|
|
29
|
+
*/
|
|
30
|
+
async function findLegacyConfigFile (basePath: string): Promise<string | null> {
|
|
31
|
+
// If the provided path already has an extension, use it directly
|
|
32
|
+
if (LEGACY_CONFIG_EXTENSIONS.some(ext => basePath.endsWith(ext))) {
|
|
33
|
+
try {
|
|
34
|
+
await access(basePath)
|
|
35
|
+
return basePath
|
|
36
|
+
} catch {
|
|
37
|
+
return null
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// Try different extensions
|
|
42
|
+
for (const ext of LEGACY_CONFIG_EXTENSIONS) {
|
|
43
|
+
const fullPath = `${basePath}${ext}`
|
|
44
|
+
try {
|
|
45
|
+
await access(fullPath)
|
|
46
|
+
return fullPath
|
|
47
|
+
} catch {
|
|
48
|
+
// Continue to next extension
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return null
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Loads a legacy config file using the appropriate loader (jiti for TS, dynamic import for JS/MJS/CJS)
|
|
57
|
+
*/
|
|
58
|
+
async function loadLegacyConfig (configPath: string): Promise<any> {
|
|
59
|
+
try {
|
|
60
|
+
let config: any
|
|
61
|
+
|
|
62
|
+
// Use jiti for TypeScript files, native import for JavaScript
|
|
63
|
+
if (configPath.endsWith('.ts')) {
|
|
64
|
+
const aliases = await getTsConfigAliases()
|
|
65
|
+
const jiti = createJiti(process.cwd(), {
|
|
66
|
+
alias: aliases,
|
|
67
|
+
interopDefault: false,
|
|
68
|
+
})
|
|
69
|
+
|
|
70
|
+
const configModule = await jiti.import(configPath, { default: true })
|
|
71
|
+
config = configModule
|
|
72
|
+
} else {
|
|
73
|
+
const configUrl = pathToFileURL(configPath).href
|
|
74
|
+
const configModule = await import(`${configUrl}?t=${Date.now()}`)
|
|
75
|
+
config = configModule.default
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
return config
|
|
79
|
+
} catch (error) {
|
|
80
|
+
console.error(`Error loading legacy config from ${configPath}:`, error)
|
|
81
|
+
return null
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Migrates a legacy i18next-parser configuration file to the new
|
|
27
87
|
* i18next-cli configuration format.
|
|
28
88
|
*
|
|
29
89
|
* This function:
|
|
30
|
-
* 1. Checks if a legacy config file exists
|
|
90
|
+
* 1. Checks if a legacy config file exists (supports .js, .mjs, .cjs, .ts)
|
|
31
91
|
* 2. Prevents migration if any new config file already exists
|
|
32
|
-
* 3. Dynamically imports the old configuration
|
|
92
|
+
* 3. Dynamically imports the old configuration using appropriate loader
|
|
33
93
|
* 4. Maps old configuration properties to new format:
|
|
34
94
|
* - `$LOCALE` → `{{language}}`
|
|
35
95
|
* - `$NAMESPACE` → `{{namespace}}`
|
|
@@ -38,41 +98,41 @@ const POSSIBLE_NEW_CONFIGS = [
|
|
|
38
98
|
* 5. Generates a new TypeScript configuration file
|
|
39
99
|
* 6. Provides warnings for deprecated features
|
|
40
100
|
*
|
|
101
|
+
* @param customConfigPath - Optional custom path to the legacy config file
|
|
102
|
+
*
|
|
41
103
|
* @example
|
|
42
|
-
* ```
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
* }
|
|
104
|
+
* ```bash
|
|
105
|
+
* # Migrate default config
|
|
106
|
+
* npx i18next-cli migrate-config
|
|
107
|
+
*
|
|
108
|
+
* # Migrate custom config with extension
|
|
109
|
+
* npx i18next-cli migrate-config i18next-parser.config.mjs
|
|
49
110
|
*
|
|
50
|
-
*
|
|
51
|
-
*
|
|
52
|
-
* locales: ['en', 'de'],
|
|
53
|
-
* extract: {
|
|
54
|
-
* input: ['src/**\/*.js'],
|
|
55
|
-
* output: 'locales/{{language}}/{{namespace}}.json'
|
|
56
|
-
* }
|
|
57
|
-
* })
|
|
111
|
+
* # Migrate custom config without extension (will try .js, .mjs, .cjs, .ts)
|
|
112
|
+
* npx i18next-cli migrate-config my-custom-config
|
|
58
113
|
* ```
|
|
59
114
|
*/
|
|
60
|
-
export async function runMigrator () {
|
|
61
|
-
|
|
115
|
+
export async function runMigrator (customConfigPath?: string) {
|
|
116
|
+
let oldConfigPath: string | null
|
|
62
117
|
|
|
63
|
-
|
|
64
|
-
await
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
118
|
+
if (customConfigPath) {
|
|
119
|
+
oldConfigPath = await findLegacyConfigFile(resolve(process.cwd(), customConfigPath))
|
|
120
|
+
if (!oldConfigPath) {
|
|
121
|
+
console.log(`No legacy config file found at or near: ${customConfigPath}`)
|
|
122
|
+
console.log('Tried extensions: .js, .mjs, .cjs, .ts')
|
|
123
|
+
return
|
|
124
|
+
}
|
|
125
|
+
} else {
|
|
126
|
+
// Default behavior: look for i18next-parser.config.* files
|
|
127
|
+
oldConfigPath = await findLegacyConfigFile(resolve(process.cwd(), 'i18next-parser.config'))
|
|
128
|
+
if (!oldConfigPath) {
|
|
129
|
+
console.log('No i18next-parser.config.* found. Nothing to migrate.')
|
|
130
|
+
console.log('Tried: i18next-parser.config.js, .mjs, .cjs, .ts')
|
|
131
|
+
return
|
|
132
|
+
}
|
|
68
133
|
}
|
|
69
134
|
|
|
70
|
-
|
|
71
|
-
await access(oldConfigPath)
|
|
72
|
-
} catch (e) {
|
|
73
|
-
console.log('No i18next-parser.config.js found. Nothing to migrate.')
|
|
74
|
-
return
|
|
75
|
-
}
|
|
135
|
+
console.log(`Attempting to migrate legacy config from: ${oldConfigPath}...`)
|
|
76
136
|
|
|
77
137
|
// Check if ANY new config file already exists
|
|
78
138
|
for (const configFile of POSSIBLE_NEW_CONFIGS) {
|
|
@@ -86,10 +146,8 @@ export async function runMigrator () {
|
|
|
86
146
|
}
|
|
87
147
|
}
|
|
88
148
|
|
|
89
|
-
//
|
|
90
|
-
const
|
|
91
|
-
const oldConfigModule = await import(oldConfigUrl)
|
|
92
|
-
const oldConfig = oldConfigModule.default
|
|
149
|
+
// Load the legacy config using the appropriate loader
|
|
150
|
+
const oldConfig = await loadLegacyConfig(oldConfigPath)
|
|
93
151
|
|
|
94
152
|
if (!oldConfig) {
|
|
95
153
|
console.error('Could not read the legacy config file.')
|
|
@@ -101,7 +159,9 @@ export async function runMigrator () {
|
|
|
101
159
|
locales: oldConfig.locales || ['en'],
|
|
102
160
|
extract: {
|
|
103
161
|
input: oldConfig.input || 'src/**/*.{js,jsx,ts,tsx}',
|
|
104
|
-
output: (oldConfig.output || 'locales/$LOCALE/$NAMESPACE.json')
|
|
162
|
+
output: (oldConfig.output || 'locales/$LOCALE/$NAMESPACE.json')
|
|
163
|
+
.replace('$LOCALE', '{{language}}')
|
|
164
|
+
.replace('$NAMESPACE', '{{namespace}}'),
|
|
105
165
|
defaultNS: oldConfig.defaultNamespace || 'translation',
|
|
106
166
|
keySeparator: oldConfig.keySeparator,
|
|
107
167
|
nsSeparator: oldConfig.namespaceSeparator,
|
|
@@ -110,15 +170,12 @@ export async function runMigrator () {
|
|
|
110
170
|
functions: oldConfig.lexers?.js?.functions || ['t', '*.t'],
|
|
111
171
|
transComponents: oldConfig.lexers?.js?.components || ['Trans'],
|
|
112
172
|
},
|
|
113
|
-
|
|
114
|
-
input: 'locales/{{language}}/{{namespace}}.json', // Sensible default
|
|
173
|
+
types: {
|
|
174
|
+
input: ['locales/{{language}}/{{namespace}}.json'], // Sensible default
|
|
115
175
|
output: 'src/types/i18next.d.ts', // Sensible default
|
|
116
176
|
},
|
|
117
|
-
sync: {
|
|
118
|
-
primaryLanguage: oldConfig.locales?.[0] || 'en',
|
|
119
|
-
secondaryLanguages: oldConfig.locales.filter((l: string) => l !== (oldConfig.locales?.[0] || 'en'))
|
|
120
|
-
},
|
|
121
177
|
}
|
|
178
|
+
|
|
122
179
|
// Make the migration smarter: if 't' is a function, also add the '*.t' wildcard
|
|
123
180
|
// to provide better out-of-the-box support for common patterns like `i18n.t`.
|
|
124
181
|
if (newConfig.extract.functions.includes('t') && !newConfig.extract.functions.includes('*.t')) {
|
|
@@ -137,8 +194,15 @@ export default defineConfig(${JSON.stringify(newConfig, null, 2)});
|
|
|
137
194
|
|
|
138
195
|
console.log('✅ Success! Migration complete.')
|
|
139
196
|
console.log(`New configuration file created at: ${newConfigPath}`)
|
|
140
|
-
console.warn('\nPlease review the generated file and adjust paths for "
|
|
197
|
+
console.warn('\nPlease review the generated file and adjust paths for "types.input" if necessary.')
|
|
198
|
+
|
|
199
|
+
// Warning for deprecated features
|
|
141
200
|
if (oldConfig.keepRemoved) {
|
|
142
201
|
console.warn('Warning: The "keepRemoved" option is deprecated. Consider using the "preservePatterns" feature for dynamic keys.')
|
|
143
202
|
}
|
|
203
|
+
|
|
204
|
+
// Warning for compatibilityJSON v3
|
|
205
|
+
if (oldConfig.i18nextOptions?.compatibilityJSON === 'v3') {
|
|
206
|
+
console.warn('Warning: compatibilityJSON "v3" is not supported in i18next-cli. Only i18next v4 format is supported.')
|
|
207
|
+
}
|
|
144
208
|
}
|
package/types/config.d.ts
CHANGED
|
@@ -47,4 +47,9 @@ export declare function loadConfig(logger?: Logger): Promise<I18nextToolkitConfi
|
|
|
47
47
|
* @throws Exits the process if the user declines to create a config or if loading fails after creation.
|
|
48
48
|
*/
|
|
49
49
|
export declare function ensureConfig(logger?: Logger): Promise<I18nextToolkitConfig>;
|
|
50
|
+
/**
|
|
51
|
+
* Parses the project's tsconfig.json to extract path aliases for jiti.
|
|
52
|
+
* @returns A record of aliases for jiti's configuration.
|
|
53
|
+
*/
|
|
54
|
+
export declare function getTsConfigAliases(): Promise<Record<string, string>>;
|
|
50
55
|
//# sourceMappingURL=config.d.ts.map
|
package/types/config.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AAc3D;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,YAAY,CAAE,MAAM,EAAE,oBAAoB,GAAG,oBAAoB,CAEhF;AAqBD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAsB,UAAU,CAAE,MAAM,GAAE,MAA4B,GAAG,OAAO,CAAC,oBAAoB,GAAG,IAAI,CAAC,CA2C5G;AAED;;;;;;GAMG;AACH,wBAAsB,YAAY,CAAE,MAAM,GAAE,MAA4B,GAAG,OAAO,CAAC,oBAAoB,CAAC,CA8BvG"}
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AAc3D;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,YAAY,CAAE,MAAM,EAAE,oBAAoB,GAAG,oBAAoB,CAEhF;AAqBD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAsB,UAAU,CAAE,MAAM,GAAE,MAA4B,GAAG,OAAO,CAAC,oBAAoB,GAAG,IAAI,CAAC,CA2C5G;AAED;;;;;;GAMG;AACH,wBAAsB,YAAY,CAAE,MAAM,GAAE,MAA4B,GAAG,OAAO,CAAC,oBAAoB,CAAC,CA8BvG;AAyBD;;;GAGG;AACH,wBAAsB,kBAAkB,IAAK,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAyB3E"}
|
package/types/index.d.ts
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
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';
|
|
7
|
+
export { runTypesGenerator } from './types-generator';
|
|
4
8
|
//# 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;AACpC,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAA"}
|
package/types/migrator.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Migrates a legacy i18next-parser
|
|
2
|
+
* Migrates a legacy i18next-parser configuration file to the new
|
|
3
3
|
* i18next-cli configuration format.
|
|
4
4
|
*
|
|
5
5
|
* This function:
|
|
6
|
-
* 1. Checks if a legacy config file exists
|
|
6
|
+
* 1. Checks if a legacy config file exists (supports .js, .mjs, .cjs, .ts)
|
|
7
7
|
* 2. Prevents migration if any new config file already exists
|
|
8
|
-
* 3. Dynamically imports the old configuration
|
|
8
|
+
* 3. Dynamically imports the old configuration using appropriate loader
|
|
9
9
|
* 4. Maps old configuration properties to new format:
|
|
10
10
|
* - `$LOCALE` → `{{language}}`
|
|
11
11
|
* - `$NAMESPACE` → `{{namespace}}`
|
|
@@ -14,24 +14,19 @@
|
|
|
14
14
|
* 5. Generates a new TypeScript configuration file
|
|
15
15
|
* 6. Provides warnings for deprecated features
|
|
16
16
|
*
|
|
17
|
+
* @param customConfigPath - Optional custom path to the legacy config file
|
|
18
|
+
*
|
|
17
19
|
* @example
|
|
18
|
-
* ```
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
* }
|
|
20
|
+
* ```bash
|
|
21
|
+
* # Migrate default config
|
|
22
|
+
* npx i18next-cli migrate-config
|
|
23
|
+
*
|
|
24
|
+
* # Migrate custom config with extension
|
|
25
|
+
* npx i18next-cli migrate-config i18next-parser.config.mjs
|
|
25
26
|
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
* locales: ['en', 'de'],
|
|
29
|
-
* extract: {
|
|
30
|
-
* input: ['src/**\/*.js'],
|
|
31
|
-
* output: 'locales/{{language}}/{{namespace}}.json'
|
|
32
|
-
* }
|
|
33
|
-
* })
|
|
27
|
+
* # Migrate custom config without extension (will try .js, .mjs, .cjs, .ts)
|
|
28
|
+
* npx i18next-cli migrate-config my-custom-config
|
|
34
29
|
* ```
|
|
35
30
|
*/
|
|
36
|
-
export declare function runMigrator(): Promise<void>;
|
|
31
|
+
export declare function runMigrator(customConfigPath?: string): Promise<void>;
|
|
37
32
|
//# sourceMappingURL=migrator.d.ts.map
|
package/types/migrator.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"migrator.d.ts","sourceRoot":"","sources":["../src/migrator.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"migrator.d.ts","sourceRoot":"","sources":["../src/migrator.ts"],"names":[],"mappings":"AAoFA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,wBAAsB,WAAW,CAAE,gBAAgB,CAAC,EAAE,MAAM,iBA6F3D"}
|