@lingui/cli 6.6.0 → 6.7.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
@@ -4,22 +4,43 @@
4
4
 
5
5
  # @lingui/cli
6
6
 
7
- > lingui command line library for manipulating message catalogues
7
+ > Lingui CLI: extracts i18n messages from source code into catalogs and compiles the translated catalogs for the runtime
8
8
 
9
- `@lingui/cli` is part of [LinguiJS][linguijs]. See the [documentation][documentation] for all information, tutorials and examples.
9
+ `@lingui/cli` is part of [Lingui][documentation]. Lingui is a lightweight, open-source internationalization (i18n) library for JavaScript and TypeScript. It brings compile-time macros and a CLI for message extraction to React, React Native, Vue, SolidJS, Astro, Svelte, and Node.js.
10
10
 
11
- ## Installation & Usage
11
+ The `lingui` command reads `lingui.config.js` (or `.ts`) from the project root: the source locale, the target locales and where the catalogs live. The [installation guide][installation] shows the minimal file and the [configuration reference][conf] lists every option.
12
12
 
13
- See the [reference][reference] documentation.
13
+ ## Installation
14
+
15
+ ```sh
16
+ npm install --save-dev @lingui/cli
17
+ ```
18
+
19
+ ## Usage
20
+
21
+ - `lingui extract` finds the messages in the source, merges them into one catalog per locale, keeps existing translations and marks removed messages as obsolete.
22
+ - `lingui compile` compiles the translated catalogs into JavaScript modules for the runtime and reports messages with invalid ICU syntax.
23
+ - `lingui extract-template` writes a single `.pot` template with the source messages, for translation platforms that create the locale files themselves.
24
+ - `lingui extract-experimental` follows the imports from each entry point instead of a glob, so a multi-page app gets one catalog per page.
25
+
26
+ Extraction parses JavaScript and TypeScript out of the box; Vue single-file components need [`@lingui/extractor-vue`][extractor-vue]. Catalogs are PO files by default, with [other formats][catalog-formats] available as separate packages. To let the bundler compile catalogs instead of running `lingui compile`, use [`@lingui/vite-plugin`][vite-plugin], [`@lingui/loader`][loader] or [`@lingui/metro-transformer`][metro-transformer].
27
+
28
+ See the [CLI reference][reference] for all commands and options.
14
29
 
15
30
  ## License
16
31
 
17
- This package is licensed under [MIT][license] license.
32
+ This package is licensed under the [MIT][license] license.
18
33
 
19
34
  [license]: https://github.com/lingui/js-lingui/blob/main/LICENSE
20
- [linguijs]: https://github.com/lingui/js-lingui
21
35
  [documentation]: https://lingui.dev
36
+ [installation]: https://lingui.dev/installation
37
+ [conf]: https://lingui.dev/ref/conf
22
38
  [reference]: https://lingui.dev/ref/cli
39
+ [catalog-formats]: https://lingui.dev/ref/catalog-formats
40
+ [extractor-vue]: https://lingui.dev/ref/extractor-vue
41
+ [vite-plugin]: https://lingui.dev/ref/vite-plugin
42
+ [loader]: https://lingui.dev/ref/loader
43
+ [metro-transformer]: https://lingui.dev/ref/metro-transformer
23
44
  [package]: https://www.npmjs.com/package/@lingui/cli
24
45
  [badge-downloads]: https://img.shields.io/npm/dw/@lingui/cli.svg
25
46
  [badge-version]: https://img.shields.io/npm/v/@lingui/cli.svg
@@ -273,12 +273,15 @@ export function order(by, catalog) {
273
273
  return acc;
274
274
  }, {});
275
275
  }
276
+ // hardcoded en-US locale to have consistent sorting
277
+ // @see https://github.com/lingui/js-lingui/pull/1808
278
+ const collator = new Intl.Collator("en-US");
276
279
  /**
277
280
  * Object keys are in the same order as they were created
278
281
  * https://stackoverflow.com/a/31102605/1535540
279
282
  */
280
283
  const orderByMessageId = (a, b) => {
281
- return a.messageId.localeCompare(b.messageId);
284
+ return collator.compare(a.messageId, b.messageId);
282
285
  };
283
286
  const orderByOrigin = (a, b) => {
284
287
  if (!a.entry.origin || !b.entry.origin) {
@@ -323,9 +326,6 @@ export async function writeCompiled(path, locale, compiledCatalog, namespace) {
323
326
  await writeFile(filename, compiledCatalog);
324
327
  return filename;
325
328
  }
326
- // hardcoded en-US locale to have consistent sorting
327
- // @see https://github.com/lingui/js-lingui/pull/1808
328
- const collator = new Intl.Collator("en-US");
329
329
  export const orderByMessage = (a, b) => {
330
330
  const aMsg = a.entry.message || "";
331
331
  const bMsg = b.entry.message || "";
@@ -14,8 +14,9 @@ export async function compileLocale(catalogs, locale, options, config, doMerge,
14
14
  fallbackLocales: config.fallbackLocales,
15
15
  sourceLocale: config.sourceLocale,
16
16
  });
17
+ const pseudoLocaleConfig = config.pseudoLocale.find((item) => item.locale === locale);
17
18
  if (!options.allowEmpty &&
18
- locale !== config.pseudoLocale.locale &&
19
+ !pseudoLocaleConfig &&
19
20
  missingMessages.length > 0) {
20
21
  logger.error(styleText("red", `Error: Failed to compile catalog for locale ${styleText("bold", locale)}!`));
21
22
  if (options.verbose) {
@@ -53,12 +54,13 @@ async function compileAndWrite(locale, config, options, writePath, messages, log
53
54
  const namespace = options.typescript
54
55
  ? "ts"
55
56
  : options.namespace || config.compileNamespace;
57
+ const pseudoLocaleConfig = config.pseudoLocale.find((item) => item.locale === locale);
56
58
  const { source: compiledCatalog, errors } = createCompiledCatalog(locale, messages, {
57
59
  strict: false,
58
60
  namespace,
59
61
  outputPrefix: options.outputPrefix,
60
- pseudoLocale: config.pseudoLocale.locale,
61
- pseudoLocaleOptions: config.pseudoLocale.options,
62
+ pseudoLocale: pseudoLocaleConfig?.locale,
63
+ pseudoLocaleOptions: pseudoLocaleConfig?.options,
62
64
  compilerBabelOptions: config.compilerBabelOptions,
63
65
  });
64
66
  if (errors.length) {
package/dist/api/stats.js CHANGED
@@ -25,8 +25,9 @@ export function printStats(config, catalogs) {
25
25
  return a.localeCompare(b);
26
26
  })
27
27
  .forEach((locale) => {
28
- if (locale === config.pseudoLocale.locale)
29
- return; // skip pseudo locale
28
+ // skip pseudo locale
29
+ if (config.pseudoLocale.some((item) => item.locale === locale))
30
+ return;
30
31
  const catalog = catalogs[locale];
31
32
  // catalog is null if no catalog exists on disk and the locale
32
33
  // was not extracted due to a `--locale` filter
@@ -7,8 +7,8 @@ import { readFileSync } from "node:fs";
7
7
  import path from "node:path";
8
8
  const getTargetLocales = (config) => {
9
9
  const sourceLocale = config.sourceLocale || "en";
10
- const pseudoLocale = config.pseudoLocale.locale || "pseudo";
11
- return config.locales.filter((value) => value != sourceLocale && value != pseudoLocale);
10
+ const pseudoLocales = new Set(config.pseudoLocale.map((item) => item.locale));
11
+ return config.locales.filter((value) => value != sourceLocale && !pseudoLocales.has(value));
12
12
  };
13
13
  // Main sync method, call "Init" or "Sync" depending on the project context
14
14
  export default async function syncProcess(config, options, extractionResult) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@lingui/cli",
3
- "version": "6.6.0",
4
- "description": "Lingui CLI to extract messages, compile catalogs, and manage translation workflows",
3
+ "version": "6.7.0",
4
+ "description": "Lingui CLI: extracts i18n messages from source code into catalogs and compiles the translated catalogs for the runtime",
5
5
  "type": "module",
6
6
  "keywords": [
7
7
  "lingui",
@@ -54,12 +54,12 @@
54
54
  "@babel/generator": "^7.28.5",
55
55
  "@babel/parser": "^7.22.0",
56
56
  "@babel/types": "^7.21.2",
57
- "@lingui/babel-plugin-extract-messages": "6.6.0",
58
- "@lingui/babel-plugin-lingui-macro": "6.6.0",
59
- "@lingui/conf": "6.6.0",
60
- "@lingui/core": "6.6.0",
61
- "@lingui/format-po": "6.6.0",
62
- "@lingui/message-utils": "6.6.0",
57
+ "@lingui/babel-plugin-extract-messages": "6.7.0",
58
+ "@lingui/babel-plugin-lingui-macro": "6.7.0",
59
+ "@lingui/conf": "6.7.0",
60
+ "@lingui/core": "6.7.0",
61
+ "@lingui/format-po": "6.7.0",
62
+ "@lingui/message-utils": "6.7.0",
63
63
  "chokidar": "5.0.0",
64
64
  "cli-table3": "^0.6.5",
65
65
  "commander": "^14.0.2",
@@ -68,7 +68,7 @@
68
68
  "ms": "^2.1.3",
69
69
  "normalize-path": "^3.0.0",
70
70
  "ora": "^9.1.0",
71
- "pseudolocale": "^2.2.0",
71
+ "pseudolocale": "^3.1.0",
72
72
  "source-map": "^0.7.6",
73
73
  "tinypool": "^2.1.0"
74
74
  },
@@ -97,5 +97,5 @@
97
97
  "rolldown": "^1.1.1",
98
98
  "vitest": "catalog:"
99
99
  },
100
- "gitHead": "665a19815378dedd89346bb7707bdb0e28df79e7"
100
+ "gitHead": "a2d4b6d42e052fed1d432050b20cc56cfdacfe98"
101
101
  }