@lingui/cli 3.12.0 → 3.13.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/api/catalog.js CHANGED
@@ -18,6 +18,10 @@ exports.cleanObsolete = exports.Catalog = void 0;
18
18
 
19
19
  var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
20
20
 
21
+ var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
22
+
23
+ var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
24
+
21
25
  var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
22
26
 
23
27
  var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
@@ -48,16 +52,16 @@ var _extractors = _interopRequireDefault(require("./extractors"));
48
52
 
49
53
  var _utils = require("./utils");
50
54
 
55
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
56
+
57
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
58
+
51
59
  function _createForOfIteratorHelper(o, allowArrayLike) { var it; if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = o[Symbol.iterator](); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
52
60
 
53
61
  function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
54
62
 
55
63
  function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
56
64
 
57
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
58
-
59
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
60
-
61
65
  var NAME = "{name}";
62
66
  var LOCALE = "{locale}";
63
67
  var LOCALE_SUFFIX_RE = /\{locale\}.*$/;
@@ -87,98 +91,204 @@ var Catalog = /*#__PURE__*/function () {
87
91
 
88
92
  (0, _createClass2.default)(Catalog, [{
89
93
  key: "make",
90
- value: function make(options) {
91
- var nextCatalog = this.collect(options);
92
- var prevCatalogs = this.readAll();
93
- var catalogs = this.merge(prevCatalogs, nextCatalog, {
94
- overwrite: options.overwrite,
95
- files: options.files
96
- }); // Map over all locales and post-process each catalog
97
-
98
- var cleanAndSort = R.map(R.pipe( // Clean obsolete messages
99
- options.clean ? cleanObsolete : R.identity, // Sort messages
100
- order(options.orderBy)));
101
- var sortedCatalogs = cleanAndSort(catalogs);
102
-
103
- if (options.locale) {
104
- this.write(options.locale, sortedCatalogs[options.locale]);
105
- } else {
106
- this.writeAll(sortedCatalogs);
94
+ value: function () {
95
+ var _make = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(options) {
96
+ var nextCatalog, prevCatalogs, catalogs, cleanAndSort, sortedCatalogs;
97
+ return _regenerator.default.wrap(function _callee$(_context) {
98
+ while (1) {
99
+ switch (_context.prev = _context.next) {
100
+ case 0:
101
+ _context.next = 2;
102
+ return this.collect(options);
103
+
104
+ case 2:
105
+ nextCatalog = _context.sent;
106
+ prevCatalogs = this.readAll();
107
+ catalogs = this.merge(prevCatalogs, nextCatalog, {
108
+ overwrite: options.overwrite,
109
+ files: options.files
110
+ }); // Map over all locales and post-process each catalog
111
+
112
+ cleanAndSort = R.map(R.pipe( // Clean obsolete messages
113
+ options.clean ? cleanObsolete : R.identity, // Sort messages
114
+ order(options.orderBy)));
115
+ sortedCatalogs = cleanAndSort(catalogs);
116
+
117
+ if (options.locale) {
118
+ this.write(options.locale, sortedCatalogs[options.locale]);
119
+ } else {
120
+ this.writeAll(sortedCatalogs);
121
+ }
122
+
123
+ case 8:
124
+ case "end":
125
+ return _context.stop();
126
+ }
127
+ }
128
+ }, _callee, this);
129
+ }));
130
+
131
+ function make(_x) {
132
+ return _make.apply(this, arguments);
107
133
  }
108
- }
134
+
135
+ return make;
136
+ }()
109
137
  }, {
110
138
  key: "makeTemplate",
111
- value: function makeTemplate(options) {
112
- var catalog = this.collect(options);
113
- var sort = order(options.orderBy);
114
- this.writeTemplate(sort(catalog));
115
- }
139
+ value: function () {
140
+ var _makeTemplate = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2(options) {
141
+ var catalog, sort;
142
+ return _regenerator.default.wrap(function _callee2$(_context2) {
143
+ while (1) {
144
+ switch (_context2.prev = _context2.next) {
145
+ case 0:
146
+ _context2.next = 2;
147
+ return this.collect(options);
148
+
149
+ case 2:
150
+ catalog = _context2.sent;
151
+ sort = order(options.orderBy);
152
+ this.writeTemplate(sort(catalog));
153
+
154
+ case 5:
155
+ case "end":
156
+ return _context2.stop();
157
+ }
158
+ }
159
+ }, _callee2, this);
160
+ }));
161
+
162
+ function makeTemplate(_x2) {
163
+ return _makeTemplate.apply(this, arguments);
164
+ }
165
+
166
+ return makeTemplate;
167
+ }()
116
168
  /**
117
169
  * Collect messages from source paths. Return a raw message catalog as JSON.
118
170
  */
119
171
 
120
172
  }, {
121
173
  key: "collect",
122
- value: function collect(options) {
123
- var _this = this;
124
-
125
- var tmpDir = _path.default.join(_os.default.tmpdir(), "lingui-".concat(process.pid));
126
-
127
- if (_fsExtra.default.existsSync(tmpDir)) {
128
- (0, _utils.removeDirectory)(tmpDir, true);
129
- } else {
130
- _fsExtra.default.mkdirSync(tmpDir);
131
- }
132
-
133
- try {
134
- var paths = this.sourcePaths;
135
-
136
- if (options.files) {
137
- options.files = options.files.map(function (p) {
138
- return (0, _normalizePath.default)(p, false);
139
- });
140
- var regex = new RegExp(options.files.join("|"), "i");
141
- paths = paths.filter(function (path) {
142
- return regex.test(path);
143
- });
144
- }
145
-
146
- paths.forEach(function (filename) {
147
- return (0, _extractors.default)(filename, tmpDir, {
148
- verbose: options.verbose,
149
- configPath: options.configPath,
150
- babelOptions: _this.config.extractBabelOptions,
151
- extractors: options.extractors,
152
- projectType: options.projectType
153
- });
154
- });
155
- return function traverse(directory) {
156
- return _fsExtra.default.readdirSync(directory).map(function (filename) {
157
- var filepath = _path.default.join(directory, filename);
158
-
159
- if (_fsExtra.default.lstatSync(filepath).isDirectory()) {
160
- return traverse(filepath);
174
+ value: function () {
175
+ var _collect = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee3(options) {
176
+ var tmpDir, paths, regex, _iterator, _step, filename;
177
+
178
+ return _regenerator.default.wrap(function _callee3$(_context3) {
179
+ while (1) {
180
+ switch (_context3.prev = _context3.next) {
181
+ case 0:
182
+ tmpDir = _path.default.join(_os.default.tmpdir(), "lingui-".concat(process.pid));
183
+
184
+ if (_fsExtra.default.existsSync(tmpDir)) {
185
+ (0, _utils.removeDirectory)(tmpDir, true);
186
+ } else {
187
+ _fsExtra.default.mkdirSync(tmpDir);
188
+ }
189
+
190
+ _context3.prev = 2;
191
+ paths = this.sourcePaths;
192
+
193
+ if (options.files) {
194
+ options.files = options.files.map(function (p) {
195
+ return (0, _normalizePath.default)(p, false);
196
+ });
197
+ regex = new RegExp(options.files.join("|"), "i");
198
+ paths = paths.filter(function (path) {
199
+ return regex.test(path);
200
+ });
201
+ }
202
+
203
+ _iterator = _createForOfIteratorHelper(paths);
204
+ _context3.prev = 6;
205
+
206
+ _iterator.s();
207
+
208
+ case 8:
209
+ if ((_step = _iterator.n()).done) {
210
+ _context3.next = 14;
211
+ break;
212
+ }
213
+
214
+ filename = _step.value;
215
+ _context3.next = 12;
216
+ return (0, _extractors.default)(filename, tmpDir, {
217
+ verbose: options.verbose,
218
+ configPath: options.configPath,
219
+ babelOptions: this.config.extractBabelOptions,
220
+ extractors: options.extractors,
221
+ projectType: options.projectType
222
+ });
223
+
224
+ case 12:
225
+ _context3.next = 8;
226
+ break;
227
+
228
+ case 14:
229
+ _context3.next = 19;
230
+ break;
231
+
232
+ case 16:
233
+ _context3.prev = 16;
234
+ _context3.t0 = _context3["catch"](6);
235
+
236
+ _iterator.e(_context3.t0);
237
+
238
+ case 19:
239
+ _context3.prev = 19;
240
+
241
+ _iterator.f();
242
+
243
+ return _context3.finish(19);
244
+
245
+ case 22:
246
+ return _context3.abrupt("return", function traverse(directory) {
247
+ return _fsExtra.default.readdirSync(directory).map(function (filename) {
248
+ var filepath = _path.default.join(directory, filename);
249
+
250
+ if (_fsExtra.default.lstatSync(filepath).isDirectory()) {
251
+ return traverse(filepath);
252
+ }
253
+
254
+ if (!filename.endsWith(".json")) return;
255
+
256
+ try {
257
+ return JSON.parse(_fsExtra.default.readFileSync(filepath).toString());
258
+ } catch (e) {}
259
+ }).filter(Boolean).reduce(function (catalog, messages) {
260
+ return R.mergeWithKey(mergeOriginsAndExtractedComments, catalog, messages);
261
+ }, {});
262
+ }(tmpDir));
263
+
264
+ case 25:
265
+ _context3.prev = 25;
266
+ _context3.t1 = _context3["catch"](2);
267
+ throw _context3.t1;
268
+
269
+ case 28:
270
+ _context3.prev = 28;
271
+ (0, _utils.removeDirectory)(tmpDir);
272
+ return _context3.finish(28);
273
+
274
+ case 31:
275
+ case "end":
276
+ return _context3.stop();
161
277
  }
278
+ }
279
+ }, _callee3, this, [[2, 25, 28, 31], [6, 16, 19, 22]]);
280
+ }));
162
281
 
163
- if (!filename.endsWith(".json")) return;
164
-
165
- try {
166
- return JSON.parse(_fsExtra.default.readFileSync(filepath).toString());
167
- } catch (e) {}
168
- }).filter(Boolean).reduce(function (catalog, messages) {
169
- return R.mergeWithKey(mergeOriginsAndExtractedComments, catalog, messages);
170
- }, {});
171
- }(tmpDir);
172
- } catch (e) {
173
- throw e;
174
- } finally {
175
- (0, _utils.removeDirectory)(tmpDir);
282
+ function collect(_x3) {
283
+ return _collect.apply(this, arguments);
176
284
  }
177
- }
285
+
286
+ return collect;
287
+ }()
178
288
  }, {
179
289
  key: "merge",
180
290
  value: function merge(prevCatalogs, nextCatalog, options) {
181
- var _this2 = this;
291
+ var _this = this;
182
292
 
183
293
  var nextKeys = R.keys(nextCatalog).map(String);
184
294
  return R.mapObjIndexed(function (prevCatalog, locale) {
@@ -189,13 +299,13 @@ var Catalog = /*#__PURE__*/function () {
189
299
 
190
300
  var newMessages = R.mapObjIndexed(function (message, key) {
191
301
  return _objectSpread({
192
- translation: _this2.config.sourceLocale === locale ? message.message || key : ""
302
+ translation: _this.config.sourceLocale === locale ? message.message || key : ""
193
303
  }, message);
194
304
  }, R.pick(newKeys, nextCatalog)); // Merge translations from previous catalog
195
305
 
196
306
  var mergedMessages = mergeKeys.map(function (key) {
197
- var updateFromDefaults = _this2.config.sourceLocale === locale && (prevCatalog[key].translation === prevCatalog[key].message || options.overwrite);
198
- var translation = updateFromDefaults ? nextCatalog[key].message : prevCatalog[key].translation;
307
+ var updateFromDefaults = _this.config.sourceLocale === locale && (prevCatalog[key].translation === prevCatalog[key].message || options.overwrite);
308
+ var translation = updateFromDefaults ? nextCatalog[key].message || key : prevCatalog[key].translation;
199
309
  return (0, _defineProperty2.default)({}, key, _objectSpread({
200
310
  translation: translation
201
311
  }, R.omit(["obsolete, translation"], nextCatalog[key])));
@@ -213,17 +323,17 @@ var Catalog = /*#__PURE__*/function () {
213
323
  }, {
214
324
  key: "getTranslations",
215
325
  value: function getTranslations(locale, options) {
216
- var _this3 = this;
326
+ var _this2 = this;
217
327
 
218
328
  var catalogs = this.readAll();
219
329
  return R.mapObjIndexed(function (_value, key) {
220
- return _this3.getTranslation(catalogs, locale, key, options);
330
+ return _this2.getTranslation(catalogs, locale, key, options);
221
331
  }, catalogs[locale]);
222
332
  }
223
333
  }, {
224
334
  key: "getTranslation",
225
335
  value: function getTranslation(catalogs, locale, key, _ref4) {
226
- var _this4 = this;
336
+ var _this3 = this;
227
337
 
228
338
  var fallbackLocales = _ref4.fallbackLocales,
229
339
  sourceLocale = _ref4.sourceLocale;
@@ -233,7 +343,7 @@ var Catalog = /*#__PURE__*/function () {
233
343
  }
234
344
 
235
345
  var getTranslation = function getTranslation(locale) {
236
- var configLocales = _this4.config.locales.join('", "');
346
+ var configLocales = _this3.config.locales.join('", "');
237
347
 
238
348
  var localeCatalog = catalogs[locale];
239
349
 
@@ -260,21 +370,21 @@ var Catalog = /*#__PURE__*/function () {
260
370
  if (!fL) return null;
261
371
 
262
372
  if (Array.isArray(fL)) {
263
- var _iterator = _createForOfIteratorHelper(fL),
264
- _step;
373
+ var _iterator2 = _createForOfIteratorHelper(fL),
374
+ _step2;
265
375
 
266
376
  try {
267
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
268
- var fallbackLocale = _step.value;
377
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
378
+ var fallbackLocale = _step2.value;
269
379
 
270
380
  if (catalogs[fallbackLocale]) {
271
381
  return getTranslation(fallbackLocale);
272
382
  }
273
383
  }
274
384
  } catch (err) {
275
- _iterator.e(err);
385
+ _iterator2.e(err);
276
386
  } finally {
277
- _iterator.f();
387
+ _iterator2.f();
278
388
  }
279
389
  } else {
280
390
  return getTranslation(fL);
@@ -312,10 +422,10 @@ var Catalog = /*#__PURE__*/function () {
312
422
  }, {
313
423
  key: "writeAll",
314
424
  value: function writeAll(catalogs) {
315
- var _this5 = this;
425
+ var _this4 = this;
316
426
 
317
427
  this.locales.forEach(function (locale) {
318
- return _this5.write(locale, catalogs[locale]);
428
+ return _this4.write(locale, catalogs[locale]);
319
429
  });
320
430
  }
321
431
  }, {
@@ -370,10 +480,10 @@ var Catalog = /*#__PURE__*/function () {
370
480
  }, {
371
481
  key: "readAll",
372
482
  value: function readAll() {
373
- var _this6 = this;
483
+ var _this5 = this;
374
484
 
375
485
  return R.mergeAll(this.locales.map(function (locale) {
376
- return (0, _defineProperty2.default)({}, locale, _this6.read(locale));
486
+ return (0, _defineProperty2.default)({}, locale, _this5.read(locale));
377
487
  }));
378
488
  }
379
489
  }, {
@@ -504,12 +614,12 @@ function getCatalogs(config) {
504
614
  }
505
615
 
506
616
  function getCatalogForFile(file, catalogs) {
507
- var _iterator2 = _createForOfIteratorHelper(catalogs),
508
- _step2;
617
+ var _iterator3 = _createForOfIteratorHelper(catalogs),
618
+ _step3;
509
619
 
510
620
  try {
511
- for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
512
- var _catalog = _step2.value;
621
+ for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
622
+ var _catalog = _step3.value;
513
623
  var catalogFile = "".concat(_catalog.path).concat(_catalog.format.catalogExtension);
514
624
  var catalogGlob = catalogFile.replace(LOCALE, "*");
515
625
 
@@ -523,9 +633,9 @@ function getCatalogForFile(file, catalogs) {
523
633
  }
524
634
  }
525
635
  } catch (err) {
526
- _iterator2.e(err);
636
+ _iterator3.e(err);
527
637
  } finally {
528
- _iterator2.f();
638
+ _iterator3.f();
529
639
  }
530
640
 
531
641
  return null;
package/api/compile.js CHANGED
@@ -12,6 +12,8 @@ exports.compile = compile;
12
12
 
13
13
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
14
14
 
15
+ var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
16
+
15
17
  var t = _interopRequireWildcard(require("@babel/types"));
16
18
 
17
19
  var _generator = _interopRequireDefault(require("@babel/generator"));
@@ -28,6 +30,18 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
28
30
 
29
31
  var INVALID_OBJECT_KEY_REGEX = /^(\d+[a-zA-Z]|[a-zA-Z]+\d)(\d|[a-zA-Z])*/;
30
32
 
33
+ /**
34
+ * Transform a single key/value translation into a Babel expression,
35
+ * applying pseudolocalization where necessary.
36
+ */
37
+ function compileSingleKey(key, translation, shouldPseudolocalize) {
38
+ if (shouldPseudolocalize) {
39
+ translation = (0, _pseudoLocalize.default)(key);
40
+ }
41
+
42
+ return t.objectProperty(t.stringLiteral(key), compile(translation));
43
+ }
44
+
31
45
  function createCompiledCatalog(locale, messages, options) {
32
46
  var _options$strict = options.strict,
33
47
  strict = _options$strict === void 0 ? false : _options$strict,
@@ -38,15 +52,22 @@ function createCompiledCatalog(locale, messages, options) {
38
52
  compilerBabelOptions = _options$compilerBabe === void 0 ? {} : _options$compilerBabe,
39
53
  _options$pure = options.pure,
40
54
  pure = _options$pure === void 0 ? false : _options$pure;
55
+ var shouldPseudolocalize = locale === pseudoLocale;
41
56
  var compiledMessages = R.keys(messages).map(function (key) {
42
- // Don't use `key` as a fallback translation in strict mode.
43
- var translation = messages[key] || (!strict ? key : "");
57
+ var value = messages[key]; // If the current ID's value is a context object, create a nested
58
+ // expression, and assign the current ID to that expression
44
59
 
45
- if (locale === pseudoLocale) {
46
- translation = (0, _pseudoLocalize.default)(translation);
47
- }
60
+ if ((0, _typeof2.default)(value) === "object") {
61
+ var contextExpression = t.objectExpression(Object.keys(value).map(function (contextKey) {
62
+ var contextTranslation = value[contextKey];
63
+ return compileSingleKey(contextKey, contextTranslation, shouldPseudolocalize);
64
+ }));
65
+ return t.objectProperty(t.stringLiteral(key), contextExpression);
66
+ } // Don't use `key` as a fallback translation in strict mode.
48
67
 
49
- return t.objectProperty(t.stringLiteral(key), compile(translation));
68
+
69
+ var translation = messages[key] || (!strict ? key : "");
70
+ return compileSingleKey(key, translation, shouldPseudolocalize);
50
71
  });
51
72
  var ast = pure ? t.objectExpression(compiledMessages) : buildExportStatement(t.objectExpression(compiledMessages), namespace);
52
73
  var code = (0, _generator.default)(ast, _objectSpread({
package/api/extract.js CHANGED
@@ -10,6 +10,10 @@ Object.defineProperty(exports, "__esModule", {
10
10
  exports.extract = extract;
11
11
  exports.collect = collect;
12
12
 
13
+ var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
14
+
15
+ var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
16
+
13
17
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
14
18
 
15
19
  var _fs = _interopRequireDefault(require("fs"));
@@ -24,6 +28,12 @@ var _utils = require("./utils");
24
28
 
25
29
  var _extractors = _interopRequireDefault(require("./extractors"));
26
30
 
31
+ function _createForOfIteratorHelper(o, allowArrayLike) { var it; if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = o[Symbol.iterator](); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
32
+
33
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
34
+
35
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
36
+
27
37
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
28
38
 
29
39
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
@@ -43,25 +53,122 @@ function mergeMessage(msgId, prev, next) {
43
53
  });
44
54
  }
45
55
 
46
- function extract(srcPaths, targetPath) {
47
- var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
48
- var _options$ignore = options.ignore,
49
- ignore = _options$ignore === void 0 ? [] : _options$ignore;
50
- var ignorePattern = ignore.length ? new RegExp(ignore.join("|"), "i") : null;
51
- srcPaths.forEach(function (srcFilename) {
52
- if (!_fs.default.existsSync(srcFilename) || ignorePattern && ignorePattern.test(srcFilename)) return;
53
-
54
- if (_fs.default.statSync(srcFilename).isDirectory()) {
55
- var subdirs = _fs.default.readdirSync(srcFilename).sort().map(function (filename) {
56
- return _path.default.join(srcFilename, filename);
57
- });
58
-
59
- extract(subdirs, targetPath, options);
60
- return;
61
- }
56
+ function extract(_x, _x2) {
57
+ return _extract.apply(this, arguments);
58
+ }
62
59
 
63
- (0, _extractors.default)(srcFilename, targetPath, options);
64
- });
60
+ function _extract() {
61
+ _extract = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(srcPaths, targetPath) {
62
+ var options,
63
+ _options$ignore,
64
+ ignore,
65
+ ignorePattern,
66
+ _iterator,
67
+ _step,
68
+ _loop,
69
+ _ret,
70
+ _args2 = arguments;
71
+
72
+ return _regenerator.default.wrap(function _callee$(_context2) {
73
+ while (1) {
74
+ switch (_context2.prev = _context2.next) {
75
+ case 0:
76
+ options = _args2.length > 2 && _args2[2] !== undefined ? _args2[2] : {};
77
+ _options$ignore = options.ignore, ignore = _options$ignore === void 0 ? [] : _options$ignore;
78
+ ignorePattern = ignore.length ? new RegExp(ignore.join("|"), "i") : null;
79
+ _iterator = _createForOfIteratorHelper(srcPaths);
80
+ _context2.prev = 4;
81
+ _loop = /*#__PURE__*/_regenerator.default.mark(function _loop() {
82
+ var srcFilename, subdirs;
83
+ return _regenerator.default.wrap(function _loop$(_context) {
84
+ while (1) {
85
+ switch (_context.prev = _context.next) {
86
+ case 0:
87
+ srcFilename = _step.value;
88
+
89
+ if (!(!_fs.default.existsSync(srcFilename) || ignorePattern && ignorePattern.test(srcFilename))) {
90
+ _context.next = 3;
91
+ break;
92
+ }
93
+
94
+ return _context.abrupt("return", "continue");
95
+
96
+ case 3:
97
+ if (!_fs.default.statSync(srcFilename).isDirectory()) {
98
+ _context.next = 8;
99
+ break;
100
+ }
101
+
102
+ subdirs = _fs.default.readdirSync(srcFilename).sort().map(function (filename) {
103
+ return _path.default.join(srcFilename, filename);
104
+ });
105
+ _context.next = 7;
106
+ return extract(subdirs, targetPath, options);
107
+
108
+ case 7:
109
+ return _context.abrupt("return", "continue");
110
+
111
+ case 8:
112
+ _context.next = 10;
113
+ return (0, _extractors.default)(srcFilename, targetPath, options);
114
+
115
+ case 10:
116
+ case "end":
117
+ return _context.stop();
118
+ }
119
+ }
120
+ }, _loop);
121
+ });
122
+
123
+ _iterator.s();
124
+
125
+ case 7:
126
+ if ((_step = _iterator.n()).done) {
127
+ _context2.next = 14;
128
+ break;
129
+ }
130
+
131
+ return _context2.delegateYield(_loop(), "t0", 9);
132
+
133
+ case 9:
134
+ _ret = _context2.t0;
135
+
136
+ if (!(_ret === "continue")) {
137
+ _context2.next = 12;
138
+ break;
139
+ }
140
+
141
+ return _context2.abrupt("continue", 12);
142
+
143
+ case 12:
144
+ _context2.next = 7;
145
+ break;
146
+
147
+ case 14:
148
+ _context2.next = 19;
149
+ break;
150
+
151
+ case 16:
152
+ _context2.prev = 16;
153
+ _context2.t1 = _context2["catch"](4);
154
+
155
+ _iterator.e(_context2.t1);
156
+
157
+ case 19:
158
+ _context2.prev = 19;
159
+
160
+ _iterator.f();
161
+
162
+ return _context2.finish(19);
163
+
164
+ case 22:
165
+ case "end":
166
+ return _context2.stop();
167
+ }
168
+ }
169
+ }, _callee, null, [[4, 16, 19, 22]]);
170
+ }));
171
+ return _extract.apply(this, arguments);
65
172
  }
66
173
 
67
174
  function collect(buildDir) {
@@ -7,45 +7,124 @@ Object.defineProperty(exports, "__esModule", {
7
7
  });
8
8
  exports.default = extract;
9
9
 
10
+ var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
11
+
12
+ var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
13
+
10
14
  var _ora = _interopRequireDefault(require("ora"));
11
15
 
12
16
  var _babel = _interopRequireDefault(require("./babel"));
13
17
 
18
+ function _createForOfIteratorHelper(o, allowArrayLike) { var it; if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = o[Symbol.iterator](); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
19
+
20
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
21
+
22
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
23
+
14
24
  var DEFAULT_EXTRACTORS = [_babel.default];
15
25
 
16
- function extract(filename, targetPath, options) {
17
- var _options$extractors;
18
-
19
- var extractorsToExtract = (_options$extractors = options.extractors) !== null && _options$extractors !== void 0 ? _options$extractors : DEFAULT_EXTRACTORS;
20
- return extractorsToExtract.some(function (e) {
21
- var ext = e;
22
-
23
- if (typeof e === "string") {
24
- // in case of the user using require.resolve in their extractors, we require that module
25
- ext = require(e);
26
- }
27
-
28
- if (ext.default) {
29
- ext = ext.default;
30
- }
31
-
32
- if (!ext.match(filename)) return false;
33
- var spinner;
34
- if (options.verbose) spinner = (0, _ora.default)().start(filename);
35
-
36
- try {
37
- ext.extract(filename, targetPath, options);
38
- } catch (e) {
39
- if (options.verbose && spinner) {
40
- spinner.fail(e.message);
41
- } else {
42
- console.error("Cannot process file ".concat(e.message));
43
- }
26
+ function extract(_x, _x2, _x3) {
27
+ return _extract.apply(this, arguments);
28
+ }
29
+
30
+ function _extract() {
31
+ _extract = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(filename, targetPath, options) {
32
+ var _options$extractors;
33
+
34
+ var extractorsToExtract, _iterator, _step, e, ext, spinner;
35
+
36
+ return _regenerator.default.wrap(function _callee$(_context) {
37
+ while (1) {
38
+ switch (_context.prev = _context.next) {
39
+ case 0:
40
+ extractorsToExtract = (_options$extractors = options.extractors) !== null && _options$extractors !== void 0 ? _options$extractors : DEFAULT_EXTRACTORS;
41
+ _iterator = _createForOfIteratorHelper(extractorsToExtract);
42
+ _context.prev = 2;
43
+
44
+ _iterator.s();
45
+
46
+ case 4:
47
+ if ((_step = _iterator.n()).done) {
48
+ _context.next = 26;
49
+ break;
50
+ }
51
+
52
+ e = _step.value;
53
+ ext = e;
54
+
55
+ if (typeof e === "string") {
56
+ // in case of the user using require.resolve in their extractors, we require that module
57
+ ext = require(e);
58
+ }
59
+
60
+ if (ext.default) {
61
+ ext = ext.default;
62
+ }
63
+
64
+ if (ext.match(filename)) {
65
+ _context.next = 11;
66
+ break;
67
+ }
44
68
 
45
- return true;
46
- }
69
+ return _context.abrupt("continue", 24);
47
70
 
48
- if (options.verbose && spinner) spinner.succeed();
49
- return true;
50
- });
71
+ case 11:
72
+ spinner = void 0;
73
+ if (options.verbose) spinner = (0, _ora.default)().start(filename);
74
+ _context.prev = 13;
75
+ _context.next = 16;
76
+ return ext.extract(filename, targetPath, options);
77
+
78
+ case 16:
79
+ _context.next = 22;
80
+ break;
81
+
82
+ case 18:
83
+ _context.prev = 18;
84
+ _context.t0 = _context["catch"](13);
85
+
86
+ if (options.verbose && spinner) {
87
+ spinner.fail(_context.t0.message);
88
+ } else {
89
+ console.error("Cannot process file ".concat(_context.t0.message));
90
+ }
91
+
92
+ return _context.abrupt("return", true);
93
+
94
+ case 22:
95
+ if (options.verbose && spinner) spinner.succeed();
96
+ return _context.abrupt("return", true);
97
+
98
+ case 24:
99
+ _context.next = 4;
100
+ break;
101
+
102
+ case 26:
103
+ _context.next = 31;
104
+ break;
105
+
106
+ case 28:
107
+ _context.prev = 28;
108
+ _context.t1 = _context["catch"](2);
109
+
110
+ _iterator.e(_context.t1);
111
+
112
+ case 31:
113
+ _context.prev = 31;
114
+
115
+ _iterator.f();
116
+
117
+ return _context.finish(31);
118
+
119
+ case 34:
120
+ return _context.abrupt("return", false);
121
+
122
+ case 35:
123
+ case "end":
124
+ return _context.stop();
125
+ }
126
+ }
127
+ }, _callee, null, [[2, 28, 31, 34], [13, 18]]);
128
+ }));
129
+ return _extract.apply(this, arguments);
51
130
  }
@@ -74,11 +74,18 @@ var serialize = function serialize(items, options) {
74
74
 
75
75
  item.extractedComments = (0, _toConsumableArray2.default)((_message$extractedCom = message.extractedComments) !== null && _message$extractedCom !== void 0 ? _message$extractedCom : []);
76
76
 
77
+ if (message.context) {
78
+ item.msgctxt = message.context;
79
+ }
80
+
77
81
  if (options.origins !== false) {
78
82
  if (message.origin && options.lineNumbers === false) {
79
- item.references = message.origin.map(function (msg) {
80
- return msg.slice(0, -1);
81
- }).map(_utils.joinOrigin);
83
+ item.references = message.origin.map(function (_ref) {
84
+ var _ref2 = (0, _slicedToArray2.default)(_ref, 1),
85
+ path = _ref2[0];
86
+
87
+ return path;
88
+ });
82
89
  } else {
83
90
  item.references = message.origin ? message.origin.map(_utils.joinOrigin) : [];
84
91
  }
@@ -171,6 +178,7 @@ var getMessageKey = R.prop("msgid");
171
178
  var getTranslations = R.prop("msgstr");
172
179
  var getExtractedComments = R.prop("extractedComments");
173
180
  var getTranslatorComments = R.prop("comments");
181
+ var getMessageContext = R.prop("msgctxt");
174
182
  var getOrigins = R.prop("references");
175
183
  var getFlags = R.compose(R.map(R.trim), R.keys, R.dissoc("obsolete"), // backward-compatibility, remove in 3.x
176
184
  R.prop("flags"));
@@ -180,6 +188,7 @@ var deserialize = R.map(R.applySpec({
180
188
  translation: R.compose(R.head, R.defaultTo([]), getTranslations),
181
189
  extractedComments: R.compose(R.defaultTo([]), getExtractedComments),
182
190
  comments: R.compose(R.defaultTo([]), getTranslatorComments),
191
+ context: R.compose(R.defaultTo(null), getMessageContext),
183
192
  obsolete: isObsolete,
184
193
  origin: R.compose(R.map(_utils.splitOrigin), R.defaultTo([]), getOrigins),
185
194
  flags: getFlags
package/api/formats/po.js CHANGED
@@ -9,6 +9,8 @@ Object.defineProperty(exports, "__esModule", {
9
9
  });
10
10
  exports.default = void 0;
11
11
 
12
+ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
13
+
12
14
  var _fs = _interopRequireDefault(require("fs"));
13
15
 
14
16
  var R = _interopRequireWildcard(require("ramda"));
@@ -39,11 +41,18 @@ var serialize = function serialize(items, options) {
39
41
  item.comments = message.comments || [];
40
42
  item.extractedComments = message.extractedComments || [];
41
43
 
44
+ if (message.context) {
45
+ item.msgctxt = message.context;
46
+ }
47
+
42
48
  if (options.origins !== false) {
43
49
  if (message.origin && options.lineNumbers === false) {
44
- item.references = message.origin.map(function (msg) {
45
- return msg.slice(0, -1);
46
- }).map(_utils.joinOrigin);
50
+ item.references = message.origin.map(function (_ref) {
51
+ var _ref2 = (0, _slicedToArray2.default)(_ref, 1),
52
+ path = _ref2[0];
53
+
54
+ return path;
55
+ });
47
56
  } else {
48
57
  item.references = message.origin ? message.origin.map(_utils.joinOrigin) : [];
49
58
  }
@@ -62,6 +71,7 @@ var getMessageKey = R.prop("msgid");
62
71
  var getTranslations = R.prop("msgstr");
63
72
  var getExtractedComments = R.prop("extractedComments");
64
73
  var getTranslatorComments = R.prop("comments");
74
+ var getMessageContext = R.prop("msgctxt");
65
75
  var getOrigins = R.prop("references");
66
76
  var getFlags = R.compose(R.map(R.trim), R.keys, R.dissoc("obsolete"), // backward-compatibility, remove in 3.x
67
77
  R.prop("flags"));
@@ -70,6 +80,7 @@ var deserialize = R.map(R.applySpec({
70
80
  translation: R.compose(R.head, R.defaultTo([]), getTranslations),
71
81
  extractedComments: R.compose(R.defaultTo([]), getExtractedComments),
72
82
  comments: R.compose(R.defaultTo([]), getTranslatorComments),
83
+ context: R.compose(R.defaultTo(null), getMessageContext),
73
84
  obsolete: isObsolete,
74
85
  origin: R.compose(R.map(_utils.splitOrigin), R.defaultTo([]), getOrigins),
75
86
  flags: getFlags
package/lingui-extract.js CHANGED
@@ -7,7 +7,7 @@ Object.defineProperty(exports, "__esModule", {
7
7
  });
8
8
  exports.default = command;
9
9
 
10
- var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
10
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
11
 
12
12
  var _interopRequireWildcard2 = _interopRequireDefault(require("@babel/runtime/helpers/interopRequireWildcard"));
13
13
 
@@ -15,7 +15,11 @@ var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
15
15
 
16
16
  var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
17
17
 
18
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
18
+ var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
19
+
20
+ var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
21
+
22
+ var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
19
23
 
20
24
  var _chalk = _interopRequireDefault(require("chalk"));
21
25
 
@@ -37,55 +41,118 @@ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (O
37
41
 
38
42
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
39
43
 
40
- function command(config, options) {
41
- // `react-app` babel plugin used by CRA requires either BABEL_ENV or NODE_ENV to be
42
- // set. We're setting it here, because lingui macros are going to use them as well.
43
- if (!process.env.BABEL_ENV && !process.env.NODE_ENV) {
44
- process.env.BABEL_ENV = "development";
45
- } // We need macros to keep imports, so extract-messages plugin know what componets
46
- // to collect. Users usually use both BABEN_ENV and NODE_ENV, so it's probably
47
- // safer to introduce a new env variable. LINGUI_EXTRACT=1 during `lingui extract`
48
-
49
-
50
- process.env.LINGUI_EXTRACT = "1";
51
- options.verbose && console.error("Extracting messages from source files…");
52
- var catalogs = (0, _catalog.getCatalogs)(config);
53
- var catalogStats = {};
54
- catalogs.forEach(function (catalog) {
55
- catalog.make(_objectSpread(_objectSpread({}, options), {}, {
56
- orderBy: config.orderBy,
57
- extractors: config.extractors,
58
- projectType: (0, _detect.detect)()
59
- }));
60
- catalogStats[catalog.path] = catalog.readAll();
61
- });
62
- Object.entries(catalogStats).forEach(function (_ref) {
63
- var _ref2 = (0, _slicedToArray2.default)(_ref, 2),
64
- key = _ref2[0],
65
- value = _ref2[1];
66
-
67
- console.log("Catalog statistics for ".concat(key, ": "));
68
- console.log((0, _stats.printStats)(config, value).toString());
69
- console.log();
70
- });
44
+ function _createForOfIteratorHelper(o, allowArrayLike) { var it; if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = o[Symbol.iterator](); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
71
45
 
72
- if (!options.watch) {
73
- console.error("(use \"".concat(_chalk.default.yellow((0, _help.helpRun)("extract")), "\" to update catalogs with new messages)"));
74
- console.error("(use \"".concat(_chalk.default.yellow((0, _help.helpRun)("compile")), "\" to compile catalogs for production)"));
75
- } // If service key is present in configuration, synchronize with cloud translation platform
46
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
76
47
 
48
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
77
49
 
78
- if ((0, _typeof2.default)(config.service) === 'object' && config.service.name && config.service.name.length) {
79
- Promise.resolve("./services/".concat(config.service.name)).then(function (s) {
80
- return (0, _interopRequireWildcard2.default)(require(s));
81
- }).then(function (module) {
82
- return module.default(config, options);
83
- }).catch(function (err) {
84
- return console.error("Can't load service module ".concat(config.service.name), err);
85
- });
86
- }
50
+ function command(_x, _x2) {
51
+ return _command.apply(this, arguments);
52
+ }
87
53
 
88
- return true;
54
+ function _command() {
55
+ _command = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2(config, options) {
56
+ var catalogs, catalogStats, _iterator, _step, catalog, moduleName;
57
+
58
+ return _regenerator.default.wrap(function _callee2$(_context2) {
59
+ while (1) {
60
+ switch (_context2.prev = _context2.next) {
61
+ case 0:
62
+ // `react-app` babel plugin used by CRA requires either BABEL_ENV or NODE_ENV to be
63
+ // set. We're setting it here, because lingui macros are going to use them as well.
64
+ if (!process.env.BABEL_ENV && !process.env.NODE_ENV) {
65
+ process.env.BABEL_ENV = "development";
66
+ } // We need macros to keep imports, so extract-messages plugin know what componets
67
+ // to collect. Users usually use both BABEN_ENV and NODE_ENV, so it's probably
68
+ // safer to introduce a new env variable. LINGUI_EXTRACT=1 during `lingui extract`
69
+
70
+
71
+ process.env.LINGUI_EXTRACT = "1";
72
+ options.verbose && console.error("Extracting messages from source files…");
73
+ catalogs = (0, _catalog.getCatalogs)(config);
74
+ catalogStats = {};
75
+ _iterator = _createForOfIteratorHelper(catalogs);
76
+ _context2.prev = 6;
77
+
78
+ _iterator.s();
79
+
80
+ case 8:
81
+ if ((_step = _iterator.n()).done) {
82
+ _context2.next = 15;
83
+ break;
84
+ }
85
+
86
+ catalog = _step.value;
87
+ _context2.next = 12;
88
+ return catalog.make(_objectSpread(_objectSpread({}, options), {}, {
89
+ orderBy: config.orderBy,
90
+ extractors: config.extractors,
91
+ projectType: (0, _detect.detect)()
92
+ }));
93
+
94
+ case 12:
95
+ catalogStats[catalog.path] = catalog.readAll();
96
+
97
+ case 13:
98
+ _context2.next = 8;
99
+ break;
100
+
101
+ case 15:
102
+ _context2.next = 20;
103
+ break;
104
+
105
+ case 17:
106
+ _context2.prev = 17;
107
+ _context2.t0 = _context2["catch"](6);
108
+
109
+ _iterator.e(_context2.t0);
110
+
111
+ case 20:
112
+ _context2.prev = 20;
113
+
114
+ _iterator.f();
115
+
116
+ return _context2.finish(20);
117
+
118
+ case 23:
119
+ Object.entries(catalogStats).forEach(function (_ref2) {
120
+ var _ref3 = (0, _slicedToArray2.default)(_ref2, 2),
121
+ key = _ref3[0],
122
+ value = _ref3[1];
123
+
124
+ console.log("Catalog statistics for ".concat(key, ": "));
125
+ console.log((0, _stats.printStats)(config, value).toString());
126
+ console.log();
127
+ });
128
+
129
+ if (!options.watch) {
130
+ console.error("(use \"".concat(_chalk.default.yellow((0, _help.helpRun)("extract")), "\" to update catalogs with new messages)"));
131
+ console.error("(use \"".concat(_chalk.default.yellow((0, _help.helpRun)("compile")), "\" to compile catalogs for production)"));
132
+ } // If service key is present in configuration, synchronize with cloud translation platform
133
+
134
+
135
+ if ((0, _typeof2.default)(config.service) === 'object' && config.service.name && config.service.name.length) {
136
+ moduleName = config.service.name.charAt(0).toLowerCase() + config.service.name.slice(1);
137
+ Promise.resolve("./services/".concat(moduleName)).then(function (s) {
138
+ return (0, _interopRequireWildcard2.default)(require(s));
139
+ }).then(function (module) {
140
+ return module.default(config, options);
141
+ }).catch(function (err) {
142
+ return console.error("Can't load service module ".concat(moduleName), err);
143
+ });
144
+ }
145
+
146
+ return _context2.abrupt("return", true);
147
+
148
+ case 27:
149
+ case "end":
150
+ return _context2.stop();
151
+ }
152
+ }
153
+ }, _callee2, null, [[6, 17, 20, 23]]);
154
+ }));
155
+ return _command.apply(this, arguments);
89
156
  }
90
157
 
91
158
  if (require.main === module) {
@@ -157,11 +224,24 @@ if (require.main === module) {
157
224
  }); // CLear the previous timer if there is any, and schedule the next
158
225
 
159
226
  debounceTimer && clearTimeout(debounceTimer);
160
- debounceTimer = setTimeout(function () {
161
- var filePath = (0, _toConsumableArray2.default)(changedPaths);
162
- changedPaths.clear();
163
- extract(filePath);
164
- }, _commander.default.debounce);
227
+ debounceTimer = setTimeout( /*#__PURE__*/(0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee() {
228
+ var filePath;
229
+ return _regenerator.default.wrap(function _callee$(_context) {
230
+ while (1) {
231
+ switch (_context.prev = _context.next) {
232
+ case 0:
233
+ filePath = (0, _toConsumableArray2.default)(changedPaths);
234
+ changedPaths.clear();
235
+ _context.next = 4;
236
+ return extract(filePath);
237
+
238
+ case 4:
239
+ case "end":
240
+ return _context.stop();
241
+ }
242
+ }
243
+ }, _callee);
244
+ })), _commander.default.debounce);
165
245
  }; // Check if Watch Mode is enabled
166
246
 
167
247
 
@@ -195,11 +275,12 @@ if (require.main === module) {
195
275
  } else if (_commander.default.args) {
196
276
  // this behaviour occurs when we extract files by his name
197
277
  // for ex: lingui extract src/app, this will extract only files included in src/app
198
- var result = extract(_commander.default.args);
199
- if (!result) process.exit(1);
278
+ extract(_commander.default.args).then(function (result) {
279
+ if (!result) process.exit(1);
280
+ });
200
281
  } else {
201
- var _result = extract();
202
-
203
- if (!_result) process.exit(1);
282
+ extract().then(function (result) {
283
+ if (!result) process.exit(1);
284
+ });
204
285
  }
205
286
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lingui/cli",
3
- "version": "3.12.0",
3
+ "version": "3.13.2",
4
4
  "description": "CLI for working wit message catalogs",
5
5
  "keywords": [
6
6
  "cli",
@@ -39,13 +39,13 @@
39
39
  "@babel/plugin-syntax-jsx": "^7.10.4",
40
40
  "@babel/runtime": "^7.11.2",
41
41
  "@babel/types": "^7.11.5",
42
- "@lingui/babel-plugin-extract-messages": "^3.12.0",
43
- "@lingui/conf": "^3.12.0",
42
+ "@lingui/babel-plugin-extract-messages": "^3.13.2",
43
+ "@lingui/conf": "^3.13.2",
44
44
  "babel-plugin-macros": "^3.0.1",
45
45
  "bcp-47": "^1.0.7",
46
46
  "chalk": "^4.1.0",
47
47
  "chokidar": "3.5.1",
48
- "cli-table": "^0.3.1",
48
+ "cli-table": "0.3.6",
49
49
  "commander": "^6.1.0",
50
50
  "date-fns": "^2.16.1",
51
51
  "fs-extra": "^9.0.1",
@@ -58,8 +58,9 @@ function syncProcess(config, options) {
58
58
 
59
59
  function init(config, options, successCallback, failCallback) {
60
60
  var sourceLocale = config.sourceLocale || 'en';
61
+ var pseudoLocale = config.pseudoLocale || 'pseudo';
61
62
  var targetLocales = config.locales.filter(function (value) {
62
- return value != sourceLocale;
63
+ return value != sourceLocale && value != pseudoLocale;
63
64
  });
64
65
  var paths = poPathsPerLocale(config);
65
66
  var segments = {};