@lingui/cli 4.1.0 → 4.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,5 @@
1
+ import { Catalog } from "../catalog";
2
+ /**
3
+ * Return all files catalog implicitly depends on.
4
+ */
5
+ export declare function getCatalogDependentFiles(catalog: Catalog, locale: string): string[];
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getCatalogDependentFiles = void 0;
4
+ const getFallbackListForLocale_1 = require("./getFallbackListForLocale");
5
+ /**
6
+ * Return all files catalog implicitly depends on.
7
+ */
8
+ function getCatalogDependentFiles(catalog, locale) {
9
+ const files = new Set([catalog.templateFile]);
10
+ (0, getFallbackListForLocale_1.getFallbackListForLocale)(catalog.config.fallbackLocales, locale).forEach((locale) => {
11
+ files.add(catalog.getFilename(locale));
12
+ });
13
+ if (catalog.config.sourceLocale && locale !== catalog.config.sourceLocale) {
14
+ files.add(catalog.getFilename(catalog.config.sourceLocale));
15
+ }
16
+ return Array.from(files.values());
17
+ }
18
+ exports.getCatalogDependentFiles = getCatalogDependentFiles;
@@ -0,0 +1,2 @@
1
+ import { FallbackLocales } from "@lingui/conf";
2
+ export declare function getFallbackListForLocale(fallbackLocales: FallbackLocales, locale: string): string[];
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getFallbackListForLocale = void 0;
4
+ function getFallbackListForLocale(fallbackLocales, locale) {
5
+ const fL = [];
6
+ if (fallbackLocales === null || fallbackLocales === void 0 ? void 0 : fallbackLocales[locale]) {
7
+ const mapping = fallbackLocales === null || fallbackLocales === void 0 ? void 0 : fallbackLocales[locale];
8
+ Array.isArray(mapping) ? fL.push(...mapping) : fL.push(mapping);
9
+ }
10
+ if ((fallbackLocales === null || fallbackLocales === void 0 ? void 0 : fallbackLocales.default) && locale !== (fallbackLocales === null || fallbackLocales === void 0 ? void 0 : fallbackLocales.default)) {
11
+ fL.push(fallbackLocales === null || fallbackLocales === void 0 ? void 0 : fallbackLocales.default);
12
+ }
13
+ return fL;
14
+ }
15
+ exports.getFallbackListForLocale = getFallbackListForLocale;
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getTranslationsForCatalog = void 0;
4
+ const getFallbackListForLocale_1 = require("./getFallbackListForLocale");
4
5
  async function getTranslationsForCatalog(catalog, locale, options) {
5
6
  const catalogs = await catalog.readAll();
6
7
  const template = (await catalog.readTemplate()) || {};
@@ -26,20 +27,14 @@ function getTranslation(catalogs, msg, locale, key, options) {
26
27
  return (_a = localeCatalog === null || localeCatalog === void 0 ? void 0 : localeCatalog[key]) === null || _a === void 0 ? void 0 : _a.translation;
27
28
  };
28
29
  const getMultipleFallbacks = (_locale) => {
29
- const fL = fallbackLocales && (fallbackLocales === null || fallbackLocales === void 0 ? void 0 : fallbackLocales[_locale]);
30
- // some probably the fallback will be undefined, so just search by locale
31
- if (!fL)
30
+ const fL = (0, getFallbackListForLocale_1.getFallbackListForLocale)(fallbackLocales, _locale);
31
+ if (!fL.length)
32
32
  return null;
33
- if (Array.isArray(fL)) {
34
- for (const fallbackLocale of fL) {
35
- if (catalogs[fallbackLocale] && getTranslation(fallbackLocale)) {
36
- return getTranslation(fallbackLocale);
37
- }
33
+ for (const fallbackLocale of fL) {
34
+ if (catalogs[fallbackLocale] && getTranslation(fallbackLocale)) {
35
+ return getTranslation(fallbackLocale);
38
36
  }
39
37
  }
40
- else {
41
- return getTranslation(fL);
42
- }
43
38
  };
44
39
  // target locale -> fallback locales -> fallback locales default ->
45
40
  // ** (following fallbacks would emit `missing` warning) **
@@ -52,8 +47,6 @@ function getTranslation(catalogs, msg, locale, key, options) {
52
47
  getTranslation(locale) ||
53
48
  // We search in fallbackLocales as dependent of each locale
54
49
  getMultipleFallbacks(locale) ||
55
- // Get translation in fallbackLocales.default (if any)
56
- ((fallbackLocales === null || fallbackLocales === void 0 ? void 0 : fallbackLocales.default) && getTranslation(fallbackLocales.default)) ||
57
50
  (sourceLocale &&
58
51
  sourceLocale === locale &&
59
52
  sourceLocaleFallback(catalogs[sourceLocale], key));
@@ -33,6 +33,7 @@ export declare class Catalog {
33
33
  format: FormatterWrapper;
34
34
  templateFile?: string;
35
35
  constructor({ name, path, include, templatePath, format, exclude }: CatalogProps, config: LinguiConfigNormalized);
36
+ getFilename(locale: string): string;
36
37
  make(options: MakeOptions): Promise<AllCatalogsType | false>;
37
38
  makeTemplate(options: MakeTemplateOptions): Promise<CatalogType | false>;
38
39
  /**
@@ -50,6 +50,10 @@ class Catalog {
50
50
  templatePath ||
51
51
  getTemplatePath(this.format.getTemplateExtension(), this.path);
52
52
  }
53
+ getFilename(locale) {
54
+ return ((0, utils_1.replacePlaceholders)(this.path, { locale }) +
55
+ this.format.getCatalogExtension());
56
+ }
53
57
  async make(options) {
54
58
  const nextCatalog = await this.collect({ files: options.files });
55
59
  if (!nextCatalog)
@@ -119,8 +123,7 @@ class Catalog {
119
123
  return await (0, getTranslationsForCatalog_1.getTranslationsForCatalog)(this, locale, options);
120
124
  }
121
125
  async write(locale, messages) {
122
- const filename = (0, utils_1.replacePlaceholders)(this.path, { locale }) +
123
- this.format.getCatalogExtension();
126
+ const filename = this.getFilename(locale);
124
127
  const created = !fs_1.default.existsSync(filename);
125
128
  await this.format.write(filename, messages, locale);
126
129
  return [created, filename];
@@ -145,9 +148,7 @@ class Catalog {
145
148
  return filename;
146
149
  }
147
150
  async read(locale) {
148
- const filename = (0, utils_1.replacePlaceholders)(this.path, { locale }) +
149
- this.format.getCatalogExtension();
150
- return await this.format.read(filename, locale);
151
+ return await this.format.read(this.getFilename(locale), locale);
151
152
  }
152
153
  async readAll() {
153
154
  const res = {};
@@ -2,4 +2,5 @@ export { getFormat } from "./formats";
2
2
  export { getCatalogForFile, getCatalogs } from "./catalog/getCatalogs";
3
3
  export { createCompiledCatalog } from "./compile";
4
4
  export { default as extractor } from "./extractors/babel";
5
+ export { getCatalogDependentFiles } from "./catalog/getCatalogDependentFiles";
5
6
  export * from "./types";
package/dist/api/index.js CHANGED
@@ -17,7 +17,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
17
17
  return (mod && mod.__esModule) ? mod : { "default": mod };
18
18
  };
19
19
  Object.defineProperty(exports, "__esModule", { value: true });
20
- exports.extractor = exports.createCompiledCatalog = exports.getCatalogs = exports.getCatalogForFile = exports.getFormat = void 0;
20
+ exports.getCatalogDependentFiles = exports.extractor = exports.createCompiledCatalog = exports.getCatalogs = exports.getCatalogForFile = exports.getFormat = void 0;
21
21
  var formats_1 = require("./formats");
22
22
  Object.defineProperty(exports, "getFormat", { enumerable: true, get: function () { return formats_1.getFormat; } });
23
23
  var getCatalogs_1 = require("./catalog/getCatalogs");
@@ -27,4 +27,6 @@ var compile_1 = require("./compile");
27
27
  Object.defineProperty(exports, "createCompiledCatalog", { enumerable: true, get: function () { return compile_1.createCompiledCatalog; } });
28
28
  var babel_1 = require("./extractors/babel");
29
29
  Object.defineProperty(exports, "extractor", { enumerable: true, get: function () { return __importDefault(babel_1).default; } });
30
+ var getCatalogDependentFiles_1 = require("./catalog/getCatalogDependentFiles");
31
+ Object.defineProperty(exports, "getCatalogDependentFiles", { enumerable: true, get: function () { return getCatalogDependentFiles_1.getCatalogDependentFiles; } });
30
32
  __exportStar(require("./types"), exports);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lingui/cli",
3
- "version": "4.1.0",
3
+ "version": "4.1.1",
4
4
  "description": "CLI for working wit message catalogs",
5
5
  "keywords": [
6
6
  "cli",
@@ -9,7 +9,8 @@
9
9
  "i10n",
10
10
  "localization",
11
11
  "i9n",
12
- "translation"
12
+ "translation",
13
+ "multilingual"
13
14
  ],
14
15
  "repository": "lingui/js-lingui",
15
16
  "bugs": "https://github.com/lingui/js-lingui/issues",
@@ -52,11 +53,11 @@
52
53
  "@babel/parser": "^7.21.2",
53
54
  "@babel/runtime": "^7.21.0",
54
55
  "@babel/types": "^7.21.2",
55
- "@lingui/babel-plugin-extract-messages": "4.1.0",
56
- "@lingui/conf": "4.1.0",
57
- "@lingui/core": "4.1.0",
58
- "@lingui/format-po": "4.1.0",
59
- "@lingui/message-utils": "4.1.0",
56
+ "@lingui/babel-plugin-extract-messages": "4.1.1",
57
+ "@lingui/conf": "4.1.1",
58
+ "@lingui/core": "4.1.1",
59
+ "@lingui/format-po": "4.1.1",
60
+ "@lingui/message-utils": "4.1.1",
60
61
  "babel-plugin-macros": "^3.0.1",
61
62
  "chalk": "^4.1.0",
62
63
  "chokidar": "3.5.1",
@@ -78,7 +79,7 @@
78
79
  },
79
80
  "devDependencies": {
80
81
  "@lingui/jest-mocks": "*",
81
- "@lingui/macro": "4.1.0",
82
+ "@lingui/macro": "4.1.1",
82
83
  "@types/convert-source-map": "^2.0.0",
83
84
  "@types/glob": "^8.1.0",
84
85
  "@types/micromatch": "^4.0.1",
@@ -86,5 +87,5 @@
86
87
  "mock-fs": "^5.2.0",
87
88
  "mockdate": "^3.0.5"
88
89
  },
89
- "gitHead": "471813c5de9ade3acccf647e18922b570a804577"
90
+ "gitHead": "dad2c065901a9574bc117a8ef7ed75465ad713d0"
90
91
  }