@lingui/cli 4.0.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 = {};
@@ -1,4 +1,6 @@
1
1
  export { getFormat } from "./formats";
2
2
  export { getCatalogForFile, getCatalogs } from "./catalog/getCatalogs";
3
3
  export { createCompiledCatalog } from "./compile";
4
+ export { default as extractor } from "./extractors/babel";
5
+ export { getCatalogDependentFiles } from "./catalog/getCatalogDependentFiles";
4
6
  export * from "./types";
package/dist/api/index.js CHANGED
@@ -13,8 +13,11 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
13
13
  var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
+ var __importDefault = (this && this.__importDefault) || function (mod) {
17
+ return (mod && mod.__esModule) ? mod : { "default": mod };
18
+ };
16
19
  Object.defineProperty(exports, "__esModule", { value: true });
17
- 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;
18
21
  var formats_1 = require("./formats");
19
22
  Object.defineProperty(exports, "getFormat", { enumerable: true, get: function () { return formats_1.getFormat; } });
20
23
  var getCatalogs_1 = require("./catalog/getCatalogs");
@@ -22,4 +25,8 @@ Object.defineProperty(exports, "getCatalogForFile", { enumerable: true, get: fun
22
25
  Object.defineProperty(exports, "getCatalogs", { enumerable: true, get: function () { return getCatalogs_1.getCatalogs; } });
23
26
  var compile_1 = require("./compile");
24
27
  Object.defineProperty(exports, "createCompiledCatalog", { enumerable: true, get: function () { return compile_1.createCompiledCatalog; } });
28
+ var babel_1 = require("./extractors/babel");
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; } });
25
32
  __exportStar(require("./types"), exports);
@@ -44,9 +44,16 @@ async function command(config, options) {
44
44
  config.service.name &&
45
45
  config.service.name.length) {
46
46
  const moduleName = config.service.name.charAt(0).toLowerCase() + config.service.name.slice(1);
47
- await import(`./services/${moduleName}`)
48
- .then((module) => module.default(config, options))
49
- .catch((err) => console.error(`Can't load service module ${moduleName}`, err));
47
+ try {
48
+ const module = require(`./services/${moduleName}`);
49
+ await module
50
+ .default(config, options)
51
+ .then(console.log)
52
+ .catch(console.error);
53
+ }
54
+ catch (err) {
55
+ console.error(`Can't load service module ${moduleName}`, err);
56
+ }
50
57
  }
51
58
  return commandSuccess;
52
59
  }
@@ -1,3 +1,3 @@
1
1
  import { LinguiConfigNormalized } from "@lingui/conf";
2
2
  import { CliExtractOptions } from "../lingui-extract";
3
- export default function syncProcess(config: LinguiConfigNormalized, options: CliExtractOptions): void;
3
+ export default function syncProcess(config: LinguiConfigNormalized, options: CliExtractOptions): Promise<string>;
@@ -23,25 +23,27 @@ const getTargetLocales = (config) => {
23
23
  return config.locales.filter((value) => value != sourceLocale && value != pseudoLocale);
24
24
  };
25
25
  // Main sync method, call "Init" or "Sync" depending on the project context
26
- function syncProcess(config, options) {
26
+ async function syncProcess(config, options) {
27
27
  if (config.format != "po") {
28
28
  console.error(`\n----------\nTranslation.io service is only compatible with the "po" format. Please update your Lingui configuration accordingly.\n----------`);
29
29
  process.exit(1);
30
30
  }
31
- const successCallback = (project) => {
32
- console.log(`\n----------\nProject successfully synchronized. Please use this URL to translate: ${project.url}\n----------`);
33
- };
34
- const failCallback = (errors) => {
35
- console.error(`\n----------\nSynchronization with Translation.io failed: ${errors.join(", ")}\n----------`);
36
- };
37
- init(config, options, successCallback, (errors) => {
38
- if (errors.length &&
39
- errors[0] === "This project has already been initialized.") {
40
- sync(config, options, successCallback, failCallback);
41
- }
42
- else {
43
- failCallback(errors);
44
- }
31
+ return await new Promise((resolve, reject) => {
32
+ const successCallback = (project) => {
33
+ resolve(`\n----------\nProject successfully synchronized. Please use this URL to translate: ${project.url}\n----------`);
34
+ };
35
+ const failCallback = (errors) => {
36
+ reject(`\n----------\nSynchronization with Translation.io failed: ${errors.join(", ")}\n----------`);
37
+ };
38
+ init(config, options, successCallback, (errors) => {
39
+ if (errors.length &&
40
+ errors[0] === "This project has already been initialized.") {
41
+ sync(config, options, successCallback, failCallback);
42
+ }
43
+ else {
44
+ failCallback(errors);
45
+ }
46
+ });
45
47
  });
46
48
  }
47
49
  exports.default = syncProcess;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lingui/cli",
3
- "version": "4.0.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.0.0",
56
- "@lingui/conf": "4.0.0",
57
- "@lingui/core": "4.0.0",
58
- "@lingui/format-po": "4.0.0",
59
- "@lingui/message-utils": "4.0.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.0.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": "998996381f5e5a458c2eccf650f949d8c5d8ac89"
90
+ "gitHead": "dad2c065901a9574bc117a8ef7ed75465ad713d0"
90
91
  }