@lingui/cli 3.17.0 → 3.17.1
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/CHANGELOG.md +12 -0
- package/build/api/catalog.js +64 -142
- package/build/api/compile.js +12 -22
- package/build/api/detect.js +0 -16
- package/build/api/extract.js +5 -24
- package/build/api/extractors/babel.js +2 -10
- package/build/api/extractors/index.js +0 -12
- package/build/api/extractors/typescript.js +4 -17
- package/build/api/formats/csv.js +0 -15
- package/build/api/formats/index.js +1 -9
- package/build/api/formats/lingui.js +2 -18
- package/build/api/formats/minimal.js +5 -18
- package/build/api/formats/po-gettext.js +45 -79
- package/build/api/formats/po.js +6 -30
- package/build/api/help.js +3 -8
- package/build/api/index.js +8 -12
- package/build/api/locales.js +3 -12
- package/build/api/pseudoLocalize.js +5 -15
- package/build/api/stats.js +2 -8
- package/build/api/utils.js +11 -31
- package/build/lingui-add-locale.js +0 -3
- package/build/lingui-compile.js +24 -53
- package/build/lingui-extract-template.js +5 -14
- package/build/lingui-extract.js +18 -45
- package/build/lingui.js +0 -4
- package/build/services/translationIO.js +61 -85
- package/build/tests.js +2 -16
- package/package.json +12 -11
|
@@ -4,29 +4,17 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
|
|
8
7
|
var _dateFns = require("date-fns");
|
|
9
|
-
|
|
10
8
|
var _fs = _interopRequireDefault(require("fs"));
|
|
11
|
-
|
|
12
9
|
var _parser = require("@messageformat/parser");
|
|
13
|
-
|
|
14
10
|
var _pluralsCldr = _interopRequireDefault(require("plurals-cldr"));
|
|
15
|
-
|
|
16
11
|
var _pofile = _interopRequireDefault(require("pofile"));
|
|
17
|
-
|
|
18
12
|
var R = _interopRequireWildcard(require("ramda"));
|
|
19
|
-
|
|
20
13
|
var _plurals = _interopRequireDefault(require("node-gettext/lib/plurals"));
|
|
21
|
-
|
|
22
14
|
var _utils = require("../utils");
|
|
23
|
-
|
|
24
|
-
function
|
|
25
|
-
|
|
26
|
-
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
27
|
-
|
|
15
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
16
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
28
17
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
29
|
-
|
|
30
18
|
function getCreateHeaders(language = "no") {
|
|
31
19
|
return {
|
|
32
20
|
"POT-Creation-Date": (0, _dateFns.format)(new Date(), "yyyy-MM-dd HH:mmxxxx"),
|
|
@@ -36,9 +24,9 @@ function getCreateHeaders(language = "no") {
|
|
|
36
24
|
"X-Generator": "@lingui/cli",
|
|
37
25
|
Language: language
|
|
38
26
|
};
|
|
39
|
-
}
|
|
40
|
-
|
|
27
|
+
}
|
|
41
28
|
|
|
29
|
+
// Attempts to turn a single tokenized ICU plural case back into a string.
|
|
42
30
|
function stringifyICUCase(icuCase) {
|
|
43
31
|
return icuCase.tokens.map(token => {
|
|
44
32
|
if (token.type === "content") {
|
|
@@ -53,78 +41,77 @@ function stringifyICUCase(icuCase) {
|
|
|
53
41
|
}
|
|
54
42
|
}).join("");
|
|
55
43
|
}
|
|
56
|
-
|
|
57
44
|
const ICU_PLURAL_REGEX = /^{.*, plural, .*}$/;
|
|
58
45
|
const ICU_SELECT_REGEX = /^{.*, select(Ordinal)?, .*}$/;
|
|
59
|
-
const LINE_ENDINGS = /\r?\n/g;
|
|
46
|
+
const LINE_ENDINGS = /\r?\n/g;
|
|
60
47
|
|
|
48
|
+
// Prefix that is used to identitify context information used by this module in PO's "extracted comments".
|
|
61
49
|
const CTX_PREFIX = "js-lingui:";
|
|
62
|
-
|
|
63
50
|
const serialize = (items, options) => R.compose(R.values, R.mapObjIndexed((message, key) => {
|
|
64
51
|
const item = new _pofile.default.Item();
|
|
65
52
|
item.msgid = key;
|
|
66
|
-
item.comments = message.comments || [];
|
|
67
|
-
// Destructuring `undefined` is forbidden, so fallback to `[]` if the message has no extracted comments.
|
|
53
|
+
item.comments = message.comments || [];
|
|
68
54
|
|
|
55
|
+
// The extractedComments array may be modified in this method, so create a new array with the message's elements.
|
|
56
|
+
// Destructuring `undefined` is forbidden, so fallback to `[]` if the message has no extracted comments.
|
|
69
57
|
item.extractedComments = [...(message.extractedComments ?? [])];
|
|
70
|
-
|
|
71
58
|
if (message.context) {
|
|
72
59
|
item.msgctxt = message.context;
|
|
73
60
|
}
|
|
74
|
-
|
|
75
61
|
if (options.origins !== false) {
|
|
76
62
|
if (message.origin && options.lineNumbers === false) {
|
|
77
63
|
item.references = message.origin.map(([path]) => path);
|
|
78
64
|
} else {
|
|
79
65
|
item.references = message.origin ? message.origin.map(_utils.joinOrigin) : [];
|
|
80
66
|
}
|
|
81
|
-
}
|
|
82
|
-
|
|
67
|
+
}
|
|
83
68
|
|
|
69
|
+
// @ts-ignore: Figure out how to set this flag
|
|
84
70
|
item.obsolete = message.obsolete;
|
|
85
|
-
item.flags = message.flags ? R.fromPairs(message.flags.map(flag => [flag, true])) : {};
|
|
86
|
-
// message can be found in `message.message` or in the item's `key` itself.
|
|
71
|
+
item.flags = message.flags ? R.fromPairs(message.flags.map(flag => [flag, true])) : {};
|
|
87
72
|
|
|
73
|
+
// Depending on whether custom ids are used by the developer, the (potential plural) "original", untranslated ICU
|
|
74
|
+
// message can be found in `message.message` or in the item's `key` itself.
|
|
88
75
|
const icuMessage = message.message || key;
|
|
76
|
+
const _simplifiedMessage = icuMessage.replace(LINE_ENDINGS, " ");
|
|
89
77
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
78
|
+
// Quick check to see if original message is a plural localization.
|
|
93
79
|
if (ICU_PLURAL_REGEX.test(_simplifiedMessage)) {
|
|
94
80
|
try {
|
|
95
|
-
|
|
81
|
+
var _message$translation;
|
|
82
|
+
const messageAst = (0, _parser.parse)(icuMessage)[0];
|
|
96
83
|
|
|
84
|
+
// Check if any of the plural cases contain plurals themselves.
|
|
97
85
|
if (messageAst.cases.some(icuCase => icuCase.tokens.some(token => token.type === "plural"))) {
|
|
98
86
|
console.warn(`Nested plurals cannot be expressed with gettext plurals. ` + `Message with key "%s" will not be saved correctly.`, key);
|
|
99
|
-
}
|
|
100
|
-
|
|
87
|
+
}
|
|
101
88
|
|
|
89
|
+
// Store placeholder that is pluralized upon to allow restoring ICU format later.
|
|
102
90
|
const ctx = new URLSearchParams({
|
|
103
91
|
pluralize_on: messageAst.arg
|
|
104
92
|
});
|
|
105
|
-
|
|
106
93
|
if (message.message == null) {
|
|
107
94
|
// For messages without developer-set ID, use first case as `msgid` and the last case as `msgid_plural`.
|
|
108
95
|
// This does not necessarily make sense for development languages with more than two numbers, but gettext
|
|
109
96
|
// only supports exactly two plural forms.
|
|
110
97
|
item.msgid = stringifyICUCase(messageAst.cases[0]);
|
|
111
|
-
item.msgid_plural = stringifyICUCase(messageAst.cases[messageAst.cases.length - 1]);
|
|
98
|
+
item.msgid_plural = stringifyICUCase(messageAst.cases[messageAst.cases.length - 1]);
|
|
112
99
|
|
|
100
|
+
// Since the original msgid is overwritten, store ICU message to allow restoring that ID later.
|
|
113
101
|
ctx.set("icu", key);
|
|
114
102
|
} else {
|
|
115
103
|
// For messages with developer-set ID, append `_plural` to the key to generate `msgid_plural`.
|
|
116
104
|
item.msgid_plural = key + "_plural";
|
|
117
105
|
}
|
|
118
|
-
|
|
119
106
|
ctx.sort();
|
|
120
|
-
item.extractedComments.push(CTX_PREFIX + ctx.toString());
|
|
107
|
+
item.extractedComments.push(CTX_PREFIX + ctx.toString());
|
|
108
|
+
|
|
109
|
+
// If there is a translated value, parse that instead of the original message to prevent overriding localized
|
|
121
110
|
// content with the original message. If there is no translated value, don't touch msgstr, since marking item as
|
|
122
111
|
// plural (above) already causes `pofile` to automatically generate `msgstr[0]` and `msgstr[1]`.
|
|
123
|
-
|
|
124
|
-
if (message.translation?.length > 0) {
|
|
112
|
+
if (((_message$translation = message.translation) === null || _message$translation === void 0 ? void 0 : _message$translation.length) > 0) {
|
|
125
113
|
try {
|
|
126
114
|
const ast = (0, _parser.parse)(message.translation)[0];
|
|
127
|
-
|
|
128
115
|
if (ast.cases == null) {
|
|
129
116
|
console.warn(`Found translation without plural cases for key "${key}". ` + `This likely means that a translated .po file misses multiple msgstr[] entries for the key. ` + `Translation found: "${message.translation}"`);
|
|
130
117
|
item.msgstr = [message.translation];
|
|
@@ -142,20 +129,18 @@ const serialize = (items, options) => R.compose(R.values, R.mapObjIndexed((messa
|
|
|
142
129
|
if (!options.disableSelectWarning && ICU_SELECT_REGEX.test(_simplifiedMessage)) {
|
|
143
130
|
console.warn(`ICU 'select' and 'selectOrdinal' formats cannot be expressed natively in gettext format. ` + `Item with key "%s" will be included in the catalog as raw ICU message. ` + `To disable this warning, include '{ disableSelectWarning: true }' in the config's 'formatOptions'`, key);
|
|
144
131
|
}
|
|
145
|
-
|
|
146
132
|
item.msgstr = [message.translation];
|
|
147
133
|
}
|
|
148
|
-
|
|
149
134
|
return item;
|
|
150
135
|
}))(items);
|
|
151
|
-
|
|
152
136
|
const getMessageKey = R.prop("msgid");
|
|
153
137
|
const getTranslations = R.prop("msgstr");
|
|
154
138
|
const getExtractedComments = R.prop("extractedComments");
|
|
155
139
|
const getTranslatorComments = R.prop("comments");
|
|
156
140
|
const getMessageContext = R.prop("msgctxt");
|
|
157
141
|
const getOrigins = R.prop("references");
|
|
158
|
-
const getFlags = R.compose(R.map(R.trim), R.keys, R.dissoc("obsolete"),
|
|
142
|
+
const getFlags = R.compose(R.map(R.trim), R.keys, R.dissoc("obsolete"),
|
|
143
|
+
// backward-compatibility, remove in 3.x
|
|
159
144
|
R.prop("flags"));
|
|
160
145
|
const isObsolete = R.either(R.path(["flags", "obsolete"]), R.prop("obsolete"));
|
|
161
146
|
const getTranslationCount = R.compose(R.length, getTranslations);
|
|
@@ -168,6 +153,7 @@ const deserialize = R.map(R.applySpec({
|
|
|
168
153
|
origin: R.compose(R.map(_utils.splitOrigin), R.defaultTo([]), getOrigins),
|
|
169
154
|
flags: getFlags
|
|
170
155
|
}));
|
|
156
|
+
|
|
171
157
|
/**
|
|
172
158
|
* Returns ICU case labels in the order that gettext lists localized messages, e.g. 0,1,2 => `["one", "two", "other"]`.
|
|
173
159
|
*
|
|
@@ -178,119 +164,99 @@ const deserialize = R.map(R.applySpec({
|
|
|
178
164
|
* This approach is heavily influenced by
|
|
179
165
|
* https://github.com/LLK/po2icu/blob/9eb97f81f72b2fee02b77f1424702e019647e9b9/lib/po2icu.js#L148.
|
|
180
166
|
*/
|
|
181
|
-
|
|
182
167
|
const getPluralCases = lang => {
|
|
183
168
|
// If users uses locale with underscore or slash, es-ES, es_ES, gettextplural is "es" not es-ES.
|
|
184
169
|
const [correctLang] = lang.split(/[-_]/g);
|
|
185
170
|
const gettextPluralsInfo = _plurals.default[correctLang];
|
|
186
|
-
return gettextPluralsInfo
|
|
171
|
+
return gettextPluralsInfo === null || gettextPluralsInfo === void 0 ? void 0 : gettextPluralsInfo.examples.map(pluralCase => (0, _pluralsCldr.default)(correctLang, pluralCase.sample));
|
|
187
172
|
};
|
|
188
|
-
|
|
189
173
|
const convertPluralsToICU = (items, lang) => {
|
|
190
174
|
// .po plurals are numbered 0-N and need to be mapped to ICU plural classes ("one", "few", "many"...). Different
|
|
191
175
|
// languages can have different plural classes (some start with "zero", some with "one"), so read that data from CLDR.
|
|
192
176
|
// `pluralForms` may be `null` if lang is not found. As long as no plural is used, don't report an error.
|
|
193
177
|
let pluralForms = getPluralCases(lang);
|
|
194
178
|
items.forEach(item => {
|
|
179
|
+
var _item$extractedCommen;
|
|
195
180
|
const translationCount = getTranslationCount(item);
|
|
196
|
-
const messageKey = getMessageKey(item);
|
|
181
|
+
const messageKey = getMessageKey(item);
|
|
197
182
|
|
|
183
|
+
// Messages without multiple translations (= plural cases) need no further processing.
|
|
198
184
|
if (translationCount <= 1 && !item.msgid_plural) {
|
|
199
185
|
return;
|
|
200
|
-
}
|
|
201
|
-
|
|
186
|
+
}
|
|
202
187
|
|
|
188
|
+
// msgid_plural must be set, but its actual value is not important.
|
|
203
189
|
if (!item.msgid_plural) {
|
|
204
190
|
console.warn(`Multiple translations for item with key "%s" but missing 'msgid_plural' in catalog "${lang}". This is not supported and the plural cases will be ignored.`, messageKey);
|
|
205
191
|
return;
|
|
206
192
|
}
|
|
207
|
-
|
|
208
|
-
const contextComment = item.extractedComments.find(comment => comment.startsWith(CTX_PREFIX))?.substr(CTX_PREFIX.length);
|
|
193
|
+
const contextComment = (_item$extractedCommen = item.extractedComments.find(comment => comment.startsWith(CTX_PREFIX))) === null || _item$extractedCommen === void 0 ? void 0 : _item$extractedCommen.substr(CTX_PREFIX.length);
|
|
209
194
|
const ctx = new URLSearchParams(contextComment);
|
|
210
|
-
|
|
211
195
|
if (contextComment != null) {
|
|
212
196
|
item.extractedComments = item.extractedComments.filter(comment => !comment.startsWith(CTX_PREFIX));
|
|
213
|
-
}
|
|
214
|
-
|
|
197
|
+
}
|
|
215
198
|
|
|
199
|
+
// If an original ICU was stored, use that as `msgid` to match the catalog that was originally exported.
|
|
216
200
|
const storedICU = ctx.get("icu");
|
|
217
|
-
|
|
218
201
|
if (storedICU != null) {
|
|
219
202
|
item.msgid = storedICU;
|
|
220
|
-
}
|
|
221
|
-
|
|
203
|
+
}
|
|
222
204
|
|
|
205
|
+
// If all translations are empty, ignore item.
|
|
223
206
|
if (item.msgstr.every(str => str.length === 0)) {
|
|
224
207
|
return;
|
|
225
208
|
}
|
|
226
|
-
|
|
227
209
|
if (pluralForms == null) {
|
|
228
210
|
console.warn(`Multiple translations for item with key "%s" in language "${lang}", but no plural cases were found. ` + `This prohibits the translation of .po plurals into ICU plurals. Pluralization will not work for this key.`, messageKey);
|
|
229
211
|
return;
|
|
230
212
|
}
|
|
231
|
-
|
|
232
213
|
const pluralCount = pluralForms.length;
|
|
233
|
-
|
|
234
214
|
if (translationCount > pluralCount) {
|
|
235
215
|
console.warn(`More translations provided (${translationCount}) for item with key "%s" in language "${lang}" than there are plural cases available (${pluralCount}). ` + `This will result in not all translations getting picked up.`, messageKey);
|
|
236
|
-
}
|
|
237
|
-
|
|
216
|
+
}
|
|
238
217
|
|
|
239
|
-
|
|
218
|
+
// Map each msgstr to a "<pluralform> {<translated_string>}" entry, joined by one space.
|
|
219
|
+
const pluralClauses = item.msgstr.map((str, index) => pluralForms[index] + " {" + str + "}").join(" ");
|
|
240
220
|
|
|
221
|
+
// Find out placeholder name from item's message context, defaulting to "count".
|
|
241
222
|
let pluralizeOn = ctx.get("pluralize_on");
|
|
242
|
-
|
|
243
223
|
if (!pluralizeOn) {
|
|
244
224
|
console.warn(`Unable to determine plural placeholder name for item with key "%s" in language "${lang}" (should be stored in a comment starting with "#. ${CTX_PREFIX}"), assuming "count".`, messageKey);
|
|
245
225
|
pluralizeOn = "count";
|
|
246
226
|
}
|
|
247
|
-
|
|
248
227
|
item.msgstr = ["{" + pluralizeOn + ", plural, " + pluralClauses + "}"];
|
|
249
228
|
});
|
|
250
229
|
};
|
|
251
|
-
|
|
252
230
|
const indexItems = R.indexBy(getMessageKey);
|
|
253
231
|
const poGettext = {
|
|
254
232
|
catalogExtension: ".po",
|
|
255
|
-
|
|
256
233
|
write(filename, catalog, options) {
|
|
257
234
|
let po;
|
|
258
|
-
|
|
259
235
|
if (_fs.default.existsSync(filename)) {
|
|
260
236
|
const raw = _fs.default.readFileSync(filename).toString();
|
|
261
|
-
|
|
262
237
|
po = _pofile.default.parse(raw);
|
|
263
238
|
} else {
|
|
264
239
|
po = new _pofile.default();
|
|
265
240
|
po.headers = getCreateHeaders(options.locale);
|
|
266
|
-
|
|
267
241
|
if (options.locale === undefined) {
|
|
268
242
|
delete po.headers.Language;
|
|
269
243
|
}
|
|
270
|
-
|
|
271
244
|
po.headerOrder = Object.keys(po.headers);
|
|
272
245
|
}
|
|
273
|
-
|
|
274
246
|
po.items = this.serialize(catalog, options);
|
|
275
247
|
(0, _utils.writeFileIfChanged)(filename, po.toString());
|
|
276
248
|
},
|
|
277
|
-
|
|
278
249
|
// Mainly exported for easier testing
|
|
279
250
|
serialize,
|
|
280
|
-
|
|
281
251
|
read(filename) {
|
|
282
252
|
const raw = _fs.default.readFileSync(filename).toString();
|
|
283
|
-
|
|
284
253
|
return this.parse(raw);
|
|
285
254
|
},
|
|
286
|
-
|
|
287
255
|
parse(raw) {
|
|
288
256
|
const po = _pofile.default.parse(raw);
|
|
289
|
-
|
|
290
257
|
convertPluralsToICU(po.items, po.headers.Language);
|
|
291
258
|
return deserialize(indexItems(po.items));
|
|
292
259
|
}
|
|
293
|
-
|
|
294
260
|
};
|
|
295
261
|
var _default = poGettext;
|
|
296
262
|
exports.default = _default;
|
package/build/api/formats/po.js
CHANGED
|
@@ -4,23 +4,14 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
|
|
8
7
|
var _fs = _interopRequireDefault(require("fs"));
|
|
9
|
-
|
|
10
8
|
var R = _interopRequireWildcard(require("ramda"));
|
|
11
|
-
|
|
12
9
|
var _dateFns = require("date-fns");
|
|
13
|
-
|
|
14
10
|
var _pofile = _interopRequireDefault(require("pofile"));
|
|
15
|
-
|
|
16
11
|
var _utils = require("../utils");
|
|
17
|
-
|
|
18
|
-
function
|
|
19
|
-
|
|
20
|
-
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
21
|
-
|
|
12
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
13
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
22
14
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
23
|
-
|
|
24
15
|
const getCreateHeaders = (language = "no") => ({
|
|
25
16
|
"POT-Creation-Date": (0, _dateFns.format)(new Date(), "yyyy-MM-dd HH:mmxxxx"),
|
|
26
17
|
"MIME-Version": "1.0",
|
|
@@ -29,39 +20,35 @@ const getCreateHeaders = (language = "no") => ({
|
|
|
29
20
|
"X-Generator": "@lingui/cli",
|
|
30
21
|
Language: language
|
|
31
22
|
});
|
|
32
|
-
|
|
33
23
|
const serialize = (items, options) => R.compose(R.values, R.mapObjIndexed((message, key) => {
|
|
34
24
|
const item = new _pofile.default.Item();
|
|
35
25
|
item.msgid = key;
|
|
36
26
|
item.msgstr = [message.translation];
|
|
37
27
|
item.comments = message.comments || [];
|
|
38
28
|
item.extractedComments = message.extractedComments || [];
|
|
39
|
-
|
|
40
29
|
if (message.context) {
|
|
41
30
|
item.msgctxt = message.context;
|
|
42
31
|
}
|
|
43
|
-
|
|
44
32
|
if (options.origins !== false) {
|
|
45
33
|
if (message.origin && options.lineNumbers === false) {
|
|
46
34
|
item.references = message.origin.map(([path]) => path);
|
|
47
35
|
} else {
|
|
48
36
|
item.references = message.origin ? message.origin.map(_utils.joinOrigin) : [];
|
|
49
37
|
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
|
|
38
|
+
}
|
|
39
|
+
// @ts-ignore: Figure out how to set this flag
|
|
53
40
|
item.obsolete = message.obsolete;
|
|
54
41
|
item.flags = message.flags ? R.fromPairs(message.flags.map(flag => [flag, true])) : {};
|
|
55
42
|
return item;
|
|
56
43
|
}))(items);
|
|
57
|
-
|
|
58
44
|
const getMessageKey = R.prop("msgid");
|
|
59
45
|
const getTranslations = R.prop("msgstr");
|
|
60
46
|
const getExtractedComments = R.prop("extractedComments");
|
|
61
47
|
const getTranslatorComments = R.prop("comments");
|
|
62
48
|
const getMessageContext = R.prop("msgctxt");
|
|
63
49
|
const getOrigins = R.prop("references");
|
|
64
|
-
const getFlags = R.compose(R.map(R.trim), R.keys, R.dissoc("obsolete"),
|
|
50
|
+
const getFlags = R.compose(R.map(R.trim), R.keys, R.dissoc("obsolete"),
|
|
51
|
+
// backward-compatibility, remove in 3.x
|
|
65
52
|
R.prop("flags"));
|
|
66
53
|
const isObsolete = R.either(R.path(["flags", "obsolete"]), R.prop("obsolete"));
|
|
67
54
|
const deserialize = R.map(R.applySpec({
|
|
@@ -81,42 +68,31 @@ const validateItems = R.forEach(item => {
|
|
|
81
68
|
const indexItems = R.indexBy(getMessageKey);
|
|
82
69
|
const po = {
|
|
83
70
|
catalogExtension: ".po",
|
|
84
|
-
|
|
85
71
|
write(filename, catalog, options) {
|
|
86
72
|
let po;
|
|
87
|
-
|
|
88
73
|
if (_fs.default.existsSync(filename)) {
|
|
89
74
|
const raw = _fs.default.readFileSync(filename).toString();
|
|
90
|
-
|
|
91
75
|
po = _pofile.default.parse(raw);
|
|
92
76
|
} else {
|
|
93
77
|
po = new _pofile.default();
|
|
94
78
|
po.headers = getCreateHeaders(options.locale);
|
|
95
|
-
|
|
96
79
|
if (options.locale === undefined) {
|
|
97
80
|
delete po.headers.Language;
|
|
98
81
|
}
|
|
99
|
-
|
|
100
82
|
po.headerOrder = R.keys(po.headers);
|
|
101
83
|
}
|
|
102
|
-
|
|
103
84
|
po.items = serialize(catalog, options);
|
|
104
85
|
(0, _utils.writeFileIfChanged)(filename, po.toString());
|
|
105
86
|
},
|
|
106
|
-
|
|
107
87
|
read(filename) {
|
|
108
88
|
const raw = _fs.default.readFileSync(filename).toString();
|
|
109
|
-
|
|
110
89
|
return this.parse(raw);
|
|
111
90
|
},
|
|
112
|
-
|
|
113
91
|
parse(raw) {
|
|
114
92
|
const po = _pofile.default.parse(raw);
|
|
115
|
-
|
|
116
93
|
validateItems(po.items);
|
|
117
94
|
return deserialize(indexItems(po.items));
|
|
118
95
|
}
|
|
119
|
-
|
|
120
96
|
};
|
|
121
97
|
var _default = po;
|
|
122
98
|
exports.default = _default;
|
package/build/api/help.js
CHANGED
|
@@ -4,9 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.helpRun = helpRun;
|
|
7
|
-
|
|
8
7
|
var _path = require("path");
|
|
9
|
-
|
|
10
8
|
/**
|
|
11
9
|
* Detect where's is the command lingui extract or lingui compile
|
|
12
10
|
* and how is being run (npm, yarn) and construct help
|
|
@@ -25,23 +23,20 @@ var _path = require("path");
|
|
|
25
23
|
* ...
|
|
26
24
|
* (use "npm run compile" to compile catalogs for production)
|
|
27
25
|
*/
|
|
26
|
+
|
|
28
27
|
function helpRun(command) {
|
|
28
|
+
var _findRootPkgJson;
|
|
29
29
|
let findRootPkgJson;
|
|
30
|
-
|
|
31
30
|
try {
|
|
32
31
|
findRootPkgJson = require((0, _path.resolve)((0, _path.join)(process.cwd(), "package.json")));
|
|
33
32
|
} catch (error) {}
|
|
34
|
-
|
|
35
|
-
if (findRootPkgJson?.scripts) {
|
|
33
|
+
if ((_findRootPkgJson = findRootPkgJson) !== null && _findRootPkgJson !== void 0 && _findRootPkgJson.scripts) {
|
|
36
34
|
const res = Object.entries(findRootPkgJson.scripts).find(([_, value]) => value.includes(`lingui ${command}`));
|
|
37
|
-
|
|
38
35
|
if (res) {
|
|
39
36
|
command = res[0];
|
|
40
37
|
}
|
|
41
38
|
}
|
|
42
|
-
|
|
43
39
|
return `${runCommand} ${command}`;
|
|
44
40
|
}
|
|
45
|
-
|
|
46
41
|
const isYarn = process.env.npm_config_user_agent && process.env.npm_config_user_agent.includes("yarn");
|
|
47
42
|
const runCommand = isYarn ? "yarn" : "npm run";
|
package/build/api/index.js
CHANGED
|
@@ -3,35 +3,31 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
Object.defineProperty(exports, "
|
|
6
|
+
Object.defineProperty(exports, "createCompiledCatalog", {
|
|
7
7
|
enumerable: true,
|
|
8
8
|
get: function () {
|
|
9
|
-
return
|
|
9
|
+
return _compile.createCompiledCatalog;
|
|
10
10
|
}
|
|
11
11
|
});
|
|
12
|
-
Object.defineProperty(exports, "
|
|
12
|
+
Object.defineProperty(exports, "getCatalogForFile", {
|
|
13
13
|
enumerable: true,
|
|
14
14
|
get: function () {
|
|
15
|
-
return _catalog.
|
|
15
|
+
return _catalog.getCatalogForFile;
|
|
16
16
|
}
|
|
17
17
|
});
|
|
18
|
-
Object.defineProperty(exports, "
|
|
18
|
+
Object.defineProperty(exports, "getCatalogs", {
|
|
19
19
|
enumerable: true,
|
|
20
20
|
get: function () {
|
|
21
|
-
return _catalog.
|
|
21
|
+
return _catalog.getCatalogs;
|
|
22
22
|
}
|
|
23
23
|
});
|
|
24
|
-
Object.defineProperty(exports, "
|
|
24
|
+
Object.defineProperty(exports, "getFormat", {
|
|
25
25
|
enumerable: true,
|
|
26
26
|
get: function () {
|
|
27
|
-
return
|
|
27
|
+
return _formats.default;
|
|
28
28
|
}
|
|
29
29
|
});
|
|
30
|
-
|
|
31
30
|
var _formats = _interopRequireDefault(require("./formats"));
|
|
32
|
-
|
|
33
31
|
var _catalog = require("./catalog");
|
|
34
|
-
|
|
35
32
|
var _compile = require("./compile");
|
|
36
|
-
|
|
37
33
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
package/build/api/locales.js
CHANGED
|
@@ -5,17 +5,11 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.isValid = isValid;
|
|
7
7
|
exports.parse = parse;
|
|
8
|
-
|
|
9
8
|
var plurals = _interopRequireWildcard(require("make-plural/plurals"));
|
|
10
|
-
|
|
11
9
|
var _bcp = _interopRequireDefault(require("bcp-47"));
|
|
12
|
-
|
|
13
10
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
14
|
-
|
|
15
|
-
function
|
|
16
|
-
|
|
17
|
-
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
18
|
-
|
|
11
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
12
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
19
13
|
/**
|
|
20
14
|
* Check that locale is valid according to BCP47 and we have plurals for it
|
|
21
15
|
* @param locale: string - Locale in BCP47 format
|
|
@@ -25,18 +19,15 @@ function isValid(locale) {
|
|
|
25
19
|
const localeData = parse(locale);
|
|
26
20
|
return localeData !== null && localeData !== undefined && localeData.language in plurals;
|
|
27
21
|
}
|
|
22
|
+
|
|
28
23
|
/**
|
|
29
24
|
* Parse locale in BCP47 format and
|
|
30
25
|
* @param locale - Locale in BCP47 format
|
|
31
26
|
* @return {LocaleInfo}
|
|
32
27
|
*/
|
|
33
|
-
|
|
34
|
-
|
|
35
28
|
function parse(locale) {
|
|
36
29
|
if (typeof locale !== "string") return null;
|
|
37
|
-
|
|
38
30
|
const schema = _bcp.default.parse(locale.replace("_", "-"));
|
|
39
|
-
|
|
40
31
|
if (!schema.language) return null;
|
|
41
32
|
return {
|
|
42
33
|
locale: _bcp.default.stringify(schema),
|
|
@@ -4,25 +4,22 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = _default;
|
|
7
|
-
|
|
8
7
|
var _ramda = _interopRequireDefault(require("ramda"));
|
|
9
|
-
|
|
10
8
|
var _pseudolocale = _interopRequireDefault(require("pseudolocale"));
|
|
11
|
-
|
|
12
9
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
|
-
|
|
14
10
|
const delimiter = "%&&&%";
|
|
15
|
-
_pseudolocale.default.option.delimiter = delimiter;
|
|
16
|
-
|
|
11
|
+
_pseudolocale.default.option.delimiter = delimiter;
|
|
12
|
+
// We do not want prepending and appending because of Plurals structure
|
|
17
13
|
_pseudolocale.default.option.prepend = "";
|
|
18
14
|
_pseudolocale.default.option.append = "";
|
|
15
|
+
|
|
19
16
|
/**
|
|
20
17
|
* Regex should match HTML tags
|
|
21
18
|
* It was taken from https://haacked.com/archive/2004/10/25/usingregularexpressionstomatchhtml.aspx/
|
|
22
19
|
* Example: https://regex101.com/r/bDHD9z/3
|
|
23
20
|
*/
|
|
24
|
-
|
|
25
21
|
const HTMLRegex = /<\/?\w+((\s+\w+(\s*=\s*(?:".*?"|'.*?'|[^'">\s]+))?)+\s*|\s*)\/?>/g;
|
|
22
|
+
|
|
26
23
|
/**
|
|
27
24
|
* Regex should match js-lingui Plurals, Select and SelectOrdinal components
|
|
28
25
|
* Example:
|
|
@@ -30,39 +27,32 @@ const HTMLRegex = /<\/?\w+((\s+\w+(\s*=\s*(?:".*?"|'.*?'|[^'">\s]+))?)+\s*|\s*)\
|
|
|
30
27
|
* SelectOrdinal https://regex101.com/r/T7hSLU/2
|
|
31
28
|
* Select https://regex101.com/r/9JnqB9/1
|
|
32
29
|
*/
|
|
33
|
-
|
|
34
30
|
const MacroRegex = /({\w*,\s*(plural|selectordinal|select),(.|\n)*?{)|(}\s*\w*\s*{)/gi;
|
|
31
|
+
|
|
35
32
|
/**
|
|
36
33
|
* Regex should match js-lingui variables
|
|
37
34
|
* Example: https://regex101.com/r/dw1QHb/2
|
|
38
35
|
*/
|
|
39
|
-
|
|
40
36
|
const VariableRegex = /({\s*[a-zA-Z_$][a-zA-Z_$0-9]*\s*})/g;
|
|
41
|
-
|
|
42
37
|
function addDelimitersHTMLTags(message) {
|
|
43
38
|
return message.replace(HTMLRegex, matchedString => {
|
|
44
39
|
return `${delimiter}${matchedString}${delimiter}`;
|
|
45
40
|
});
|
|
46
41
|
}
|
|
47
|
-
|
|
48
42
|
function addDelimitersMacro(message) {
|
|
49
43
|
return message.replace(MacroRegex, matchedString => {
|
|
50
44
|
return `${delimiter}${matchedString}${delimiter}`;
|
|
51
45
|
});
|
|
52
46
|
}
|
|
53
|
-
|
|
54
47
|
function addDelimitersVariables(message) {
|
|
55
48
|
return message.replace(VariableRegex, matchedString => {
|
|
56
49
|
return `${delimiter}${matchedString}${delimiter}`;
|
|
57
50
|
});
|
|
58
51
|
}
|
|
59
|
-
|
|
60
52
|
const addDelimiters = _ramda.default.compose(addDelimitersVariables, addDelimitersMacro, addDelimitersHTMLTags);
|
|
61
|
-
|
|
62
53
|
function removeDelimiters(message) {
|
|
63
54
|
return message.replace(new RegExp(delimiter, "g"), "");
|
|
64
55
|
}
|
|
65
|
-
|
|
66
56
|
function _default(message) {
|
|
67
57
|
message = addDelimiters(message);
|
|
68
58
|
message = _pseudolocale.default.str(message);
|
package/build/api/stats.js
CHANGED
|
@@ -5,17 +5,12 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.getStats = getStats;
|
|
7
7
|
exports.printStats = printStats;
|
|
8
|
-
|
|
9
8
|
var _cliTable = _interopRequireDefault(require("cli-table"));
|
|
10
|
-
|
|
11
9
|
var _chalk = _interopRequireDefault(require("chalk"));
|
|
12
|
-
|
|
13
10
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
14
|
-
|
|
15
11
|
function getStats(catalog) {
|
|
16
12
|
return [Object.keys(catalog).length, Object.keys(catalog).filter(key => !catalog[key].translation).length];
|
|
17
13
|
}
|
|
18
|
-
|
|
19
14
|
function printStats(config, catalogs) {
|
|
20
15
|
const table = new _cliTable.default({
|
|
21
16
|
head: ["Language", "Total count", "Missing"],
|
|
@@ -27,11 +22,10 @@ function printStats(config, catalogs) {
|
|
|
27
22
|
}
|
|
28
23
|
});
|
|
29
24
|
Object.keys(catalogs).forEach(locale => {
|
|
30
|
-
const catalog = catalogs[locale];
|
|
25
|
+
const catalog = catalogs[locale];
|
|
26
|
+
// catalog is null if no catalog exists on disk and the locale
|
|
31
27
|
// was not extracted due to a `--locale` filter
|
|
32
|
-
|
|
33
28
|
const [all, translated] = catalog ? getStats(catalog) : ["-", "-"];
|
|
34
|
-
|
|
35
29
|
if (config.sourceLocale === locale) {
|
|
36
30
|
table.push({
|
|
37
31
|
[`${_chalk.default.bold(locale)} (source)`]: [all, "-"]
|