@lingui/cli 5.9.1 → 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 +48 -45
- 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
|
@@ -1,21 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createSegmentFromLinguiItem = createSegmentFromLinguiItem;
|
|
4
|
-
exports.createLinguiItemFromSegment = createLinguiItemFromSegment;
|
|
5
|
-
const generateMessageId_1 = require("@lingui/message-utils/generateMessageId");
|
|
1
|
+
import { generateMessageId } from "@lingui/message-utils/generateMessageId";
|
|
6
2
|
const EXPLICIT_ID_FLAG = "js-lingui-explicit-id";
|
|
7
3
|
const EXPLICIT_ID_AND_CONTEXT_FLAG = "js-lingui-explicit-id-and-context";
|
|
8
4
|
function isGeneratedId(id, message) {
|
|
9
|
-
return id ===
|
|
5
|
+
return id === generateMessageId(message.message, message.context);
|
|
10
6
|
}
|
|
11
7
|
const joinOrigin = (origin) => origin.join(":");
|
|
12
8
|
const splitOrigin = (origin) => {
|
|
13
9
|
const [file, line] = origin.split(":");
|
|
14
10
|
return [file, line ? Number(line) : null];
|
|
15
11
|
};
|
|
16
|
-
function createSegmentFromLinguiItem(key, item) {
|
|
12
|
+
export function createSegmentFromLinguiItem(key, item) {
|
|
17
13
|
const itemHasExplicitId = !isGeneratedId(key, item);
|
|
18
|
-
const itemHasContext = !!item.context;
|
|
19
14
|
const segment = {
|
|
20
15
|
type: "source", // No way to edit text for source language (inside code), so not using "key" here
|
|
21
16
|
source: "",
|
|
@@ -25,12 +20,12 @@ function createSegmentFromLinguiItem(key, item) {
|
|
|
25
20
|
};
|
|
26
21
|
// For segment.source & segment.context, we must remain compatible with projects created/synced before Lingui V4
|
|
27
22
|
if (itemHasExplicitId) {
|
|
28
|
-
segment.source = item.message || item.translation;
|
|
23
|
+
segment.source = item.message || item.translation || "";
|
|
29
24
|
segment.context = key;
|
|
30
25
|
}
|
|
31
26
|
else {
|
|
32
|
-
segment.source = item.message || item.translation;
|
|
33
|
-
if (
|
|
27
|
+
segment.source = item.message || item.translation || "";
|
|
28
|
+
if (item.context) {
|
|
34
29
|
segment.context = item.context;
|
|
35
30
|
}
|
|
36
31
|
}
|
|
@@ -40,7 +35,7 @@ function createSegmentFromLinguiItem(key, item) {
|
|
|
40
35
|
// Since Lingui v4, when using explicit IDs, Lingui automatically adds 'js-lingui-explicit-id' to the extractedComments array
|
|
41
36
|
const comments = [];
|
|
42
37
|
if (itemHasExplicitId) {
|
|
43
|
-
if (
|
|
38
|
+
if (item.context) {
|
|
44
39
|
// segment.context is already used for the explicit ID, so we need to pass the context (for translators) in segment.comment
|
|
45
40
|
comments.push(item.context, EXPLICIT_ID_AND_CONTEXT_FLAG);
|
|
46
41
|
}
|
|
@@ -51,30 +46,31 @@ function createSegmentFromLinguiItem(key, item) {
|
|
|
51
46
|
segment.comment = [...comments, ...(item.comments || [])].join(" | ");
|
|
52
47
|
return segment;
|
|
53
48
|
}
|
|
54
|
-
function createLinguiItemFromSegment(segment) {
|
|
55
|
-
|
|
56
|
-
const
|
|
57
|
-
const segmentHasExplicitIdAndContext = (_b = segment.comment) === null || _b === void 0 ? void 0 : _b.includes(EXPLICIT_ID_AND_CONTEXT_FLAG);
|
|
49
|
+
export function createLinguiItemFromSegment(segment) {
|
|
50
|
+
const segmentHasExplicitId = segment.comment?.includes(EXPLICIT_ID_FLAG);
|
|
51
|
+
const segmentHasExplicitIdAndContext = segment.comment?.includes(EXPLICIT_ID_AND_CONTEXT_FLAG);
|
|
58
52
|
const item = {
|
|
59
53
|
translation: segment.target,
|
|
60
|
-
origin:
|
|
54
|
+
origin: segment.references?.length
|
|
61
55
|
? segment.references.map(splitOrigin)
|
|
62
56
|
: [],
|
|
63
57
|
message: segment.source,
|
|
64
58
|
comments: [],
|
|
59
|
+
placeholders: {},
|
|
65
60
|
};
|
|
66
|
-
let id
|
|
61
|
+
let id;
|
|
67
62
|
if (segmentHasExplicitId || segmentHasExplicitIdAndContext) {
|
|
68
63
|
id = segment.context;
|
|
69
64
|
}
|
|
70
65
|
else {
|
|
71
|
-
id =
|
|
66
|
+
id = generateMessageId(segment.source, segment.context);
|
|
72
67
|
item.context = segment.context;
|
|
73
68
|
}
|
|
74
69
|
if (segment.comment) {
|
|
75
70
|
item.comments = segment.comment.split(" | ").filter(
|
|
76
71
|
// drop flags from comments
|
|
77
|
-
(comment) => comment !== EXPLICIT_ID_AND_CONTEXT_FLAG &&
|
|
72
|
+
(comment) => comment !== EXPLICIT_ID_AND_CONTEXT_FLAG &&
|
|
73
|
+
comment !== EXPLICIT_ID_FLAG);
|
|
78
74
|
// We recompose a target PO Item that is consistent with the source PO Item
|
|
79
75
|
if (segmentHasExplicitIdAndContext) {
|
|
80
76
|
item.context = item.comments.shift();
|
|
@@ -27,13 +27,6 @@ export type TranslationIoProject = {
|
|
|
27
27
|
name: string;
|
|
28
28
|
url: string;
|
|
29
29
|
};
|
|
30
|
-
export type TranslationIoResponse = {
|
|
31
|
-
errors?: string[];
|
|
32
|
-
project?: TranslationIoProject;
|
|
33
|
-
segments?: {
|
|
34
|
-
[locale: string]: TranslationIoSegment[];
|
|
35
|
-
};
|
|
36
|
-
};
|
|
37
30
|
export type FetchResult<T> = {
|
|
38
31
|
data: T;
|
|
39
32
|
error: undefined;
|
|
@@ -44,5 +37,16 @@ export type FetchResult<T> = {
|
|
|
44
37
|
};
|
|
45
38
|
data: undefined;
|
|
46
39
|
};
|
|
40
|
+
export type TranslationIoResponse = TranslationIoErrorResponse | TranslationProjectResponse;
|
|
41
|
+
type TranslationIoErrorResponse = {
|
|
42
|
+
errors: string[];
|
|
43
|
+
};
|
|
44
|
+
type TranslationProjectResponse = {
|
|
45
|
+
project: TranslationIoProject;
|
|
46
|
+
segments: {
|
|
47
|
+
[locale: string]: TranslationIoSegment[];
|
|
48
|
+
};
|
|
49
|
+
};
|
|
47
50
|
export declare function tioSync(request: TranslationIoSyncRequest, apiKey: string): Promise<FetchResult<TranslationIoResponse>>;
|
|
48
51
|
export declare function tioInit(request: TranslationIoInitRequest, apiKey: string): Promise<FetchResult<TranslationIoResponse>>;
|
|
52
|
+
export {};
|
|
@@ -1,20 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.tioSync = tioSync;
|
|
4
|
-
exports.tioInit = tioInit;
|
|
5
|
-
// todo: need to enable strictNullChecks to support this kind of type narrowing
|
|
6
|
-
// export type TranslationIoResponse =
|
|
7
|
-
// | TranslationIoErrorResponse
|
|
8
|
-
// | TranslationProjectResponse
|
|
9
|
-
//
|
|
10
|
-
// type TranslationIoErrorResponse = {
|
|
11
|
-
// errors: string[]
|
|
12
|
-
// }
|
|
13
|
-
// type TranslationProjectResponse = {
|
|
14
|
-
// errors: null
|
|
15
|
-
// project: TranslationIoProject
|
|
16
|
-
// segments: { [locale: string]: TranslationIoSegment[] }
|
|
17
|
-
// }
|
|
18
1
|
async function post(url, request) {
|
|
19
2
|
const response = await fetch(url, {
|
|
20
3
|
method: "POST",
|
|
@@ -34,9 +17,9 @@ async function post(url, request) {
|
|
|
34
17
|
}
|
|
35
18
|
return { data: await response.json(), error: undefined };
|
|
36
19
|
}
|
|
37
|
-
async function tioSync(request, apiKey) {
|
|
20
|
+
export async function tioSync(request, apiKey) {
|
|
38
21
|
return post(`https://translation.io/api/v1/segments/sync.json?api_key=${apiKey}`, request);
|
|
39
22
|
}
|
|
40
|
-
async function tioInit(request, apiKey) {
|
|
23
|
+
export async function tioInit(request, apiKey) {
|
|
41
24
|
return post(`https://translation.io/api/v1/segments/init.json?api_key=${apiKey}`, request);
|
|
42
25
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { LinguiConfigNormalized } from "@lingui/conf";
|
|
2
|
-
import { CliExtractOptions } from "../lingui-extract";
|
|
3
|
-
import { TranslationIoProject, TranslationIoSegment } from "./translationIO/translationio-api";
|
|
4
|
-
import { Catalog } from "../api/catalog";
|
|
5
|
-
import { AllCatalogsType } from "../api/types";
|
|
2
|
+
import { CliExtractOptions } from "../lingui-extract.js";
|
|
3
|
+
import { TranslationIoProject, TranslationIoSegment } from "./translationIO/translationio-api.js";
|
|
4
|
+
import { Catalog } from "../api/catalog.js";
|
|
5
|
+
import { AllCatalogsType } from "../api/types.js";
|
|
6
6
|
type ExtractionResult = {
|
|
7
7
|
catalog: Catalog;
|
|
8
8
|
messagesByLocale: AllCatalogsType;
|
|
@@ -1,24 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
exports.default = syncProcess;
|
|
7
|
-
exports.init = init;
|
|
8
|
-
exports.sync = sync;
|
|
9
|
-
exports.writeSegmentsToCatalogs = writeSegmentsToCatalogs;
|
|
10
|
-
const fs_1 = __importDefault(require("fs"));
|
|
11
|
-
const path_1 = require("path");
|
|
12
|
-
const translationio_api_1 = require("./translationIO/translationio-api");
|
|
13
|
-
const catalog_1 = require("../api/catalog");
|
|
14
|
-
const segment_converters_1 = require("./translationIO/segment-converters");
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import { dirname } from "path";
|
|
3
|
+
import { tioInit, tioSync, } from "./translationIO/translationio-api.js";
|
|
4
|
+
import { order } from "../api/catalog.js";
|
|
5
|
+
import { createLinguiItemFromSegment, createSegmentFromLinguiItem, } from "./translationIO/segment-converters.js";
|
|
15
6
|
const getTargetLocales = (config) => {
|
|
16
7
|
const sourceLocale = config.sourceLocale || "en";
|
|
17
8
|
const pseudoLocale = config.pseudoLocale || "pseudo";
|
|
18
9
|
return config.locales.filter((value) => value != sourceLocale && value != pseudoLocale);
|
|
19
10
|
};
|
|
20
11
|
// Main sync method, call "Init" or "Sync" depending on the project context
|
|
21
|
-
async function syncProcess(config, options, extractionResult) {
|
|
12
|
+
export default async function syncProcess(config, options, extractionResult) {
|
|
22
13
|
const reportSuccess = (project) => {
|
|
23
14
|
return `\n----------\nProject successfully synchronized. Please use this URL to translate: ${project.url}\n----------`;
|
|
24
15
|
};
|
|
@@ -40,7 +31,7 @@ async function syncProcess(config, options, extractionResult) {
|
|
|
40
31
|
}
|
|
41
32
|
// Initialize project with source and existing translations (only first time!)
|
|
42
33
|
// Cf. https://translation.io/docs/create-library#initialization
|
|
43
|
-
async function init(config, extractionResult) {
|
|
34
|
+
export async function init(config, extractionResult) {
|
|
44
35
|
const sourceLocale = config.sourceLocale || "en";
|
|
45
36
|
const targetLocales = getTargetLocales(config);
|
|
46
37
|
const segments = {};
|
|
@@ -54,7 +45,7 @@ async function init(config, extractionResult) {
|
|
|
54
45
|
if (entry.obsolete)
|
|
55
46
|
return;
|
|
56
47
|
targetLocales.forEach((targetLocale) => {
|
|
57
|
-
segments[targetLocale].push(
|
|
48
|
+
segments[targetLocale].push(createSegmentFromLinguiItem(key, entry));
|
|
58
49
|
});
|
|
59
50
|
});
|
|
60
51
|
}
|
|
@@ -69,7 +60,7 @@ async function init(config, extractionResult) {
|
|
|
69
60
|
});
|
|
70
61
|
}
|
|
71
62
|
}
|
|
72
|
-
const { data, error } = await
|
|
63
|
+
const { data, error } = await tioInit({
|
|
73
64
|
client: "lingui",
|
|
74
65
|
version: require("@lingui/core/package.json").version,
|
|
75
66
|
source_language: sourceLocale,
|
|
@@ -79,7 +70,7 @@ async function init(config, extractionResult) {
|
|
|
79
70
|
if (error) {
|
|
80
71
|
return { success: false, errors: [error.message] };
|
|
81
72
|
}
|
|
82
|
-
if (data
|
|
73
|
+
if ("errors" in data) {
|
|
83
74
|
return { success: false, errors: data.errors };
|
|
84
75
|
}
|
|
85
76
|
await writeSegmentsToCatalogs(config, sourceLocale, extractionResult, data.segments);
|
|
@@ -87,7 +78,7 @@ async function init(config, extractionResult) {
|
|
|
87
78
|
}
|
|
88
79
|
// Send all source text from PO to Translation.io and create new PO based on received translations
|
|
89
80
|
// Cf. https://translation.io/docs/create-library#synchronization
|
|
90
|
-
async function sync(config, options, extractionResult) {
|
|
81
|
+
export async function sync(config, options, extractionResult) {
|
|
91
82
|
const sourceLocale = config.sourceLocale || "en";
|
|
92
83
|
const targetLocales = getTargetLocales(config);
|
|
93
84
|
const segments = [];
|
|
@@ -97,10 +88,10 @@ async function sync(config, options, extractionResult) {
|
|
|
97
88
|
Object.entries(messages).forEach(([key, entry]) => {
|
|
98
89
|
if (entry.obsolete)
|
|
99
90
|
return;
|
|
100
|
-
segments.push(
|
|
91
|
+
segments.push(createSegmentFromLinguiItem(key, entry));
|
|
101
92
|
});
|
|
102
93
|
}
|
|
103
|
-
const { data, error } = await
|
|
94
|
+
const { data, error } = await tioSync({
|
|
104
95
|
client: "lingui",
|
|
105
96
|
version: require("@lingui/core/package.json").version,
|
|
106
97
|
source_language: sourceLocale,
|
|
@@ -112,13 +103,13 @@ async function sync(config, options, extractionResult) {
|
|
|
112
103
|
if (error) {
|
|
113
104
|
return { success: false, errors: [error.message] };
|
|
114
105
|
}
|
|
115
|
-
if (data
|
|
106
|
+
if ("errors" in data) {
|
|
116
107
|
return { success: false, errors: data.errors };
|
|
117
108
|
}
|
|
118
109
|
await writeSegmentsToCatalogs(config, sourceLocale, extractionResult, data.segments);
|
|
119
110
|
return { success: true, project: data.project };
|
|
120
111
|
}
|
|
121
|
-
async function writeSegmentsToCatalogs(config, sourceLocale, extractionResult, segmentsPerLocale) {
|
|
112
|
+
export async function writeSegmentsToCatalogs(config, sourceLocale, extractionResult, segmentsPerLocale) {
|
|
122
113
|
// Create segments from source locale PO items
|
|
123
114
|
for (const { catalog, messagesByLocale } of extractionResult) {
|
|
124
115
|
const sourceMessages = messagesByLocale[sourceLocale];
|
|
@@ -127,28 +118,30 @@ async function writeSegmentsToCatalogs(config, sourceLocale, extractionResult, s
|
|
|
127
118
|
{
|
|
128
119
|
const path = catalog.getFilename(targetLocale);
|
|
129
120
|
const jsPath = path.replace(new RegExp(`${catalog.format.getCatalogExtension()}$`), "") + ".js";
|
|
130
|
-
const dirPath =
|
|
121
|
+
const dirPath = dirname(path);
|
|
131
122
|
// todo: check tests and all these logic, maybe it could be simplified to just drop the folder
|
|
132
123
|
// Remove PO, JS and empty dir
|
|
133
|
-
if (
|
|
134
|
-
await
|
|
124
|
+
if (fs.existsSync(path)) {
|
|
125
|
+
await fs.promises.unlink(path);
|
|
135
126
|
}
|
|
136
|
-
if (
|
|
137
|
-
await
|
|
127
|
+
if (fs.existsSync(jsPath)) {
|
|
128
|
+
await fs.promises.unlink(jsPath);
|
|
138
129
|
}
|
|
139
|
-
if (
|
|
140
|
-
await
|
|
130
|
+
if (fs.existsSync(dirPath) && fs.readdirSync(dirPath).length === 0) {
|
|
131
|
+
await fs.promises.rmdir(dirPath);
|
|
141
132
|
}
|
|
142
133
|
}
|
|
143
|
-
const translations = Object.fromEntries(segmentsPerLocale[targetLocale].map((segment) =>
|
|
134
|
+
const translations = Object.fromEntries(segmentsPerLocale[targetLocale].map((segment) => createLinguiItemFromSegment(segment)));
|
|
144
135
|
const messages = Object.fromEntries(Object.entries(sourceMessages).map(([key, entry]) => {
|
|
145
|
-
var _a;
|
|
146
136
|
return [
|
|
147
137
|
key,
|
|
148
|
-
|
|
138
|
+
{
|
|
139
|
+
...entry,
|
|
140
|
+
translation: translations[key]?.translation,
|
|
141
|
+
},
|
|
149
142
|
];
|
|
150
143
|
}));
|
|
151
|
-
await catalog.write(targetLocale,
|
|
144
|
+
await catalog.write(targetLocale, order(config.orderBy, messages));
|
|
152
145
|
}
|
|
153
146
|
}
|
|
154
147
|
}
|
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
import { CliCompileOptions } from "../lingui-compile";
|
|
2
|
-
import { SerializedLogs } from "../api/workerLogger";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
};
|
|
10
|
-
export type CompileWorker = typeof compileWorker;
|
|
11
|
-
export {};
|
|
1
|
+
import { CliCompileOptions } from "../lingui-compile.js";
|
|
2
|
+
import { SerializedLogs } from "../api/workerLogger.js";
|
|
3
|
+
export type CompileWorkerFunction = typeof compileWorker;
|
|
4
|
+
export declare const compileWorker: (locale: string, options: CliCompileOptions, doMerge: boolean, linguiConfigPath: string) => Promise<{
|
|
5
|
+
logs: SerializedLogs;
|
|
6
|
+
error?: unknown;
|
|
7
|
+
exitProgram?: boolean;
|
|
8
|
+
}>;
|
|
@@ -1,39 +1,33 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const workerLogger_1 = require("../api/workerLogger");
|
|
7
|
-
const ProgramExit_1 = require("../api/ProgramExit");
|
|
8
|
-
const getCatalogs_1 = require("../api/catalog/getCatalogs");
|
|
1
|
+
import { compileLocale } from "../api/compile/compileLocale.js";
|
|
2
|
+
import { getConfig } from "@lingui/conf";
|
|
3
|
+
import { WorkerLogger } from "../api/workerLogger.js";
|
|
4
|
+
import { ProgramExit } from "../api/ProgramExit.js";
|
|
5
|
+
import { getCatalogs } from "../api/catalog/getCatalogs.js";
|
|
9
6
|
let linguiConfig;
|
|
10
7
|
let catalogs;
|
|
11
|
-
const compileWorker = {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
return { logs: logger.flush() };
|
|
37
|
-
},
|
|
8
|
+
export const compileWorker = async (locale, options, doMerge, linguiConfigPath) => {
|
|
9
|
+
if (!linguiConfig) {
|
|
10
|
+
// initialize config once per worker, speed up workers follow execution
|
|
11
|
+
linguiConfig = getConfig({
|
|
12
|
+
configPath: linguiConfigPath,
|
|
13
|
+
skipValidation: true,
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
if (!catalogs) {
|
|
17
|
+
// catalogs holds path to the files and message catalogs, so it's kinda configuration object
|
|
18
|
+
// it depends only on the config, so we can initialize it once per program execution
|
|
19
|
+
catalogs = await getCatalogs(linguiConfig);
|
|
20
|
+
}
|
|
21
|
+
const logger = new WorkerLogger();
|
|
22
|
+
try {
|
|
23
|
+
await compileLocale(catalogs, locale, options, linguiConfig, doMerge, logger);
|
|
24
|
+
}
|
|
25
|
+
catch (error) {
|
|
26
|
+
return {
|
|
27
|
+
logs: logger.flush(),
|
|
28
|
+
error,
|
|
29
|
+
exitProgram: error instanceof ProgramExit,
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
return { logs: logger.flush() };
|
|
38
33
|
};
|
|
39
|
-
(0, worker_1.expose)(compileWorker);
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { ExtractedMessage } from "@lingui/conf";
|
|
2
2
|
export type ExtractWorkerFunction = typeof extractWorker;
|
|
3
|
-
declare const extractWorker: (filename: string, linguiConfigPath: string) => Promise<{
|
|
4
|
-
messages
|
|
3
|
+
export declare const extractWorker: (filename: string, linguiConfigPath: string) => Promise<{
|
|
4
|
+
messages: ExtractedMessage[];
|
|
5
5
|
success: boolean;
|
|
6
6
|
}>;
|
|
7
|
-
export {};
|
|
@@ -1,24 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const worker_1 = require("threads/worker");
|
|
7
|
-
const conf_1 = require("@lingui/conf");
|
|
8
|
-
const extractors_1 = __importDefault(require("../api/extractors"));
|
|
1
|
+
import { getConfig, } from "@lingui/conf";
|
|
2
|
+
import extract from "../api/extractors/index.js";
|
|
9
3
|
let linguiConfig;
|
|
10
|
-
const extractWorker = async (filename, linguiConfigPath) => {
|
|
4
|
+
export const extractWorker = async (filename, linguiConfigPath) => {
|
|
11
5
|
if (!linguiConfig) {
|
|
12
6
|
// initialize config once per worker, speed up workers follow execution
|
|
13
|
-
linguiConfig =
|
|
7
|
+
linguiConfig = getConfig({
|
|
14
8
|
configPath: linguiConfigPath,
|
|
15
9
|
skipValidation: true,
|
|
16
10
|
});
|
|
17
11
|
}
|
|
18
12
|
const messages = [];
|
|
19
|
-
const success = await (
|
|
13
|
+
const success = await extract(filename, (msg) => {
|
|
20
14
|
messages.push(msg);
|
|
21
15
|
}, linguiConfig);
|
|
22
16
|
return { success, messages };
|
|
23
17
|
};
|
|
24
|
-
(0, worker_1.expose)(extractWorker);
|
package/package.json
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lingui/cli",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "6.0.0-next.0",
|
|
4
4
|
"description": "CLI for working wit message catalogs",
|
|
5
|
+
"type": "module",
|
|
5
6
|
"keywords": [
|
|
6
7
|
"cli",
|
|
7
8
|
"i18n",
|
|
@@ -28,28 +29,16 @@
|
|
|
28
29
|
"lingui": "./dist/lingui.js"
|
|
29
30
|
},
|
|
30
31
|
"exports": {
|
|
31
|
-
".":
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
},
|
|
35
|
-
"./api": {
|
|
36
|
-
"types": "./dist/api/index.d.ts",
|
|
37
|
-
"default": "./dist/api/index.js"
|
|
38
|
-
},
|
|
39
|
-
"./api/extractors/babel": {
|
|
40
|
-
"types": "./dist/api/extractors/babel.d.ts",
|
|
41
|
-
"default": "./dist/api/extractors/babel.js"
|
|
42
|
-
},
|
|
43
|
-
"./api/extractors/typescript": {
|
|
44
|
-
"types": "./dist/api/extractors/typescript.d.ts",
|
|
45
|
-
"default": "./dist/api/extractors/typescript.js"
|
|
46
|
-
}
|
|
32
|
+
".": "./dist/index.js",
|
|
33
|
+
"./api": "./dist/api/index.js",
|
|
34
|
+
"./api/extractors/babel": "./dist/api/extractors/babel.js"
|
|
47
35
|
},
|
|
48
36
|
"scripts": {
|
|
49
|
-
"build": "
|
|
37
|
+
"build": "tsc -p tsconfig.build.json",
|
|
38
|
+
"check-types": "tsc --noEmit"
|
|
50
39
|
},
|
|
51
40
|
"engines": {
|
|
52
|
-
"node": ">=
|
|
41
|
+
"node": ">=22.19.0"
|
|
53
42
|
},
|
|
54
43
|
"files": [
|
|
55
44
|
"LICENSE",
|
|
@@ -58,43 +47,37 @@
|
|
|
58
47
|
],
|
|
59
48
|
"dependencies": {
|
|
60
49
|
"@babel/core": "^7.21.0",
|
|
61
|
-
"@babel/generator": "^7.
|
|
50
|
+
"@babel/generator": "^7.28.5",
|
|
62
51
|
"@babel/parser": "^7.22.0",
|
|
63
|
-
"@babel/runtime": "^7.21.0",
|
|
64
52
|
"@babel/types": "^7.21.2",
|
|
65
|
-
"@lingui/babel-plugin-extract-messages": "
|
|
66
|
-
"@lingui/babel-plugin-lingui-macro": "
|
|
67
|
-
"@lingui/conf": "
|
|
68
|
-
"@lingui/core": "
|
|
69
|
-
"@lingui/format-po": "
|
|
70
|
-
"@lingui/message-utils": "
|
|
71
|
-
"chokidar": "
|
|
72
|
-
"cli-
|
|
73
|
-
"commander": "^
|
|
74
|
-
"convert-source-map": "^2.0.0",
|
|
75
|
-
"date-fns": "^3.6.0",
|
|
53
|
+
"@lingui/babel-plugin-extract-messages": "6.0.0-next.0",
|
|
54
|
+
"@lingui/babel-plugin-lingui-macro": "6.0.0-next.0",
|
|
55
|
+
"@lingui/conf": "6.0.0-next.0",
|
|
56
|
+
"@lingui/core": "6.0.0-next.0",
|
|
57
|
+
"@lingui/format-po": "6.0.0-next.0",
|
|
58
|
+
"@lingui/message-utils": "6.0.0-next.0",
|
|
59
|
+
"chokidar": "5.0.0",
|
|
60
|
+
"cli-table3": "^0.6.5",
|
|
61
|
+
"commander": "^14.0.2",
|
|
76
62
|
"esbuild": "^0.25.1",
|
|
77
|
-
"
|
|
63
|
+
"jiti": "^2.6.1",
|
|
78
64
|
"micromatch": "^4.0.7",
|
|
79
65
|
"ms": "^2.1.3",
|
|
80
66
|
"normalize-path": "^3.0.0",
|
|
81
|
-
"ora": "^
|
|
82
|
-
"
|
|
83
|
-
"pofile": "^1.1.4",
|
|
84
|
-
"pseudolocale": "^2.0.0",
|
|
67
|
+
"ora": "^9.1.0",
|
|
68
|
+
"pseudolocale": "^2.2.0",
|
|
85
69
|
"source-map": "^0.7.6",
|
|
86
|
-
"
|
|
70
|
+
"tinypool": "^2.1.0"
|
|
87
71
|
},
|
|
88
72
|
"devDependencies": {
|
|
89
|
-
"@lingui/
|
|
90
|
-
"@types/
|
|
73
|
+
"@lingui/test-utils": "3.0.3",
|
|
74
|
+
"@types/babel__generator": "^7.27.0",
|
|
91
75
|
"@types/micromatch": "^4.0.1",
|
|
92
76
|
"@types/ms": "^2.1.0",
|
|
93
77
|
"@types/normalize-path": "^3.0.0",
|
|
94
78
|
"mock-fs": "^5.2.0",
|
|
95
|
-
"mockdate": "^3.0.5",
|
|
96
79
|
"msw": "^2.12.7",
|
|
97
|
-
"
|
|
80
|
+
"vitest": "4.0.18"
|
|
98
81
|
},
|
|
99
|
-
"gitHead": "
|
|
82
|
+
"gitHead": "a9576050487a4f7dfbc88db20814d5a1bb861c8c"
|
|
100
83
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export type ExtractWorkerPool = ReturnType<typeof createExtractWorkerPool>;
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createExtractWorkerPool = createExtractWorkerPool;
|
|
4
|
-
const threads_1 = require("threads");
|
|
5
|
-
/** @internal */
|
|
6
|
-
function createExtractWorkerPool(opts) {
|
|
7
|
-
return (0, threads_1.Pool)(() => (0, threads_1.spawn)(new threads_1.Worker("../workers/extractWorker")), { size: opts.poolSize });
|
|
8
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const extractor = {
|
|
4
|
-
match(filename) {
|
|
5
|
-
throw new Error("Typescript extractor was removed. " +
|
|
6
|
-
"Lingui CLI can parse typescript out of the box. " +
|
|
7
|
-
"Please remove it from your lingui.config.js");
|
|
8
|
-
},
|
|
9
|
-
extract() { },
|
|
10
|
-
};
|
|
11
|
-
exports.default = extractor;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function getEntryPoints(entries: string[]): string[];
|