@lingui/cli 4.1.0 → 4.1.2
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/dist/api/catalog/getCatalogDependentFiles.d.ts +5 -0
- package/dist/api/catalog/getCatalogDependentFiles.js +31 -0
- package/dist/api/catalog/getFallbackListForLocale.d.ts +2 -0
- package/dist/api/catalog/getFallbackListForLocale.js +15 -0
- package/dist/api/catalog/getTranslationsForCatalog.js +6 -13
- package/dist/api/catalog.d.ts +1 -0
- package/dist/api/catalog.js +6 -5
- package/dist/api/index.d.ts +1 -0
- package/dist/api/index.js +3 -1
- package/package.json +11 -9
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.getCatalogDependentFiles = void 0;
|
|
7
|
+
const getFallbackListForLocale_1 = require("./getFallbackListForLocale");
|
|
8
|
+
const pathe_1 = __importDefault(require("pathe"));
|
|
9
|
+
const promises_1 = __importDefault(require("node:fs/promises"));
|
|
10
|
+
const fileExists = async (path) => !!(await promises_1.default.stat(path).catch(() => false));
|
|
11
|
+
/**
|
|
12
|
+
* Return all files catalog implicitly depends on.
|
|
13
|
+
*/
|
|
14
|
+
async function getCatalogDependentFiles(catalog, locale) {
|
|
15
|
+
const files = new Set([catalog.templateFile]);
|
|
16
|
+
(0, getFallbackListForLocale_1.getFallbackListForLocale)(catalog.config.fallbackLocales, locale).forEach((locale) => {
|
|
17
|
+
files.add(catalog.getFilename(locale));
|
|
18
|
+
});
|
|
19
|
+
if (catalog.config.sourceLocale && locale !== catalog.config.sourceLocale) {
|
|
20
|
+
files.add(catalog.getFilename(catalog.config.sourceLocale));
|
|
21
|
+
}
|
|
22
|
+
const out = [];
|
|
23
|
+
for (const file of files) {
|
|
24
|
+
const filePath = pathe_1.default.join(catalog.config.rootDir, file);
|
|
25
|
+
if (await fileExists(filePath)) {
|
|
26
|
+
out.push(filePath);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
return out;
|
|
30
|
+
}
|
|
31
|
+
exports.getCatalogDependentFiles = getCatalogDependentFiles;
|
|
@@ -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 =
|
|
30
|
-
|
|
31
|
-
if (!fL)
|
|
30
|
+
const fL = (0, getFallbackListForLocale_1.getFallbackListForLocale)(fallbackLocales, _locale);
|
|
31
|
+
if (!fL.length)
|
|
32
32
|
return null;
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
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));
|
package/dist/api/catalog.d.ts
CHANGED
|
@@ -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
|
/**
|
package/dist/api/catalog.js
CHANGED
|
@@ -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 =
|
|
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
|
-
|
|
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 = {};
|
package/dist/api/index.d.ts
CHANGED
|
@@ -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.
|
|
3
|
+
"version": "4.1.2",
|
|
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.
|
|
56
|
-
"@lingui/conf": "4.1.
|
|
57
|
-
"@lingui/core": "4.1.
|
|
58
|
-
"@lingui/format-po": "4.1.
|
|
59
|
-
"@lingui/message-utils": "4.1.
|
|
56
|
+
"@lingui/babel-plugin-extract-messages": "4.1.2",
|
|
57
|
+
"@lingui/conf": "4.1.2",
|
|
58
|
+
"@lingui/core": "4.1.2",
|
|
59
|
+
"@lingui/format-po": "4.1.2",
|
|
60
|
+
"@lingui/message-utils": "4.1.2",
|
|
60
61
|
"babel-plugin-macros": "^3.0.1",
|
|
61
62
|
"chalk": "^4.1.0",
|
|
62
63
|
"chokidar": "3.5.1",
|
|
@@ -70,6 +71,7 @@
|
|
|
70
71
|
"micromatch": "4.0.2",
|
|
71
72
|
"normalize-path": "^3.0.0",
|
|
72
73
|
"ora": "^5.1.0",
|
|
74
|
+
"pathe": "^1.1.0",
|
|
73
75
|
"pkg-up": "^3.1.0",
|
|
74
76
|
"pofile": "^1.1.4",
|
|
75
77
|
"pseudolocale": "^2.0.0",
|
|
@@ -78,7 +80,7 @@
|
|
|
78
80
|
},
|
|
79
81
|
"devDependencies": {
|
|
80
82
|
"@lingui/jest-mocks": "*",
|
|
81
|
-
"@lingui/macro": "4.1.
|
|
83
|
+
"@lingui/macro": "4.1.2",
|
|
82
84
|
"@types/convert-source-map": "^2.0.0",
|
|
83
85
|
"@types/glob": "^8.1.0",
|
|
84
86
|
"@types/micromatch": "^4.0.1",
|
|
@@ -86,5 +88,5 @@
|
|
|
86
88
|
"mock-fs": "^5.2.0",
|
|
87
89
|
"mockdate": "^3.0.5"
|
|
88
90
|
},
|
|
89
|
-
"gitHead": "
|
|
91
|
+
"gitHead": "0cec936f2cbc190fdf8fe0581fe808e6c8fe3d20"
|
|
90
92
|
}
|