@lingui/cli 4.0.0-next.1 → 4.0.0-next.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/build/api/catalog/getCatalogs.js +7 -2
- package/build/api/catalog/getTranslationsForCatalog.js +3 -3
- package/build/api/catalog.js +45 -43
- package/build/api/compile.js +5 -0
- package/build/api/extractors/babel.js +12 -6
- package/build/api/formats/api/formatterWrapper.js +42 -0
- package/build/api/formats/csv.js +11 -24
- package/build/api/formats/index.js +19 -20
- package/build/api/formats/lingui.js +28 -34
- package/build/api/formats/minimal.js +15 -28
- package/build/api/formats/po-gettext.js +44 -44
- package/build/api/formats/po.js +32 -36
- package/build/api/rethrownError.js +14 -0
- package/build/api/utils.js +14 -12
- package/build/extract-experimental/buildExternalizeFilter.js +39 -0
- package/build/extract-experimental/bundleSource.js +69 -0
- package/build/extract-experimental/constants.js +10 -0
- package/build/extract-experimental/getEntryPoints.js +14 -0
- package/build/extract-experimental/getExperimentalCatalogs.js +27 -0
- package/build/extract-experimental/resolveCatalogPath.js +23 -0
- package/build/extract-experimental/resolveTemplatePath.js +17 -0
- package/build/extract-experimental/writeCatalogs.js +59 -0
- package/build/lingui-compile.js +26 -17
- package/build/lingui-extract-experimental.js +103 -0
- package/build/lingui-extract.js +1 -1
- package/build/lingui.js +1 -1
- package/build/services/translationIO.js +27 -30
- package/build/tests.js +21 -0
- package/package.json +12 -11
|
@@ -52,18 +52,18 @@ function init(config, options, successCallback, failCallback) {
|
|
|
52
52
|
const sourceLocale = config.sourceLocale || "en";
|
|
53
53
|
const targetLocales = getTargetLocales(config);
|
|
54
54
|
const paths = poPathsPerLocale(config);
|
|
55
|
-
|
|
55
|
+
const segments = {};
|
|
56
56
|
targetLocales.forEach(targetLocale => {
|
|
57
57
|
segments[targetLocale] = [];
|
|
58
58
|
});
|
|
59
59
|
|
|
60
60
|
// Create segments from source locale PO items
|
|
61
61
|
paths[sourceLocale].forEach(path => {
|
|
62
|
-
|
|
63
|
-
|
|
62
|
+
const raw = _fs.default.readFileSync(path).toString();
|
|
63
|
+
const po = _pofile.default.parse(raw);
|
|
64
64
|
po.items.filter(item => !item["obsolete"]).forEach(item => {
|
|
65
65
|
targetLocales.forEach(targetLocale => {
|
|
66
|
-
|
|
66
|
+
const newSegment = createSegmentFromPoItem(item);
|
|
67
67
|
segments[targetLocale].push(newSegment);
|
|
68
68
|
});
|
|
69
69
|
});
|
|
@@ -72,14 +72,14 @@ function init(config, options, successCallback, failCallback) {
|
|
|
72
72
|
// Add translations to segments from target locale PO items
|
|
73
73
|
targetLocales.forEach(targetLocale => {
|
|
74
74
|
paths[targetLocale].forEach(path => {
|
|
75
|
-
|
|
76
|
-
|
|
75
|
+
const raw = _fs.default.readFileSync(path).toString();
|
|
76
|
+
const po = _pofile.default.parse(raw);
|
|
77
77
|
po.items.filter(item => !item["obsolete"]).forEach((item, index) => {
|
|
78
78
|
segments[targetLocale][index].target = item.msgstr[0];
|
|
79
79
|
});
|
|
80
80
|
});
|
|
81
81
|
});
|
|
82
|
-
|
|
82
|
+
const request = {
|
|
83
83
|
client: "lingui",
|
|
84
84
|
version: require("@lingui/core/package.json").version,
|
|
85
85
|
source_language: sourceLocale,
|
|
@@ -104,29 +104,26 @@ function sync(config, options, successCallback, failCallback) {
|
|
|
104
104
|
const sourceLocale = config.sourceLocale || "en";
|
|
105
105
|
const targetLocales = getTargetLocales(config);
|
|
106
106
|
const paths = poPathsPerLocale(config);
|
|
107
|
-
|
|
107
|
+
const segments = [];
|
|
108
108
|
|
|
109
109
|
// Create segments with correct source
|
|
110
110
|
paths[sourceLocale].forEach(path => {
|
|
111
|
-
|
|
112
|
-
|
|
111
|
+
const raw = _fs.default.readFileSync(path).toString();
|
|
112
|
+
const po = _pofile.default.parse(raw);
|
|
113
113
|
po.items.filter(item => !item["obsolete"]).forEach(item => {
|
|
114
|
-
|
|
114
|
+
const newSegment = createSegmentFromPoItem(item);
|
|
115
115
|
segments.push(newSegment);
|
|
116
116
|
});
|
|
117
117
|
});
|
|
118
|
-
|
|
118
|
+
const request = {
|
|
119
119
|
client: "lingui",
|
|
120
120
|
version: require("@lingui/core/package.json").version,
|
|
121
121
|
source_language: sourceLocale,
|
|
122
122
|
target_languages: targetLocales,
|
|
123
|
-
segments: segments
|
|
123
|
+
segments: segments,
|
|
124
|
+
// Sync and then remove unused segments (not present in the local application) from Translation.io
|
|
125
|
+
purge: Boolean(options.clean)
|
|
124
126
|
};
|
|
125
|
-
|
|
126
|
-
// Sync and then remove unused segments (not present in the local application) from Translation.io
|
|
127
|
-
if (options.clean) {
|
|
128
|
-
request["purge"] = true;
|
|
129
|
-
}
|
|
130
127
|
postTio("sync", request, config.service.apiKey, response => {
|
|
131
128
|
if (response.errors) {
|
|
132
129
|
failCallback(response.errors);
|
|
@@ -139,8 +136,8 @@ function sync(config, options, successCallback, failCallback) {
|
|
|
139
136
|
});
|
|
140
137
|
}
|
|
141
138
|
function createSegmentFromPoItem(item) {
|
|
142
|
-
|
|
143
|
-
|
|
139
|
+
const itemHasId = item.msgid != item.msgstr[0] && item.msgstr[0].length;
|
|
140
|
+
const segment = {
|
|
144
141
|
type: "source",
|
|
145
142
|
// No way to edit text for source language (inside code), so not using "key" here
|
|
146
143
|
source: itemHasId ? item.msgstr[0] : item.msgid,
|
|
@@ -161,7 +158,7 @@ function createSegmentFromPoItem(item) {
|
|
|
161
158
|
return segment;
|
|
162
159
|
}
|
|
163
160
|
function createPoItemFromSegment(segment) {
|
|
164
|
-
|
|
161
|
+
const item = new _pofile.default.Item();
|
|
165
162
|
item.msgid = segment.context ? segment.context : segment.source;
|
|
166
163
|
item.msgstr = [segment.target];
|
|
167
164
|
item.references = segment.references && segment.references.length ? segment.references : [];
|
|
@@ -190,11 +187,11 @@ function saveSegmentsToTargetPos(config, paths, segmentsPerLocale) {
|
|
|
190
187
|
// Find target path (ignoring {name})
|
|
191
188
|
const localePath = "".concat(config.catalogs[0].path.replace(/{locale}/g, targetLocale).replace(/{name}/g, ""), ".po");
|
|
192
189
|
const segments = segmentsPerLocale[targetLocale];
|
|
193
|
-
|
|
190
|
+
const po = new _pofile.default();
|
|
194
191
|
po.headers = getCreateHeaders(targetLocale);
|
|
195
|
-
|
|
192
|
+
const items = [];
|
|
196
193
|
segments.forEach(segment => {
|
|
197
|
-
|
|
194
|
+
const item = createPoItemFromSegment(segment);
|
|
198
195
|
items.push(item);
|
|
199
196
|
});
|
|
200
197
|
|
|
@@ -224,7 +221,7 @@ function saveSegmentsToTargetPos(config, paths, segmentsPerLocale) {
|
|
|
224
221
|
});
|
|
225
222
|
}
|
|
226
223
|
function poPathsPerLocale(config) {
|
|
227
|
-
const paths =
|
|
224
|
+
const paths = {};
|
|
228
225
|
config.locales.forEach(locale => {
|
|
229
226
|
paths[locale] = [];
|
|
230
227
|
config.catalogs.forEach(catalog => {
|
|
@@ -241,23 +238,23 @@ function poPathsPerLocale(config) {
|
|
|
241
238
|
return paths;
|
|
242
239
|
}
|
|
243
240
|
function postTio(action, request, apiKey, successCallback, failCallback) {
|
|
244
|
-
|
|
245
|
-
|
|
241
|
+
const jsonRequest = JSON.stringify(request);
|
|
242
|
+
const options = {
|
|
246
243
|
hostname: "translation.io",
|
|
247
|
-
path:
|
|
244
|
+
path: `/api/v1/segments/${action}.json?api_key=${apiKey}`,
|
|
248
245
|
method: "POST",
|
|
249
246
|
headers: {
|
|
250
247
|
"Content-Type": "application/json"
|
|
251
248
|
}
|
|
252
249
|
};
|
|
253
|
-
|
|
250
|
+
const req = _https.default.request(options, res => {
|
|
254
251
|
res.setEncoding("utf8");
|
|
255
252
|
let body = "";
|
|
256
253
|
res.on("data", chunk => {
|
|
257
254
|
body = body.concat(chunk);
|
|
258
255
|
});
|
|
259
256
|
res.on("end", () => {
|
|
260
|
-
|
|
257
|
+
const response = JSON.parse(body);
|
|
261
258
|
successCallback(response);
|
|
262
259
|
});
|
|
263
260
|
});
|
package/build/tests.js
CHANGED
|
@@ -4,6 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.copyFixture = copyFixture;
|
|
7
|
+
exports.createFixtures = createFixtures;
|
|
7
8
|
exports.defaultMergeOptions = exports.defaultMakeTemplateOptions = exports.defaultMakeOptions = void 0;
|
|
8
9
|
exports.listingToHumanReadable = listingToHumanReadable;
|
|
9
10
|
exports.makeCatalog = void 0;
|
|
@@ -93,6 +94,26 @@ function listingToHumanReadable(listing) {
|
|
|
93
94
|
});
|
|
94
95
|
return output.join("\n");
|
|
95
96
|
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Create fixtures from provided listing in temp folder
|
|
100
|
+
* Alternative for mock-fs which is also mocking nodejs require calls
|
|
101
|
+
* @param listing
|
|
102
|
+
*/
|
|
103
|
+
async function createFixtures(listing) {
|
|
104
|
+
const tmpDir = await _fs.default.promises.mkdtemp(_path.default.join(_os.default.tmpdir(), `lingui-test-${process.pid}`));
|
|
105
|
+
async function create(listing) {
|
|
106
|
+
for (const [filename, value] of Object.entries(listing)) {
|
|
107
|
+
if (typeof value === "string") {
|
|
108
|
+
await _fs.default.promises.writeFile(_path.default.join(tmpDir, filename), value);
|
|
109
|
+
} else {
|
|
110
|
+
await create(value);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
await create(listing);
|
|
115
|
+
return tmpDir;
|
|
116
|
+
}
|
|
96
117
|
function readFsToJson(directory, filter) {
|
|
97
118
|
const out = {};
|
|
98
119
|
_fs.default.readdirSync(directory).map(filename => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lingui/cli",
|
|
3
|
-
"version": "4.0.0-next.
|
|
3
|
+
"version": "4.0.0-next.2",
|
|
4
4
|
"description": "CLI for working wit message catalogs",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cli",
|
|
@@ -45,15 +45,14 @@
|
|
|
45
45
|
"build/"
|
|
46
46
|
],
|
|
47
47
|
"dependencies": {
|
|
48
|
-
"@babel/core": "^7.
|
|
49
|
-
"@babel/generator": "^7.
|
|
50
|
-
"@babel/parser": "^7.
|
|
51
|
-
"@babel/
|
|
52
|
-
"@babel/
|
|
53
|
-
"@babel
|
|
54
|
-
"@lingui/
|
|
55
|
-
"@lingui/
|
|
56
|
-
"@lingui/core": "^4.0.0-next.1",
|
|
48
|
+
"@babel/core": "^7.21.0",
|
|
49
|
+
"@babel/generator": "^7.21.1",
|
|
50
|
+
"@babel/parser": "^7.21.2",
|
|
51
|
+
"@babel/runtime": "^7.21.0",
|
|
52
|
+
"@babel/types": "^7.21.2",
|
|
53
|
+
"@lingui/babel-plugin-extract-messages": "^4.0.0-next.2",
|
|
54
|
+
"@lingui/conf": "^4.0.0-next.2",
|
|
55
|
+
"@lingui/core": "^4.0.0-next.2",
|
|
57
56
|
"@messageformat/parser": "^5.0.0",
|
|
58
57
|
"babel-plugin-macros": "^3.0.1",
|
|
59
58
|
"chalk": "^4.1.0",
|
|
@@ -62,6 +61,7 @@
|
|
|
62
61
|
"commander": "^10.0.0",
|
|
63
62
|
"convert-source-map": "^2.0.0",
|
|
64
63
|
"date-fns": "^2.16.1",
|
|
64
|
+
"esbuild": "^0.17.10",
|
|
65
65
|
"glob": "^7.1.4",
|
|
66
66
|
"inquirer": "^7.3.3",
|
|
67
67
|
"micromatch": "4.0.2",
|
|
@@ -70,6 +70,7 @@
|
|
|
70
70
|
"normalize-path": "^3.0.0",
|
|
71
71
|
"ora": "^5.1.0",
|
|
72
72
|
"papaparse": "^5.3.0",
|
|
73
|
+
"pkg-up": "^3.1.0",
|
|
73
74
|
"plurals-cldr": "^1.0.4",
|
|
74
75
|
"pofile": "^1.1.4",
|
|
75
76
|
"pseudolocale": "^1.1.0",
|
|
@@ -86,5 +87,5 @@
|
|
|
86
87
|
"mock-fs": "^5.2.0",
|
|
87
88
|
"mockdate": "^3.0.2"
|
|
88
89
|
},
|
|
89
|
-
"gitHead": "
|
|
90
|
+
"gitHead": "556ab57e20c2ac9d384a22424c6a90c2ba0dd133"
|
|
90
91
|
}
|