@lingui/cli 5.9.2 → 6.0.0-next.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/dist/api/ProgramExit.js +1 -5
- package/dist/api/catalog/extractFromFiles.d.ts +4 -4
- package/dist/api/catalog/extractFromFiles.js +38 -32
- package/dist/api/catalog/getCatalogDependentFiles.d.ts +1 -1
- package/dist/api/catalog/getCatalogDependentFiles.js +8 -47
- package/dist/api/catalog/getCatalogs.d.ts +2 -2
- package/dist/api/catalog/getCatalogs.js +35 -44
- package/dist/api/catalog/getFallbackListForLocale.js +5 -8
- package/dist/api/catalog/getTranslationsForCatalog.d.ts +1 -1
- package/dist/api/catalog/getTranslationsForCatalog.js +9 -13
- package/dist/api/catalog/mergeCatalog.d.ts +3 -3
- package/dist/api/catalog/mergeCatalog.js +13 -21
- package/dist/api/catalog.d.ts +15 -15
- package/dist/api/catalog.js +51 -48
- package/dist/api/compile/compileLocale.d.ts +3 -3
- package/dist/api/compile/compileLocale.js +28 -33
- package/dist/api/compile.js +13 -49
- package/dist/api/extractors/babel.d.ts +2 -2
- package/dist/api/extractors/babel.js +52 -45
- package/dist/api/extractors/index.js +6 -13
- package/dist/api/formats/formatterWrapper.d.ts +2 -2
- package/dist/api/formats/formatterWrapper.js +10 -12
- package/dist/api/formats/index.d.ts +3 -4
- package/dist/api/formats/index.js +5 -44
- package/dist/api/getPathsForCompileWatcher.d.ts +7 -0
- package/dist/api/getPathsForCompileWatcher.js +15 -0
- package/dist/api/getPathsForExtractWatcher.d.ts +8 -0
- package/dist/api/getPathsForExtractWatcher.js +14 -0
- package/dist/api/help.js +5 -7
- package/dist/api/index.d.ts +7 -7
- package/dist/api/index.js +7 -36
- package/dist/api/logger.d.ts +1 -1
- package/dist/api/logger.js +1 -2
- package/dist/api/messages.d.ts +2 -2
- package/dist/api/messages.js +5 -12
- package/dist/api/pseudoLocalize.js +3 -9
- package/dist/api/resolveWorkersOptions.js +3 -9
- package/dist/api/rethrownError.js +2 -5
- package/dist/api/stats.d.ts +3 -2
- package/dist/api/stats.js +7 -16
- package/dist/api/typedPool.d.ts +6 -0
- package/dist/api/typedPool.js +16 -0
- package/dist/api/types.js +1 -2
- package/dist/api/utils.d.ts +2 -2
- package/dist/api/utils.js +24 -41
- package/dist/api/workerLogger.d.ts +2 -2
- package/dist/api/workerLogger.js +2 -8
- package/dist/api/workerPools.d.ts +3 -0
- package/dist/api/workerPools.js +7 -0
- package/dist/extract-experimental/buildIncludeDepsFilter.js +1 -4
- package/dist/extract-experimental/bundleSource.d.ts +3 -2
- package/dist/extract-experimental/bundleSource.js +10 -13
- package/dist/extract-experimental/constants.js +2 -5
- package/dist/extract-experimental/extractFromBundleAndWrite.d.ts +3 -4
- package/dist/extract-experimental/extractFromBundleAndWrite.js +11 -17
- package/dist/extract-experimental/getExperimentalCatalogs.d.ts +4 -3
- package/dist/extract-experimental/getExperimentalCatalogs.js +10 -15
- package/dist/extract-experimental/linguiEsbuildPlugin.js +12 -19
- package/dist/extract-experimental/resolveCatalogPath.d.ts +1 -1
- package/dist/extract-experimental/resolveCatalogPath.js +7 -14
- package/dist/extract-experimental/resolveTemplatePath.js +7 -10
- package/dist/extract-experimental/workers/extractWorker.d.ts +5 -3
- package/dist/extract-experimental/workers/extractWorker.js +7 -10
- package/dist/extract-experimental/workers/extractWorkerWrapper.prod.d.ts +8 -0
- package/dist/extract-experimental/workers/extractWorkerWrapper.prod.js +2 -0
- package/dist/extract-experimental/writeCatalogs.d.ts +2 -2
- package/dist/extract-experimental/writeCatalogs.js +15 -22
- package/dist/index.js +1 -5
- package/dist/lingui-compile.d.ts +1 -1
- package/dist/lingui-compile.js +45 -59
- package/dist/lingui-extract-experimental.d.ts +3 -2
- package/dist/lingui-extract-experimental.js +58 -62
- package/dist/lingui-extract-template.d.ts +5 -4
- package/dist/lingui-extract-template.js +25 -27
- package/dist/lingui-extract.d.ts +3 -4
- package/dist/lingui-extract.js +62 -69
- package/dist/lingui.js +5 -10
- package/dist/services/translationIO/segment-converters.d.ts +1 -1
- package/dist/services/translationIO/segment-converters.js +16 -20
- package/dist/services/translationIO/translationio-api.d.ts +11 -7
- package/dist/services/translationIO/translationio-api.js +2 -19
- package/dist/services/translationIO.d.ts +4 -4
- package/dist/services/translationIO.js +28 -35
- package/dist/workers/compileWorker.d.ts +8 -11
- package/dist/workers/compileWorker.js +30 -36
- package/dist/workers/compileWorkerWrapper.prod.d.ts +7 -0
- package/dist/workers/compileWorkerWrapper.prod.js +2 -0
- package/dist/workers/extractWorker.d.ts +2 -3
- package/dist/workers/extractWorker.js +5 -12
- package/dist/workers/extractWorkerWrapper.prod.d.ts +6 -0
- package/dist/workers/extractWorkerWrapper.prod.js +2 -0
- package/package.json +26 -43
- package/dist/api/extractWorkerPool.d.ts +0 -1
- package/dist/api/extractWorkerPool.js +0 -8
- package/dist/api/extractors/typescript.d.ts +0 -3
- package/dist/api/extractors/typescript.js +0 -11
- package/dist/extract-experimental/getEntryPoints.d.ts +0 -1
- package/dist/extract-experimental/getEntryPoints.js +0 -7
package/dist/api/ProgramExit.js
CHANGED
|
@@ -1,10 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ProgramExit = void 0;
|
|
4
|
-
class ProgramExit extends Error {
|
|
1
|
+
export class ProgramExit extends Error {
|
|
5
2
|
constructor() {
|
|
6
3
|
super();
|
|
7
4
|
this.name = "ProgramExit";
|
|
8
5
|
}
|
|
9
6
|
}
|
|
10
|
-
exports.ProgramExit = ProgramExit;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { ExtractedMessage, LinguiConfigNormalized } from "@lingui/conf";
|
|
2
|
-
import { ExtractedCatalogType } from "../types";
|
|
3
|
-
import { ExtractWorkerPool } from "../
|
|
4
|
-
export declare function extractFromFiles(paths: string[], config: LinguiConfigNormalized): Promise<ExtractedCatalogType>;
|
|
2
|
+
import { ExtractedCatalogType } from "../types.js";
|
|
3
|
+
import { ExtractWorkerPool } from "../workerPools.js";
|
|
4
|
+
export declare function extractFromFiles(paths: string[], config: LinguiConfigNormalized): Promise<ExtractedCatalogType | undefined>;
|
|
5
5
|
export declare function mergeExtractedMessage(next: ExtractedMessage, messages: ExtractedCatalogType, config: LinguiConfigNormalized): void;
|
|
6
|
-
export declare function extractFromFilesWithWorkerPool(workerPool: ExtractWorkerPool, paths: string[], config: LinguiConfigNormalized): Promise<ExtractedCatalogType>;
|
|
6
|
+
export declare function extractFromFilesWithWorkerPool(workerPool: ExtractWorkerPool, paths: string[], config: LinguiConfigNormalized): Promise<ExtractedCatalogType | undefined>;
|
|
@@ -1,17 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const extractors_1 = __importDefault(require("../extractors"));
|
|
12
|
-
const utils_1 = require("../utils");
|
|
1
|
+
import { styleText } from "node:util";
|
|
2
|
+
import path from "path";
|
|
3
|
+
import extract from "../extractors/index.js";
|
|
4
|
+
import { prettyOrigin } from "../utils.js";
|
|
5
|
+
function mergeOrigins(prev, next) {
|
|
6
|
+
if (!next) {
|
|
7
|
+
return prev;
|
|
8
|
+
}
|
|
9
|
+
return [...prev, next].sort((a, b) => a[0].localeCompare(b[0]));
|
|
10
|
+
}
|
|
13
11
|
function mergePlaceholders(prev, next) {
|
|
14
|
-
const res =
|
|
12
|
+
const res = { ...prev };
|
|
15
13
|
// Handle case where next is null or undefined
|
|
16
14
|
if (!next)
|
|
17
15
|
return res;
|
|
@@ -26,21 +24,20 @@ function mergePlaceholders(prev, next) {
|
|
|
26
24
|
});
|
|
27
25
|
return res;
|
|
28
26
|
}
|
|
29
|
-
async function extractFromFiles(paths, config) {
|
|
27
|
+
export async function extractFromFiles(paths, config) {
|
|
30
28
|
const messages = {};
|
|
31
29
|
let catalogSuccess = true;
|
|
32
30
|
for (const filename of paths) {
|
|
33
|
-
const fileSuccess = await (
|
|
31
|
+
const fileSuccess = await extract(filename, (next) => {
|
|
34
32
|
mergeExtractedMessage(next, messages, config);
|
|
35
33
|
}, config);
|
|
36
|
-
catalogSuccess
|
|
34
|
+
catalogSuccess &&= fileSuccess;
|
|
37
35
|
}
|
|
38
36
|
if (!catalogSuccess)
|
|
39
37
|
return undefined;
|
|
40
38
|
return messages;
|
|
41
39
|
}
|
|
42
|
-
function mergeExtractedMessage(next, messages, config) {
|
|
43
|
-
var _a;
|
|
40
|
+
export function mergeExtractedMessage(next, messages, config) {
|
|
44
41
|
if (!messages[next.id]) {
|
|
45
42
|
messages[next.id] = {
|
|
46
43
|
message: next.message,
|
|
@@ -52,27 +49,36 @@ function mergeExtractedMessage(next, messages, config) {
|
|
|
52
49
|
}
|
|
53
50
|
const prev = messages[next.id];
|
|
54
51
|
// there might be a case when filename was not mapped from sourcemaps
|
|
55
|
-
const
|
|
56
|
-
?
|
|
57
|
-
|
|
58
|
-
|
|
52
|
+
const nextOrigin = next.origin
|
|
53
|
+
? [
|
|
54
|
+
path.relative(config.rootDir, next.origin[0]).replace(/\\/g, "/"),
|
|
55
|
+
next.origin[1],
|
|
56
|
+
]
|
|
57
|
+
: undefined;
|
|
59
58
|
if (prev.message && next.message && prev.message !== next.message) {
|
|
60
|
-
throw new Error(`Encountered different default translations for message ${
|
|
61
|
-
`\n${
|
|
62
|
-
`\n${
|
|
59
|
+
throw new Error(`Encountered different default translations for message ${styleText("yellow", next.id)}` +
|
|
60
|
+
`\n${styleText("yellow", prettyOrigin(prev.origin))} ${prev.message}` +
|
|
61
|
+
`\n${styleText("yellow", prettyOrigin([nextOrigin || [""]]))} ${next.message}`);
|
|
63
62
|
}
|
|
64
|
-
messages[next.id] =
|
|
63
|
+
messages[next.id] = {
|
|
64
|
+
...prev,
|
|
65
|
+
message: prev.message ?? next.message,
|
|
66
|
+
comments: next.comment
|
|
65
67
|
? [...prev.comments, next.comment].sort()
|
|
66
|
-
: prev.comments,
|
|
68
|
+
: prev.comments,
|
|
69
|
+
origin: mergeOrigins(prev.origin, nextOrigin),
|
|
70
|
+
placeholders: mergePlaceholders(prev.placeholders, next.placeholders),
|
|
71
|
+
};
|
|
67
72
|
}
|
|
68
|
-
async function extractFromFilesWithWorkerPool(workerPool, paths, config) {
|
|
73
|
+
export async function extractFromFilesWithWorkerPool(workerPool, paths, config) {
|
|
69
74
|
const messages = {};
|
|
70
75
|
let catalogSuccess = true;
|
|
71
|
-
|
|
76
|
+
const resolvedConfigPath = config.resolvedConfigPath;
|
|
77
|
+
if (!resolvedConfigPath) {
|
|
72
78
|
throw new Error("Multithreading is only supported when lingui config loaded from file system, not passed by API");
|
|
73
79
|
}
|
|
74
|
-
await Promise.all(paths.map(
|
|
75
|
-
const result = await
|
|
80
|
+
await Promise.all(paths.map(async (filename) => {
|
|
81
|
+
const result = await workerPool.run(filename, resolvedConfigPath);
|
|
76
82
|
if (!result.success) {
|
|
77
83
|
catalogSuccess = false;
|
|
78
84
|
}
|
|
@@ -81,7 +87,7 @@ async function extractFromFilesWithWorkerPool(workerPool, paths, config) {
|
|
|
81
87
|
mergeExtractedMessage(message, messages, config);
|
|
82
88
|
});
|
|
83
89
|
}
|
|
84
|
-
}))
|
|
90
|
+
}));
|
|
85
91
|
if (!catalogSuccess)
|
|
86
92
|
return undefined;
|
|
87
93
|
return messages;
|
|
@@ -1,53 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
-
};
|
|
38
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.getCatalogDependentFiles = getCatalogDependentFiles;
|
|
40
|
-
const getFallbackListForLocale_1 = require("./getFallbackListForLocale");
|
|
41
|
-
const promises_1 = __importDefault(require("node:fs/promises"));
|
|
42
|
-
const node_path_1 = __importDefault(require("node:path"));
|
|
43
|
-
const process = __importStar(require("process"));
|
|
44
|
-
const fileExists = async (path) => !!(await promises_1.default.stat(path).catch(() => false));
|
|
1
|
+
import { getFallbackListForLocale } from "./getFallbackListForLocale.js";
|
|
2
|
+
import fs from "node:fs/promises";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import * as process from "process";
|
|
5
|
+
const fileExists = async (path) => !!(await fs.stat(path).catch(() => false));
|
|
45
6
|
/**
|
|
46
7
|
* Return all files catalog implicitly depends on.
|
|
47
8
|
*/
|
|
48
|
-
async function getCatalogDependentFiles(catalog, locale) {
|
|
9
|
+
export async function getCatalogDependentFiles(catalog, locale) {
|
|
49
10
|
const files = new Set([catalog.templateFile]);
|
|
50
|
-
|
|
11
|
+
getFallbackListForLocale(catalog.config.fallbackLocales, locale).forEach((locale) => {
|
|
51
12
|
files.add(catalog.getFilename(locale));
|
|
52
13
|
});
|
|
53
14
|
if (catalog.config.sourceLocale && locale !== catalog.config.sourceLocale) {
|
|
@@ -55,7 +16,7 @@ async function getCatalogDependentFiles(catalog, locale) {
|
|
|
55
16
|
}
|
|
56
17
|
const out = [];
|
|
57
18
|
for (let file of files) {
|
|
58
|
-
file =
|
|
19
|
+
file = path.isAbsolute(file) ? file : path.join(process.cwd(), file);
|
|
59
20
|
if (await fileExists(file)) {
|
|
60
21
|
out.push(file);
|
|
61
22
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { LinguiConfigNormalized } from "@lingui/conf";
|
|
2
|
-
import { Catalog } from "../catalog";
|
|
2
|
+
import { Catalog } from "../catalog.js";
|
|
3
3
|
/**
|
|
4
4
|
* Parse `config.catalogs` and return a list of configured Catalog instances.
|
|
5
5
|
*/
|
|
@@ -11,4 +11,4 @@ export declare function getMergedCatalogPath(config: LinguiConfigNormalized): Pr
|
|
|
11
11
|
export declare function getCatalogForFile(file: string, catalogs: Catalog[]): {
|
|
12
12
|
locale: string;
|
|
13
13
|
catalog: Catalog;
|
|
14
|
-
};
|
|
14
|
+
} | null;
|
|
@@ -1,32 +1,23 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
exports.getCatalogForFile = getCatalogForFile;
|
|
9
|
-
const glob_1 = require("glob");
|
|
10
|
-
const path_1 = __importDefault(require("path"));
|
|
11
|
-
const catalog_1 = require("../catalog");
|
|
12
|
-
const utils_1 = require("../utils");
|
|
13
|
-
const micromatch_1 = __importDefault(require("micromatch"));
|
|
14
|
-
const formats_1 = require("../formats");
|
|
15
|
-
const getExperimentalCatalogs_1 = require("../../extract-experimental/getExperimentalCatalogs");
|
|
1
|
+
import { globSync } from "node:fs";
|
|
2
|
+
import path from "path";
|
|
3
|
+
import { Catalog } from "../catalog.js";
|
|
4
|
+
import { normalizeRelativePath, PATHSEP, replacePlaceholders, } from "../utils.js";
|
|
5
|
+
import micromatch from "micromatch";
|
|
6
|
+
import { getFormat } from "../formats/index.js";
|
|
7
|
+
import { getExperimentalCatalogs } from "../../extract-experimental/getExperimentalCatalogs.js";
|
|
16
8
|
const NAME_PH = "{name}";
|
|
17
9
|
const LOCALE_PH = "{locale}";
|
|
18
10
|
/**
|
|
19
11
|
* Parse `config.catalogs` and return a list of configured Catalog instances.
|
|
20
12
|
*/
|
|
21
|
-
async function getCatalogs(config) {
|
|
22
|
-
var _a, _b;
|
|
13
|
+
export async function getCatalogs(config) {
|
|
23
14
|
const catalogsConfig = config.catalogs;
|
|
24
15
|
const catalogs = [];
|
|
25
|
-
const format = await
|
|
16
|
+
const format = await getFormat(config.format, config.sourceLocale);
|
|
26
17
|
catalogsConfig.forEach((catalog) => {
|
|
27
18
|
validateCatalogPath(catalog.path, format.getCatalogExtension());
|
|
28
|
-
const include = ensureArray(catalog.include).map(
|
|
29
|
-
const exclude = ensureArray(catalog.exclude).map(
|
|
19
|
+
const include = ensureArray(catalog.include).map(normalizeRelativePath);
|
|
20
|
+
const exclude = ensureArray(catalog.exclude).map(normalizeRelativePath);
|
|
30
21
|
// catalog.path without {name} pattern -> always refers to a single catalog
|
|
31
22
|
if (!catalog.path.includes(NAME_PH)) {
|
|
32
23
|
// Validate that sourcePaths doesn't use {name} pattern either
|
|
@@ -37,33 +28,33 @@ async function getCatalogs(config) {
|
|
|
37
28
|
` Either add {name} pattern to "${catalog.path}" or remove it` +
|
|
38
29
|
` from all source directories.`);
|
|
39
30
|
}
|
|
40
|
-
catalogs.push(new
|
|
31
|
+
catalogs.push(new Catalog({
|
|
41
32
|
name: getCatalogName(catalog.path),
|
|
42
|
-
path:
|
|
33
|
+
path: normalizeRelativePath(catalog.path),
|
|
43
34
|
include,
|
|
44
35
|
exclude,
|
|
45
36
|
format,
|
|
46
37
|
}, config));
|
|
47
38
|
return;
|
|
48
39
|
}
|
|
49
|
-
const patterns = include.map((path) =>
|
|
50
|
-
const candidates =
|
|
51
|
-
|
|
52
|
-
mark: true,
|
|
40
|
+
const patterns = include.map((path) => replacePlaceholders(path, { name: "*" }));
|
|
41
|
+
const candidates = globSync(patterns, {
|
|
42
|
+
exclude,
|
|
53
43
|
});
|
|
54
44
|
candidates.forEach((catalogDir) => {
|
|
55
|
-
const name =
|
|
56
|
-
catalogs.push(new
|
|
45
|
+
const name = path.basename(catalogDir);
|
|
46
|
+
catalogs.push(new Catalog({
|
|
57
47
|
name,
|
|
58
|
-
path:
|
|
59
|
-
include: include.map((path) =>
|
|
60
|
-
exclude: exclude.map((path) =>
|
|
48
|
+
path: normalizeRelativePath(replacePlaceholders(catalog.path, { name })),
|
|
49
|
+
include: include.map((path) => replacePlaceholders(path, { name })),
|
|
50
|
+
exclude: exclude.map((path) => replacePlaceholders(path, { name })),
|
|
61
51
|
format,
|
|
62
52
|
}, config));
|
|
63
53
|
});
|
|
64
54
|
});
|
|
65
|
-
if (
|
|
66
|
-
|
|
55
|
+
if (config.experimental?.extractor &&
|
|
56
|
+
config.experimental.extractor.entries.length) {
|
|
57
|
+
catalogs.push(...(await getExperimentalCatalogs(config, format, config.experimental.extractor)));
|
|
67
58
|
}
|
|
68
59
|
return catalogs;
|
|
69
60
|
}
|
|
@@ -78,17 +69,17 @@ const ensureArray = (value) => {
|
|
|
78
69
|
/**
|
|
79
70
|
* Create catalog for merged messages.
|
|
80
71
|
*/
|
|
81
|
-
async function getMergedCatalogPath(config) {
|
|
82
|
-
const format = await
|
|
72
|
+
export async function getMergedCatalogPath(config) {
|
|
73
|
+
const format = await getFormat(config.format, config.sourceLocale);
|
|
83
74
|
validateCatalogPath(config.catalogsMergePath, format.getCatalogExtension());
|
|
84
|
-
return
|
|
75
|
+
return normalizeRelativePath(config.catalogsMergePath);
|
|
85
76
|
}
|
|
86
|
-
function getCatalogForFile(file, catalogs) {
|
|
77
|
+
export function getCatalogForFile(file, catalogs) {
|
|
87
78
|
for (const catalog of catalogs) {
|
|
88
79
|
const catalogFile = `${catalog.path}${catalog.format.getCatalogExtension()}`;
|
|
89
|
-
const catalogGlob =
|
|
90
|
-
const matchPattern =
|
|
91
|
-
const match =
|
|
80
|
+
const catalogGlob = replacePlaceholders(catalogFile, { locale: "*" });
|
|
81
|
+
const matchPattern = normalizeRelativePath(path.relative(catalog.config.rootDir, catalogGlob)).replace(/(\(|\)|\[|\])/g, "\\$1");
|
|
82
|
+
const match = micromatch.capture(matchPattern, normalizeRelativePath(file));
|
|
92
83
|
if (match) {
|
|
93
84
|
return {
|
|
94
85
|
locale: match[0],
|
|
@@ -105,11 +96,11 @@ function validateCatalogPath(path, extension) {
|
|
|
105
96
|
if (!path.includes(LOCALE_PH)) {
|
|
106
97
|
throw new Error(`Invalid catalog path: ${LOCALE_PH} variable is missing`);
|
|
107
98
|
}
|
|
108
|
-
if (!path.endsWith(
|
|
99
|
+
if (!path.endsWith(PATHSEP)) {
|
|
109
100
|
return;
|
|
110
101
|
}
|
|
111
102
|
const correctPath = path.slice(0, -1);
|
|
112
|
-
const examplePath =
|
|
103
|
+
const examplePath = replacePlaceholders(correctPath, {
|
|
113
104
|
locale: "en",
|
|
114
105
|
}) + extension;
|
|
115
106
|
throw new Error(
|
|
@@ -121,6 +112,6 @@ function validateCatalogPath(path, extension) {
|
|
|
121
112
|
function getCatalogName(filePath) {
|
|
122
113
|
// catalog name is the last directory of catalogPath.
|
|
123
114
|
// If the last part is {locale}, then catalog doesn't have an explicit name
|
|
124
|
-
const
|
|
125
|
-
return
|
|
115
|
+
const name = path.basename(normalizeRelativePath(filePath));
|
|
116
|
+
return name !== LOCALE_PH ? name : undefined;
|
|
126
117
|
}
|
|
@@ -1,14 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getFallbackListForLocale = getFallbackListForLocale;
|
|
4
|
-
function getFallbackListForLocale(fallbackLocales, locale) {
|
|
1
|
+
export function getFallbackListForLocale(fallbackLocales, locale) {
|
|
5
2
|
const fL = [];
|
|
6
|
-
if (fallbackLocales
|
|
7
|
-
const mapping = fallbackLocales
|
|
3
|
+
if (fallbackLocales?.[locale]) {
|
|
4
|
+
const mapping = fallbackLocales?.[locale];
|
|
8
5
|
Array.isArray(mapping) ? fL.push(...mapping) : fL.push(mapping);
|
|
9
6
|
}
|
|
10
|
-
if (typeof
|
|
11
|
-
locale !==
|
|
7
|
+
if (typeof fallbackLocales?.default === "string" &&
|
|
8
|
+
locale !== fallbackLocales?.default) {
|
|
12
9
|
fL.push(fallbackLocales.default);
|
|
13
10
|
}
|
|
14
11
|
return fL;
|
|
@@ -1,19 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.getTranslationsForCatalog = getTranslationsForCatalog;
|
|
4
|
-
const getFallbackListForLocale_1 = require("./getFallbackListForLocale");
|
|
5
|
-
async function getTranslationsForCatalog(catalog, locale, options) {
|
|
1
|
+
import { getFallbackListForLocale } from "./getFallbackListForLocale.js";
|
|
2
|
+
export async function getTranslationsForCatalog(catalog, locale, options) {
|
|
6
3
|
const locales = new Set([
|
|
7
4
|
locale,
|
|
8
5
|
options.sourceLocale,
|
|
9
|
-
...
|
|
6
|
+
...getFallbackListForLocale(options.fallbackLocales, locale),
|
|
10
7
|
]);
|
|
11
8
|
const [catalogs, template] = await Promise.all([
|
|
12
9
|
catalog.readAll(Array.from(locales)),
|
|
13
10
|
catalog.readTemplate(),
|
|
14
11
|
]);
|
|
15
12
|
const sourceLocaleCatalog = catalogs[options.sourceLocale] || {};
|
|
16
|
-
const input =
|
|
13
|
+
const input = { ...template, ...sourceLocaleCatalog, ...catalogs[locale] };
|
|
17
14
|
const missing = [];
|
|
18
15
|
const messages = Object.keys(input).reduce((acc, key) => {
|
|
19
16
|
acc[key] = getTranslation(catalogs, input[key], locale, key, (event) => {
|
|
@@ -27,20 +24,19 @@ async function getTranslationsForCatalog(catalog, locale, options) {
|
|
|
27
24
|
};
|
|
28
25
|
}
|
|
29
26
|
function sourceLocaleFallback(catalog, key) {
|
|
30
|
-
if (!
|
|
31
|
-
return
|
|
27
|
+
if (!catalog?.[key]) {
|
|
28
|
+
return undefined;
|
|
32
29
|
}
|
|
33
30
|
return catalog[key].translation || catalog[key].message;
|
|
34
31
|
}
|
|
35
32
|
function getTranslation(catalogs, msg, locale, key, onMissing, options) {
|
|
36
33
|
const { fallbackLocales, sourceLocale } = options;
|
|
37
34
|
const getTranslation = (_locale) => {
|
|
38
|
-
var _a;
|
|
39
35
|
const localeCatalog = catalogs[_locale];
|
|
40
|
-
return
|
|
36
|
+
return localeCatalog?.[key]?.translation;
|
|
41
37
|
};
|
|
42
38
|
const getMultipleFallbacks = (_locale) => {
|
|
43
|
-
const fL =
|
|
39
|
+
const fL = getFallbackListForLocale(fallbackLocales, _locale);
|
|
44
40
|
if (!fL.length)
|
|
45
41
|
return null;
|
|
46
42
|
for (const fallbackLocale of fL) {
|
|
@@ -66,7 +62,7 @@ function getTranslation(catalogs, msg, locale, key, onMissing, options) {
|
|
|
66
62
|
if (!translation) {
|
|
67
63
|
onMissing({
|
|
68
64
|
id: key,
|
|
69
|
-
source: msg.message || sourceLocaleFallback(catalogs[sourceLocale], key),
|
|
65
|
+
source: msg.message || sourceLocaleFallback(catalogs[sourceLocale], key) || "",
|
|
70
66
|
});
|
|
71
67
|
}
|
|
72
68
|
return (translation ||
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type { MergeOptions } from "../catalog";
|
|
2
|
-
import { CatalogType, ExtractedCatalogType } from "../types";
|
|
3
|
-
export declare function mergeCatalog(prevCatalog: CatalogType, nextCatalog: ExtractedCatalogType, forSourceLocale: boolean, options: MergeOptions): CatalogType;
|
|
1
|
+
import type { MergeOptions } from "../catalog.js";
|
|
2
|
+
import { CatalogType, ExtractedCatalogType } from "../types.js";
|
|
3
|
+
export declare function mergeCatalog(prevCatalog: CatalogType | undefined, nextCatalog: ExtractedCatalogType, forSourceLocale: boolean, options: MergeOptions): CatalogType;
|
|
@@ -1,27 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var t = {};
|
|
4
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
5
|
-
t[p] = s[p];
|
|
6
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
7
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
8
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
9
|
-
t[p[i]] = s[p[i]];
|
|
10
|
-
}
|
|
11
|
-
return t;
|
|
12
|
-
};
|
|
13
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
-
exports.mergeCatalog = mergeCatalog;
|
|
15
|
-
function mergeCatalog(prevCatalog, nextCatalog, forSourceLocale, options) {
|
|
1
|
+
export function mergeCatalog(prevCatalog, nextCatalog, forSourceLocale, options) {
|
|
2
|
+
prevCatalog = prevCatalog || {};
|
|
16
3
|
const nextKeys = Object.keys(nextCatalog);
|
|
17
|
-
const prevKeys = Object.keys(prevCatalog
|
|
4
|
+
const prevKeys = Object.keys(prevCatalog);
|
|
18
5
|
const newKeys = nextKeys.filter((key) => !prevKeys.includes(key));
|
|
19
6
|
const mergeKeys = nextKeys.filter((key) => prevKeys.includes(key));
|
|
20
7
|
const obsoleteKeys = prevKeys.filter((key) => !nextKeys.includes(key));
|
|
21
8
|
// Initialize new catalog with new keys
|
|
22
9
|
const newMessages = Object.fromEntries(newKeys.map((key) => [
|
|
23
10
|
key,
|
|
24
|
-
|
|
11
|
+
{
|
|
12
|
+
translation: forSourceLocale ? nextCatalog[key].message || key : "",
|
|
13
|
+
...nextCatalog[key],
|
|
14
|
+
},
|
|
25
15
|
]));
|
|
26
16
|
// Merge translations from previous catalog
|
|
27
17
|
const mergedMessages = Object.fromEntries(mergeKeys.map((key) => {
|
|
@@ -31,15 +21,17 @@ function mergeCatalog(prevCatalog, nextCatalog, forSourceLocale, options) {
|
|
|
31
21
|
const translation = updateFromDefaults
|
|
32
22
|
? nextCatalog[key].message || key
|
|
33
23
|
: prevCatalog[key].translation;
|
|
34
|
-
const _a = nextCatalog[key], { obsolete } = _a, rest = __rest(_a, ["obsolete"]);
|
|
35
24
|
const { extra } = prevCatalog[key];
|
|
36
|
-
return [key,
|
|
25
|
+
return [key, { ...extra, ...nextCatalog[key], translation }];
|
|
37
26
|
}));
|
|
38
27
|
// Mark all remaining translations as obsolete
|
|
39
28
|
// Only if *options.files* is not provided
|
|
40
29
|
const obsoleteMessages = Object.fromEntries(obsoleteKeys.map((key) => [
|
|
41
30
|
key,
|
|
42
|
-
|
|
31
|
+
{
|
|
32
|
+
...prevCatalog[key],
|
|
33
|
+
...(options.files ? {} : { obsolete: true }),
|
|
34
|
+
},
|
|
43
35
|
]));
|
|
44
|
-
return
|
|
36
|
+
return { ...newMessages, ...mergedMessages, ...obsoleteMessages };
|
|
45
37
|
}
|
package/dist/api/catalog.d.ts
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
import { LinguiConfigNormalized, OrderBy, OrderByFn } from "@lingui/conf";
|
|
2
|
-
import { FormatterWrapper } from "./formats";
|
|
3
|
-
import { CompiledCatalogNamespace } from "./compile";
|
|
4
|
-
import { GetTranslationsOptions } from "./catalog/getTranslationsForCatalog";
|
|
5
|
-
import { AllCatalogsType, CatalogType, ExtractedCatalogType } from "./types";
|
|
6
|
-
import { ExtractWorkerPool } from "./
|
|
2
|
+
import { FormatterWrapper } from "./formats/index.js";
|
|
3
|
+
import { CompiledCatalogNamespace } from "./compile.js";
|
|
4
|
+
import { GetTranslationsOptions } from "./catalog/getTranslationsForCatalog.js";
|
|
5
|
+
import { AllCatalogsType, CatalogType, ExtractedCatalogType } from "./types.js";
|
|
6
|
+
import { ExtractWorkerPool } from "./workerPools.js";
|
|
7
7
|
export type MakeOptions = {
|
|
8
8
|
files?: string[];
|
|
9
9
|
clean: boolean;
|
|
10
10
|
overwrite: boolean;
|
|
11
|
-
locale
|
|
12
|
-
orderBy
|
|
11
|
+
locale?: string[];
|
|
12
|
+
orderBy: OrderBy;
|
|
13
13
|
workerPool?: ExtractWorkerPool;
|
|
14
14
|
};
|
|
15
15
|
export type MakeTemplateOptions = {
|
|
16
16
|
files?: string[];
|
|
17
|
-
orderBy
|
|
17
|
+
orderBy: OrderBy;
|
|
18
18
|
workerPool?: ExtractWorkerPool;
|
|
19
19
|
};
|
|
20
20
|
export type MergeOptions = {
|
|
@@ -36,7 +36,7 @@ export declare class Catalog {
|
|
|
36
36
|
include: Array<string>;
|
|
37
37
|
exclude: Array<string>;
|
|
38
38
|
format: FormatterWrapper;
|
|
39
|
-
templateFile
|
|
39
|
+
templateFile: string;
|
|
40
40
|
constructor({ name, path, include, templatePath, format, exclude }: CatalogProps, config: LinguiConfigNormalized);
|
|
41
41
|
getFilename(locale: string): string;
|
|
42
42
|
make(options: MakeOptions): Promise<AllCatalogsType | false>;
|
|
@@ -52,21 +52,21 @@ export declare class Catalog {
|
|
|
52
52
|
[k: string]: CatalogType;
|
|
53
53
|
};
|
|
54
54
|
getTranslations(locale: string, options: GetTranslationsOptions): Promise<{
|
|
55
|
-
missing: import("./catalog/getTranslationsForCatalog").TranslationMissingEvent[];
|
|
55
|
+
missing: import("./catalog/getTranslationsForCatalog.js").TranslationMissingEvent[];
|
|
56
56
|
messages: {
|
|
57
57
|
[id: string]: string;
|
|
58
58
|
};
|
|
59
59
|
}>;
|
|
60
60
|
write(locale: string, messages: CatalogType): Promise<[created: boolean, filename: string]>;
|
|
61
61
|
writeTemplate(messages: CatalogType): Promise<void>;
|
|
62
|
-
read(locale: string): Promise<CatalogType>;
|
|
62
|
+
read(locale: string): Promise<CatalogType | undefined>;
|
|
63
63
|
readAll(locales?: string[]): Promise<AllCatalogsType>;
|
|
64
|
-
readTemplate(): Promise<CatalogType>;
|
|
64
|
+
readTemplate(): Promise<CatalogType | undefined>;
|
|
65
65
|
get sourcePaths(): string[];
|
|
66
66
|
get localeDir(): string;
|
|
67
|
-
get locales(): string[];
|
|
67
|
+
get locales(): string[] & never[];
|
|
68
68
|
}
|
|
69
|
-
export declare function cleanObsolete<T extends
|
|
70
|
-
export declare function order<T extends
|
|
69
|
+
export declare function cleanObsolete<T extends CatalogType>(messages: T): T;
|
|
70
|
+
export declare function order<T extends CatalogType>(by: OrderBy, catalog: T): T;
|
|
71
71
|
export declare function writeCompiled(path: string, locale: string, compiledCatalog: string, namespace?: CompiledCatalogNamespace): Promise<string>;
|
|
72
72
|
export declare const orderByMessage: OrderByFn;
|