i18next-cli 1.56.12 → 1.57.0

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
@@ -25,6 +25,10 @@ A unified, high-performance i18next CLI toolchain, powered by SWC.
25
25
  > npx i18next-cli lint
26
26
  > ```
27
27
 
28
+ ## Advice:
29
+
30
+ If you're looking for a managed backend to pair with `i18next-cli`, take a look at [Locize](https://www.locize.com?utm_source=i18next_cli_readme&utm_medium=github&utm_campaign=readme) — `i18next-cli` already ships with `locize-download`, `locize-sync`, and `locize-migrate` commands. Built by the same team behind i18next, with CDN delivery, AI translation, review workflow, and no redeploys for copy changes.
31
+
28
32
  ## Why i18next-cli?
29
33
 
30
34
  `i18next-cli` is built from the ground up to meet the demands of modern web development.
@@ -106,6 +110,25 @@ Interactive setup wizard to create your configuration file.
106
110
  npx i18next-cli init
107
111
  ```
108
112
 
113
+ **Options:**
114
+ - `--ci`: Skip the browser launch when a backend (e.g. Locize) is selected;
115
+ the signup URL is printed instead. Useful for scripted runs. The wizard
116
+ also auto-detects `CI=true` and falls back to printing the URL on headless
117
+ Linux (no `DISPLAY`/`WAYLAND_DISPLAY`), so this flag is rarely needed
118
+ explicitly.
119
+
120
+ The wizard asks for the config file type, locales, source-file glob, output
121
+ path, and finally **"Translation backend?"** with three options:
122
+
123
+ - **Local files only** (default) — keeps the current local-JSON workflow.
124
+ - **Locize** (recommended for team / production workflows) — opens the
125
+ [Locize](https://www.locize.app) signup page in your browser and then
126
+ prompts for your Project ID and API key. The wizard writes a `locize`
127
+ block into the generated config so [`locize-sync`](#locize-integration)
128
+ works out of the box. The API key prompt can be left empty (read-only
129
+ mode); add it later via a `LOCIZE_API_KEY` environment variable.
130
+ - **Other / skip** — same as "Local files only" for the wizard's purposes.
131
+
109
132
  ### `extract`
110
133
  Parses source files, extracts keys, and updates your JSON translation files.
111
134
 
@@ -447,6 +470,12 @@ npx i18next-cli rename-key "Invalid username or password" "login.form.invalid-cr
447
470
 
448
471
  ### Locize Integration
449
472
 
473
+ **First-time setup:** the easiest way to wire up Locize is to run
474
+ `npx i18next-cli init` and pick **Locize** at the "Translation backend?"
475
+ prompt — the wizard will open the signup page, ask for your Project ID
476
+ and API key, and write the `locize` block into your config for you. See
477
+ [the `init` command](#init) for details.
478
+
450
479
  **Prerequisites:** The locize commands require `locize-cli` to be installed:
451
480
 
452
481
  ```bash
package/dist/cjs/cli.js CHANGED
@@ -32,7 +32,7 @@ const program = new commander.Command();
32
32
  program
33
33
  .name('i18next-cli')
34
34
  .description('A unified, high-performance i18next CLI.')
35
- .version('1.56.12'); // This string is replaced with the actual version at build time by rollup
35
+ .version('1.57.0'); // This string is replaced with the actual version at build time by rollup
36
36
  // new: global config override option
37
37
  program.option('-c, --config <path>', 'Path to i18next-cli config file (overrides detection)');
38
38
  program
@@ -163,7 +163,8 @@ program
163
163
  program
164
164
  .command('init')
165
165
  .description('Create a new i18next.config.ts/js file with an interactive setup wizard.')
166
- .action(init.runInit);
166
+ .option('--ci', 'Skip the browser launch when a backend (e.g. Locize) is selected. The signup URL is printed instead.')
167
+ .action((options) => init.runInit({ ci: !!options.ci }));
167
168
  program
168
169
  .command('lint')
169
170
  .description('Find potential issues like hardcoded strings in your codebase.')
package/dist/cjs/init.js CHANGED
@@ -3,8 +3,58 @@
3
3
  var inquirer = require('inquirer');
4
4
  var promises = require('node:fs/promises');
5
5
  var node_path = require('node:path');
6
+ var execa = require('execa');
6
7
  var heuristicConfig = require('./heuristic-config.js');
7
8
 
9
+ const LOCIZE_SIGNUP_URL = 'https://www.locize.app/register?from=i18next-cli+init+wizard';
10
+ /** Rough 8-4-4-4-12 hex UUID shape — not strict (locize project IDs may evolve). */
11
+ const UUID_SHAPE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
12
+ /**
13
+ * Opens the given URL in the user's default browser using the platform-native command.
14
+ * Returns true on success, false if there's nowhere to open one (CI, headless Linux)
15
+ * or if spawning the command failed.
16
+ */
17
+ async function openBrowser(url, opts = {}) {
18
+ // Short-circuit: no point spawning a browser-opener in CI or headless Linux.
19
+ if (opts.ci || process.env.CI === 'true')
20
+ return false;
21
+ const isWSL = !!process.env.WSL_DISTRO_NAME;
22
+ if (process.platform === 'linux' && !isWSL &&
23
+ !process.env.DISPLAY && !process.env.WAYLAND_DISPLAY) {
24
+ return false;
25
+ }
26
+ try {
27
+ if (process.platform === 'darwin') {
28
+ await execa.execa('open', [url], { stdio: 'ignore' });
29
+ }
30
+ else if (process.platform === 'win32') {
31
+ // `start` is a cmd.exe builtin; the empty "" is the window-title slot
32
+ await execa.execa('cmd', ['/c', 'start', '""', url], { stdio: 'ignore' });
33
+ }
34
+ else if (isWSL) {
35
+ // WSL: try the wslu / wsl-open shims that bridge to the Windows side
36
+ // before falling back to xdg-open (which usually isn't installed there).
37
+ try {
38
+ await execa.execa('wslview', [url], { stdio: 'ignore' });
39
+ }
40
+ catch {
41
+ try {
42
+ await execa.execa('wsl-open', [url], { stdio: 'ignore' });
43
+ }
44
+ catch {
45
+ await execa.execa('xdg-open', [url], { stdio: 'ignore' });
46
+ }
47
+ }
48
+ }
49
+ else {
50
+ await execa.execa('xdg-open', [url], { stdio: 'ignore' });
51
+ }
52
+ return true;
53
+ }
54
+ catch {
55
+ return false;
56
+ }
57
+ }
8
58
  /**
9
59
  * Determines if the current project is configured as an ESM project.
10
60
  * Checks the package.json file for `"type": "module"`.
@@ -92,7 +142,7 @@ async function isTypeScriptProject() {
92
142
  * // - i18next.config.js (JavaScript ESM/CommonJS)
93
143
  * ```
94
144
  */
95
- async function runInit() {
145
+ async function runInit(options = {}) {
96
146
  console.log('Welcome to the i18next-cli setup wizard!');
97
147
  console.log('Scanning your project for a recommended configuration...');
98
148
  const detectedConfig = await heuristicConfig.detectConfig();
@@ -143,7 +193,49 @@ async function runInit() {
143
193
  ? detectedConfig.extract.output
144
194
  : 'public/locales/{{language}}/{{namespace}}.json',
145
195
  },
196
+ {
197
+ type: 'select',
198
+ name: 'backend',
199
+ message: 'Translation backend?',
200
+ choices: [
201
+ { name: 'Local files only', value: 'local' },
202
+ { name: 'Locize (recommended) — managed backend, CDN delivery, optional AI auto-translate', value: 'locize' },
203
+ { name: 'Other / skip', value: 'other' },
204
+ ],
205
+ default: 'local',
206
+ },
146
207
  ]);
208
+ let locizeConfig;
209
+ if (answers.backend === 'locize') {
210
+ console.log('\nOpening the Locize signup page in your browser. After you create your account and project, come back here and paste your Project ID and API key.');
211
+ const opened = await openBrowser(LOCIZE_SIGNUP_URL, { ci: options.ci });
212
+ if (!opened) {
213
+ console.log(`\n👉 Open this URL manually: ${LOCIZE_SIGNUP_URL}\n`);
214
+ }
215
+ const credentials = await inquirer.prompt([
216
+ {
217
+ type: 'input',
218
+ name: 'projectId',
219
+ message: 'Locize Project ID (e.g. 4eeb5ce0-a7a7-453f-8eb3-078f6eeb56fe):',
220
+ validate: (input) => input.trim().length > 0 || 'Project ID cannot be empty.',
221
+ filter: (input) => input.trim(),
222
+ },
223
+ {
224
+ type: 'password',
225
+ name: 'apiKey',
226
+ message: 'Locize API key (needed for saveMissing / auto-publish / sync during development; leave empty to skip and add later via env var):',
227
+ filter: (input) => input.trim(),
228
+ },
229
+ ]);
230
+ if (!UUID_SHAPE.test(credentials.projectId)) {
231
+ console.log("⚠️ The Project ID doesn't look like a UUID (8-4-4-4-12 hex). It will still be written — double-check it in your Locize project settings.");
232
+ }
233
+ // API keys come in multiple shapes (UUID, `lz_pat_…`, `lz_api_…`, etc.) —
234
+ // treat them as opaque; no client-side format check.
235
+ locizeConfig = { projectId: credentials.projectId };
236
+ if (credentials.apiKey)
237
+ locizeConfig.apiKey = credentials.apiKey;
238
+ }
147
239
  const isTypeScript = answers.fileType.includes('TypeScript');
148
240
  const isEsm = await isEsmProject();
149
241
  const fileName = isTypeScript ? 'i18next.config.ts' : 'i18next.config.js';
@@ -154,6 +246,8 @@ async function runInit() {
154
246
  output: answers.output,
155
247
  },
156
248
  };
249
+ if (locizeConfig)
250
+ configObject.locize = locizeConfig;
157
251
  // Helper to serialize a JS value as a JS literal:
158
252
  function toJs(value, indent = 2, level = 0) {
159
253
  const pad = (n) => ' '.repeat(n * indent);
@@ -225,6 +319,28 @@ module.exports = ${toJs(configObject)}`;
225
319
  const outputPath = node_path.resolve(process.cwd(), fileName);
226
320
  await promises.writeFile(outputPath, fileContent.trim());
227
321
  console.log(`✅ Configuration file created at: ${outputPath}`);
322
+ if (locizeConfig) {
323
+ console.log('\nNext steps for Locize:');
324
+ console.log(' 1. Push your local translations to Locize:');
325
+ console.log(' npx i18next-cli locize-sync');
326
+ console.log(' 2. Find your Project ID and API keys in the Locize UI under:');
327
+ console.log(' Project Settings → "API, CDN, NOTIFICATIONS" tab (www.locize.app)');
328
+ if (locizeConfig.apiKey) {
329
+ console.log(' 3. Before committing, move the API key out of the config file into an environment variable:');
330
+ console.log(' # .env (add to .gitignore)');
331
+ console.log(' LOCIZE_API_KEY=<paste the key currently in your config>');
332
+ console.log(' # then in your config:');
333
+ console.log(' apiKey: process.env.LOCIZE_API_KEY');
334
+ }
335
+ else {
336
+ console.log(' 3. Add your API key later via environment variable:');
337
+ console.log(' # .env (add to .gitignore)');
338
+ console.log(' LOCIZE_API_KEY=...');
339
+ console.log(' # then in your config:');
340
+ console.log(' apiKey: process.env.LOCIZE_API_KEY');
341
+ }
342
+ console.log(' 4. To enable automatic translation, turn it on in your Locize project settings → "EDITOR, TM/MT/AI, ORDERING" tab (web UI).');
343
+ }
228
344
  }
229
345
 
230
346
  exports.runInit = runInit;
package/dist/esm/cli.js CHANGED
@@ -30,7 +30,7 @@ const program = new Command();
30
30
  program
31
31
  .name('i18next-cli')
32
32
  .description('A unified, high-performance i18next CLI.')
33
- .version('1.56.12'); // This string is replaced with the actual version at build time by rollup
33
+ .version('1.57.0'); // This string is replaced with the actual version at build time by rollup
34
34
  // new: global config override option
35
35
  program.option('-c, --config <path>', 'Path to i18next-cli config file (overrides detection)');
36
36
  program
@@ -161,7 +161,8 @@ program
161
161
  program
162
162
  .command('init')
163
163
  .description('Create a new i18next.config.ts/js file with an interactive setup wizard.')
164
- .action(runInit);
164
+ .option('--ci', 'Skip the browser launch when a backend (e.g. Locize) is selected. The signup URL is printed instead.')
165
+ .action((options) => runInit({ ci: !!options.ci }));
165
166
  program
166
167
  .command('lint')
167
168
  .description('Find potential issues like hardcoded strings in your codebase.')
package/dist/esm/init.js CHANGED
@@ -1,8 +1,58 @@
1
1
  import inquirer from 'inquirer';
2
2
  import { writeFile, readFile } from 'node:fs/promises';
3
3
  import { resolve } from 'node:path';
4
+ import { execa } from 'execa';
4
5
  import { detectConfig } from './heuristic-config.js';
5
6
 
7
+ const LOCIZE_SIGNUP_URL = 'https://www.locize.app/register?from=i18next-cli+init+wizard';
8
+ /** Rough 8-4-4-4-12 hex UUID shape — not strict (locize project IDs may evolve). */
9
+ const UUID_SHAPE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
10
+ /**
11
+ * Opens the given URL in the user's default browser using the platform-native command.
12
+ * Returns true on success, false if there's nowhere to open one (CI, headless Linux)
13
+ * or if spawning the command failed.
14
+ */
15
+ async function openBrowser(url, opts = {}) {
16
+ // Short-circuit: no point spawning a browser-opener in CI or headless Linux.
17
+ if (opts.ci || process.env.CI === 'true')
18
+ return false;
19
+ const isWSL = !!process.env.WSL_DISTRO_NAME;
20
+ if (process.platform === 'linux' && !isWSL &&
21
+ !process.env.DISPLAY && !process.env.WAYLAND_DISPLAY) {
22
+ return false;
23
+ }
24
+ try {
25
+ if (process.platform === 'darwin') {
26
+ await execa('open', [url], { stdio: 'ignore' });
27
+ }
28
+ else if (process.platform === 'win32') {
29
+ // `start` is a cmd.exe builtin; the empty "" is the window-title slot
30
+ await execa('cmd', ['/c', 'start', '""', url], { stdio: 'ignore' });
31
+ }
32
+ else if (isWSL) {
33
+ // WSL: try the wslu / wsl-open shims that bridge to the Windows side
34
+ // before falling back to xdg-open (which usually isn't installed there).
35
+ try {
36
+ await execa('wslview', [url], { stdio: 'ignore' });
37
+ }
38
+ catch {
39
+ try {
40
+ await execa('wsl-open', [url], { stdio: 'ignore' });
41
+ }
42
+ catch {
43
+ await execa('xdg-open', [url], { stdio: 'ignore' });
44
+ }
45
+ }
46
+ }
47
+ else {
48
+ await execa('xdg-open', [url], { stdio: 'ignore' });
49
+ }
50
+ return true;
51
+ }
52
+ catch {
53
+ return false;
54
+ }
55
+ }
6
56
  /**
7
57
  * Determines if the current project is configured as an ESM project.
8
58
  * Checks the package.json file for `"type": "module"`.
@@ -90,7 +140,7 @@ async function isTypeScriptProject() {
90
140
  * // - i18next.config.js (JavaScript ESM/CommonJS)
91
141
  * ```
92
142
  */
93
- async function runInit() {
143
+ async function runInit(options = {}) {
94
144
  console.log('Welcome to the i18next-cli setup wizard!');
95
145
  console.log('Scanning your project for a recommended configuration...');
96
146
  const detectedConfig = await detectConfig();
@@ -141,7 +191,49 @@ async function runInit() {
141
191
  ? detectedConfig.extract.output
142
192
  : 'public/locales/{{language}}/{{namespace}}.json',
143
193
  },
194
+ {
195
+ type: 'select',
196
+ name: 'backend',
197
+ message: 'Translation backend?',
198
+ choices: [
199
+ { name: 'Local files only', value: 'local' },
200
+ { name: 'Locize (recommended) — managed backend, CDN delivery, optional AI auto-translate', value: 'locize' },
201
+ { name: 'Other / skip', value: 'other' },
202
+ ],
203
+ default: 'local',
204
+ },
144
205
  ]);
206
+ let locizeConfig;
207
+ if (answers.backend === 'locize') {
208
+ console.log('\nOpening the Locize signup page in your browser. After you create your account and project, come back here and paste your Project ID and API key.');
209
+ const opened = await openBrowser(LOCIZE_SIGNUP_URL, { ci: options.ci });
210
+ if (!opened) {
211
+ console.log(`\n👉 Open this URL manually: ${LOCIZE_SIGNUP_URL}\n`);
212
+ }
213
+ const credentials = await inquirer.prompt([
214
+ {
215
+ type: 'input',
216
+ name: 'projectId',
217
+ message: 'Locize Project ID (e.g. 4eeb5ce0-a7a7-453f-8eb3-078f6eeb56fe):',
218
+ validate: (input) => input.trim().length > 0 || 'Project ID cannot be empty.',
219
+ filter: (input) => input.trim(),
220
+ },
221
+ {
222
+ type: 'password',
223
+ name: 'apiKey',
224
+ message: 'Locize API key (needed for saveMissing / auto-publish / sync during development; leave empty to skip and add later via env var):',
225
+ filter: (input) => input.trim(),
226
+ },
227
+ ]);
228
+ if (!UUID_SHAPE.test(credentials.projectId)) {
229
+ console.log("⚠️ The Project ID doesn't look like a UUID (8-4-4-4-12 hex). It will still be written — double-check it in your Locize project settings.");
230
+ }
231
+ // API keys come in multiple shapes (UUID, `lz_pat_…`, `lz_api_…`, etc.) —
232
+ // treat them as opaque; no client-side format check.
233
+ locizeConfig = { projectId: credentials.projectId };
234
+ if (credentials.apiKey)
235
+ locizeConfig.apiKey = credentials.apiKey;
236
+ }
145
237
  const isTypeScript = answers.fileType.includes('TypeScript');
146
238
  const isEsm = await isEsmProject();
147
239
  const fileName = isTypeScript ? 'i18next.config.ts' : 'i18next.config.js';
@@ -152,6 +244,8 @@ async function runInit() {
152
244
  output: answers.output,
153
245
  },
154
246
  };
247
+ if (locizeConfig)
248
+ configObject.locize = locizeConfig;
155
249
  // Helper to serialize a JS value as a JS literal:
156
250
  function toJs(value, indent = 2, level = 0) {
157
251
  const pad = (n) => ' '.repeat(n * indent);
@@ -223,6 +317,28 @@ module.exports = ${toJs(configObject)}`;
223
317
  const outputPath = resolve(process.cwd(), fileName);
224
318
  await writeFile(outputPath, fileContent.trim());
225
319
  console.log(`✅ Configuration file created at: ${outputPath}`);
320
+ if (locizeConfig) {
321
+ console.log('\nNext steps for Locize:');
322
+ console.log(' 1. Push your local translations to Locize:');
323
+ console.log(' npx i18next-cli locize-sync');
324
+ console.log(' 2. Find your Project ID and API keys in the Locize UI under:');
325
+ console.log(' Project Settings → "API, CDN, NOTIFICATIONS" tab (www.locize.app)');
326
+ if (locizeConfig.apiKey) {
327
+ console.log(' 3. Before committing, move the API key out of the config file into an environment variable:');
328
+ console.log(' # .env (add to .gitignore)');
329
+ console.log(' LOCIZE_API_KEY=<paste the key currently in your config>');
330
+ console.log(' # then in your config:');
331
+ console.log(' apiKey: process.env.LOCIZE_API_KEY');
332
+ }
333
+ else {
334
+ console.log(' 3. Add your API key later via environment variable:');
335
+ console.log(' # .env (add to .gitignore)');
336
+ console.log(' LOCIZE_API_KEY=...');
337
+ console.log(' # then in your config:');
338
+ console.log(' apiKey: process.env.LOCIZE_API_KEY');
339
+ }
340
+ console.log(' 4. To enable automatic translation, turn it on in your Locize project settings → "EDITOR, TM/MT/AI, ORDERING" tab (web UI).');
341
+ }
226
342
  }
227
343
 
228
344
  export { runInit };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "i18next-cli",
3
- "version": "1.56.12",
3
+ "version": "1.57.0",
4
4
  "description": "A unified, high-performance i18next CLI.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -1 +1 @@
1
- {"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAoBnC,QAAA,MAAM,OAAO,SAAgB,CAAA;AAiZ7B,OAAO,EAAE,OAAO,EAAE,CAAA"}
1
+ {"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAoBnC,QAAA,MAAM,OAAO,SAAgB,CAAA;AAkZ7B,OAAO,EAAE,OAAO,EAAE,CAAA"}
package/types/init.d.ts CHANGED
@@ -25,5 +25,7 @@
25
25
  * // - i18next.config.js (JavaScript ESM/CommonJS)
26
26
  * ```
27
27
  */
28
- export declare function runInit(): Promise<void>;
28
+ export declare function runInit(options?: {
29
+ ci?: boolean;
30
+ }): Promise<void>;
29
31
  //# sourceMappingURL=init.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../src/init.ts"],"names":[],"mappings":"AAiEA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAsB,OAAO,kBAyI5B"}
1
+ {"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../src/init.ts"],"names":[],"mappings":"AAkHA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAsB,OAAO,CAAE,OAAO,GAAE;IAAE,EAAE,CAAC,EAAE,OAAO,CAAA;CAAO,iBA6M5D"}