@lingui/cli 5.7.0 → 5.8.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/catalog.d.ts +2 -2
- package/dist/api/catalog.js +45 -58
- package/package.json +8 -8
package/dist/api/catalog.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { LinguiConfigNormalized, OrderBy } from "@lingui/conf";
|
|
1
|
+
import { LinguiConfigNormalized, OrderBy, OrderByFn } from "@lingui/conf";
|
|
2
2
|
import { FormatterWrapper } from "./formats";
|
|
3
3
|
import { CompiledCatalogNamespace } from "./compile";
|
|
4
4
|
import { GetTranslationsOptions } from "./catalog/getTranslationsForCatalog";
|
|
@@ -69,4 +69,4 @@ export declare class Catalog {
|
|
|
69
69
|
export declare function cleanObsolete<T extends ExtractedCatalogType>(messages: T): T;
|
|
70
70
|
export declare function order<T extends ExtractedCatalogType>(by: OrderBy, catalog: T): T;
|
|
71
71
|
export declare function writeCompiled(path: string, locale: string, compiledCatalog: string, namespace?: CompiledCatalogNamespace): Promise<string>;
|
|
72
|
-
export declare
|
|
72
|
+
export declare const orderByMessage: OrderByFn;
|
package/dist/api/catalog.js
CHANGED
|
@@ -3,11 +3,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.Catalog = void 0;
|
|
6
|
+
exports.orderByMessage = exports.Catalog = void 0;
|
|
7
7
|
exports.cleanObsolete = cleanObsolete;
|
|
8
8
|
exports.order = order;
|
|
9
9
|
exports.writeCompiled = writeCompiled;
|
|
10
|
-
exports.orderByMessage = orderByMessage;
|
|
11
10
|
const fs_1 = __importDefault(require("fs"));
|
|
12
11
|
const path_1 = __importDefault(require("path"));
|
|
13
12
|
const glob_1 = require("glob");
|
|
@@ -140,8 +139,7 @@ class Catalog {
|
|
|
140
139
|
return await this.format.read(filename, undefined);
|
|
141
140
|
}
|
|
142
141
|
get sourcePaths() {
|
|
143
|
-
const includeGlobs = this.include
|
|
144
|
-
.map((includePath) => {
|
|
142
|
+
const includeGlobs = this.include.map((includePath) => {
|
|
145
143
|
const isDir = (0, utils_1.isDirectory)(includePath);
|
|
146
144
|
/**
|
|
147
145
|
* glob library results from absolute patterns such as /foo/* are mounted onto the root setting using path.join.
|
|
@@ -150,8 +148,7 @@ class Catalog {
|
|
|
150
148
|
return isDir
|
|
151
149
|
? (0, normalize_path_1.default)(path_1.default.resolve(process.cwd(), includePath === "/" ? "" : includePath, "**/*.*"))
|
|
152
150
|
: includePath;
|
|
153
|
-
})
|
|
154
|
-
.map(utils_1.makePathRegexSafe);
|
|
151
|
+
});
|
|
155
152
|
return (0, glob_1.globSync)(includeGlobs, { ignore: this.exclude, mark: true });
|
|
156
153
|
}
|
|
157
154
|
get localeDir() {
|
|
@@ -173,28 +170,33 @@ function cleanObsolete(messages) {
|
|
|
173
170
|
return Object.fromEntries(Object.entries(messages).filter(([, message]) => !message.obsolete));
|
|
174
171
|
}
|
|
175
172
|
function order(by, catalog) {
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
return Object.keys(messages)
|
|
188
|
-
.sort()
|
|
173
|
+
const orderByFn = typeof by === "function"
|
|
174
|
+
? by
|
|
175
|
+
: {
|
|
176
|
+
messageId: orderByMessageId,
|
|
177
|
+
message: exports.orderByMessage,
|
|
178
|
+
origin: orderByOrigin,
|
|
179
|
+
}[by];
|
|
180
|
+
return Object.keys(catalog)
|
|
181
|
+
.sort((a, b) => {
|
|
182
|
+
return orderByFn({ messageId: a, entry: catalog[a] }, { messageId: b, entry: catalog[b] });
|
|
183
|
+
})
|
|
189
184
|
.reduce((acc, key) => {
|
|
190
185
|
;
|
|
191
|
-
acc[key] =
|
|
186
|
+
acc[key] = catalog[key];
|
|
192
187
|
return acc;
|
|
193
188
|
}, {});
|
|
194
189
|
}
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
190
|
+
/**
|
|
191
|
+
* Object keys are in the same order as they were created
|
|
192
|
+
* https://stackoverflow.com/a/31102605/1535540
|
|
193
|
+
*/
|
|
194
|
+
const orderByMessageId = (a, b) => {
|
|
195
|
+
return a.messageId.localeCompare(b.messageId);
|
|
196
|
+
};
|
|
197
|
+
const orderByOrigin = (a, b) => {
|
|
198
|
+
function getFirstOrigin(entry) {
|
|
199
|
+
const sortedOrigins = entry.origin.sort((a, b) => {
|
|
198
200
|
if (a[0] < b[0])
|
|
199
201
|
return -1;
|
|
200
202
|
if (a[0] > b[0])
|
|
@@ -203,26 +205,18 @@ function orderByOrigin(messages) {
|
|
|
203
205
|
});
|
|
204
206
|
return sortedOrigins[0];
|
|
205
207
|
}
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
return 0;
|
|
219
|
-
})
|
|
220
|
-
.reduce((acc, key) => {
|
|
221
|
-
;
|
|
222
|
-
acc[key] = messages[key];
|
|
223
|
-
return acc;
|
|
224
|
-
}, {});
|
|
225
|
-
}
|
|
208
|
+
const [aFile, aLineNumber] = getFirstOrigin(a.entry);
|
|
209
|
+
const [bFile, bLineNumber] = getFirstOrigin(b.entry);
|
|
210
|
+
if (aFile < bFile)
|
|
211
|
+
return -1;
|
|
212
|
+
if (aFile > bFile)
|
|
213
|
+
return 1;
|
|
214
|
+
if (aLineNumber < bLineNumber)
|
|
215
|
+
return -1;
|
|
216
|
+
if (aLineNumber > bLineNumber)
|
|
217
|
+
return 1;
|
|
218
|
+
return 0;
|
|
219
|
+
};
|
|
226
220
|
async function writeCompiled(path, locale, compiledCatalog, namespace) {
|
|
227
221
|
let ext;
|
|
228
222
|
switch (namespace) {
|
|
@@ -240,21 +234,14 @@ async function writeCompiled(path, locale, compiledCatalog, namespace) {
|
|
|
240
234
|
await (0, utils_1.writeFile)(filename, compiledCatalog);
|
|
241
235
|
return filename;
|
|
242
236
|
}
|
|
243
|
-
|
|
237
|
+
const orderByMessage = (a, b) => {
|
|
244
238
|
// hardcoded en-US locale to have consistent sorting
|
|
245
239
|
// @see https://github.com/lingui/js-lingui/pull/1808
|
|
246
240
|
const collator = new Intl.Collator("en-US");
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
})
|
|
255
|
-
.reduce((acc, key) => {
|
|
256
|
-
;
|
|
257
|
-
acc[key] = messages[key];
|
|
258
|
-
return acc;
|
|
259
|
-
}, {});
|
|
260
|
-
}
|
|
241
|
+
const aMsg = a.entry.message || "";
|
|
242
|
+
const bMsg = b.entry.message || "";
|
|
243
|
+
const aCtxt = a.entry.context || "";
|
|
244
|
+
const bCtxt = b.entry.context || "";
|
|
245
|
+
return collator.compare(aMsg, bMsg) || collator.compare(aCtxt, bCtxt);
|
|
246
|
+
};
|
|
247
|
+
exports.orderByMessage = orderByMessage;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lingui/cli",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.8.0",
|
|
4
4
|
"description": "CLI for working wit message catalogs",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cli",
|
|
@@ -62,12 +62,12 @@
|
|
|
62
62
|
"@babel/parser": "^7.22.0",
|
|
63
63
|
"@babel/runtime": "^7.21.0",
|
|
64
64
|
"@babel/types": "^7.21.2",
|
|
65
|
-
"@lingui/babel-plugin-extract-messages": "5.
|
|
66
|
-
"@lingui/babel-plugin-lingui-macro": "5.
|
|
67
|
-
"@lingui/conf": "5.
|
|
68
|
-
"@lingui/core": "5.
|
|
69
|
-
"@lingui/format-po": "5.
|
|
70
|
-
"@lingui/message-utils": "5.
|
|
65
|
+
"@lingui/babel-plugin-extract-messages": "5.8.0",
|
|
66
|
+
"@lingui/babel-plugin-lingui-macro": "5.8.0",
|
|
67
|
+
"@lingui/conf": "5.8.0",
|
|
68
|
+
"@lingui/core": "5.8.0",
|
|
69
|
+
"@lingui/format-po": "5.8.0",
|
|
70
|
+
"@lingui/message-utils": "5.8.0",
|
|
71
71
|
"chokidar": "3.5.1",
|
|
72
72
|
"cli-table": "^0.3.11",
|
|
73
73
|
"commander": "^10.0.0",
|
|
@@ -95,5 +95,5 @@
|
|
|
95
95
|
"mockdate": "^3.0.5",
|
|
96
96
|
"ts-node": "^10.9.2"
|
|
97
97
|
},
|
|
98
|
-
"gitHead": "
|
|
98
|
+
"gitHead": "83d0513bdda9ff14003a05d376c7fedf860dd7ee"
|
|
99
99
|
}
|