@lingui/cli 5.6.1 → 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/dist/api/compile/compileLocale.js +1 -0
- package/dist/api/compile.d.ts +1 -0
- package/dist/api/compile.js +2 -2
- package/dist/lingui-compile.d.ts +1 -0
- package/dist/lingui-compile.js +2 -0
- package/dist/services/translationIO.js +7 -1
- package/package.json +9 -9
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;
|
|
@@ -62,6 +62,7 @@ async function compileAndWrite(locale, config, options, writePath, messages, log
|
|
|
62
62
|
const { source: compiledCatalog, errors } = (0, compile_1.createCompiledCatalog)(locale, messages, {
|
|
63
63
|
strict: false,
|
|
64
64
|
namespace,
|
|
65
|
+
outputPrefix: options.outputPrefix,
|
|
65
66
|
pseudoLocale: config.pseudoLocale,
|
|
66
67
|
compilerBabelOptions: config.compilerBabelOptions,
|
|
67
68
|
});
|
package/dist/api/compile.d.ts
CHANGED
package/dist/api/compile.js
CHANGED
|
@@ -43,7 +43,7 @@ const generator_1 = __importDefault(require("@babel/generator"));
|
|
|
43
43
|
const compileMessage_1 = require("@lingui/message-utils/compileMessage");
|
|
44
44
|
const pseudoLocalize_1 = __importDefault(require("./pseudoLocalize"));
|
|
45
45
|
function createCompiledCatalog(locale, messages, options) {
|
|
46
|
-
const { strict = false, namespace = "cjs", pseudoLocale, compilerBabelOptions = {}, } = options;
|
|
46
|
+
const { strict = false, namespace = "cjs", pseudoLocale, compilerBabelOptions = {}, outputPrefix = "/*eslint-disable*/", } = options;
|
|
47
47
|
const shouldPseudolocalize = locale === pseudoLocale;
|
|
48
48
|
const errors = [];
|
|
49
49
|
const compiledMessages = Object.keys(messages)
|
|
@@ -72,7 +72,7 @@ function createCompiledCatalog(locale, messages, options) {
|
|
|
72
72
|
const code = (0, generator_1.default)(ast, Object.assign({ minified: true, jsescOption: {
|
|
73
73
|
minimal: true,
|
|
74
74
|
} }, compilerBabelOptions)).code;
|
|
75
|
-
return { source:
|
|
75
|
+
return { source: `${outputPrefix}` + code, errors };
|
|
76
76
|
}
|
|
77
77
|
function buildExportStatement(expression, namespace) {
|
|
78
78
|
if (namespace === "ts") {
|
package/dist/lingui-compile.d.ts
CHANGED
package/dist/lingui-compile.js
CHANGED
|
@@ -80,6 +80,7 @@ if (require.main === module) {
|
|
|
80
80
|
.option("--namespace <namespace>", "Specify namespace for compiled bundle. Ex: cjs(default) -> module.exports, es -> export, window.test -> window.test")
|
|
81
81
|
.option("--watch", "Enables Watch Mode")
|
|
82
82
|
.option("--debounce <delay>", "Debounces compilation for given amount of milliseconds")
|
|
83
|
+
.option("--output-prefix <prefix>", "Add a custom string to the beginning of compiled files (header/prefix). Useful for tools like linters or coverage directives. Defaults to '/*eslint-disable*/'")
|
|
83
84
|
.on("--help", function () {
|
|
84
85
|
console.log("\n Examples:\n");
|
|
85
86
|
console.log(" # Compile translations and use defaults or message IDs for missing translations");
|
|
@@ -102,6 +103,7 @@ if (require.main === module) {
|
|
|
102
103
|
workersOptions: (0, resolveWorkersOptions_1.resolveWorkersOptions)(options),
|
|
103
104
|
typescript: options.typescript || config.compileNamespace === "ts" || false,
|
|
104
105
|
namespace: options.namespace, // we want this to be undefined if user does not specify so default can be used
|
|
106
|
+
outputPrefix: options.outputPrefix,
|
|
105
107
|
}));
|
|
106
108
|
return previousRun;
|
|
107
109
|
};
|
|
@@ -25,9 +25,15 @@ const getTargetLocales = (config) => {
|
|
|
25
25
|
const pseudoLocale = config.pseudoLocale || "pseudo";
|
|
26
26
|
return config.locales.filter((value) => value != sourceLocale && value != pseudoLocale);
|
|
27
27
|
};
|
|
28
|
+
const validCatalogFormat = (config) => {
|
|
29
|
+
if (typeof config.format === "string") {
|
|
30
|
+
return config.format === "po";
|
|
31
|
+
}
|
|
32
|
+
return config.format.catalogExtension === ".po";
|
|
33
|
+
};
|
|
28
34
|
// Main sync method, call "Init" or "Sync" depending on the project context
|
|
29
35
|
async function syncProcess(config, options) {
|
|
30
|
-
if (config
|
|
36
|
+
if (!validCatalogFormat(config)) {
|
|
31
37
|
console.error(`\n----------\nTranslation.io service is only compatible with the "po" format. Please update your Lingui configuration accordingly.\n----------`);
|
|
32
38
|
process.exit(1);
|
|
33
39
|
}
|
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",
|
|
@@ -82,7 +82,7 @@
|
|
|
82
82
|
"picocolors": "^1.1.1",
|
|
83
83
|
"pofile": "^1.1.4",
|
|
84
84
|
"pseudolocale": "^2.0.0",
|
|
85
|
-
"source-map": "^0.
|
|
85
|
+
"source-map": "^0.7.6",
|
|
86
86
|
"threads": "^1.7.0"
|
|
87
87
|
},
|
|
88
88
|
"devDependencies": {
|
|
@@ -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
|
}
|