@lingui/cli 3.15.0 → 3.16.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 +495 -0
- package/build/LICENSE +21 -0
- package/build/api/catalog.js +582 -0
- package/build/api/compile.js +89 -0
- package/{api → build/api}/detect.js +23 -9
- package/build/api/extract.js +78 -0
- package/build/api/extractors/babel.js +51 -0
- package/build/api/extractors/index.js +51 -0
- package/build/api/extractors/typescript.js +71 -0
- package/build/api/formats/csv.js +65 -0
- package/{api → build/api}/formats/index.js +8 -5
- package/build/api/formats/lingui.js +67 -0
- package/build/api/formats/minimal.js +63 -0
- package/build/api/formats/po-gettext.js +296 -0
- package/build/api/formats/po.js +122 -0
- package/{api → build/api}/help.js +6 -18
- package/{api → build/api}/index.js +7 -7
- package/build/api/locales.js +45 -0
- package/{api → build/api}/pseudoLocalize.js +13 -13
- package/build/api/stats.js +46 -0
- package/{api → build/api}/utils.js +21 -40
- package/build/lingui-add-locale.js +11 -0
- package/build/lingui-compile.js +192 -0
- package/build/lingui-extract-template.js +64 -0
- package/build/lingui-extract.js +181 -0
- package/{lingui.js → build/lingui.js} +2 -2
- package/{services → build/services}/translationIO.js +78 -94
- package/build/tests.js +78 -0
- package/package.json +24 -12
- package/api/catalog.js +0 -778
- package/api/compile.js +0 -172
- package/api/extract.js +0 -192
- package/api/extractors/babel.js +0 -61
- package/api/extractors/index.js +0 -130
- package/api/extractors/typescript.js +0 -77
- package/api/formats/csv.js +0 -71
- package/api/formats/lingui.js +0 -64
- package/api/formats/minimal.js +0 -63
- package/api/formats/po-gettext.js +0 -331
- package/api/formats/po.js +0 -130
- package/api/locales.js +0 -43
- package/api/stats.js +0 -51
- package/lingui-add-locale.js +0 -11
- package/lingui-compile.js +0 -198
- package/lingui-extract-template.js +0 -123
- package/lingui-extract.js +0 -286
package/api/compile.js
DELETED
|
@@ -1,172 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");
|
|
4
|
-
|
|
5
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
6
|
-
|
|
7
|
-
Object.defineProperty(exports, "__esModule", {
|
|
8
|
-
value: true
|
|
9
|
-
});
|
|
10
|
-
exports.createCompiledCatalog = createCompiledCatalog;
|
|
11
|
-
exports.compile = compile;
|
|
12
|
-
|
|
13
|
-
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
14
|
-
|
|
15
|
-
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
|
|
16
|
-
|
|
17
|
-
var t = _interopRequireWildcard(require("@babel/types"));
|
|
18
|
-
|
|
19
|
-
var _generator = _interopRequireDefault(require("@babel/generator"));
|
|
20
|
-
|
|
21
|
-
var _messageformatParser = require("messageformat-parser");
|
|
22
|
-
|
|
23
|
-
var R = _interopRequireWildcard(require("ramda"));
|
|
24
|
-
|
|
25
|
-
var _pseudoLocalize = _interopRequireDefault(require("./pseudoLocalize"));
|
|
26
|
-
|
|
27
|
-
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
|
-
|
|
29
|
-
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; }
|
|
30
|
-
|
|
31
|
-
var INVALID_OBJECT_KEY_REGEX = /^(\d+[a-zA-Z]|[a-zA-Z]+\d)(\d|[a-zA-Z])*/;
|
|
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
|
-
return t.objectProperty(t.stringLiteral(key), compile(translation, shouldPseudolocalize));
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
function createCompiledCatalog(locale, messages, options) {
|
|
42
|
-
var _options$strict = options.strict,
|
|
43
|
-
strict = _options$strict === void 0 ? false : _options$strict,
|
|
44
|
-
_options$namespace = options.namespace,
|
|
45
|
-
namespace = _options$namespace === void 0 ? "cjs" : _options$namespace,
|
|
46
|
-
pseudoLocale = options.pseudoLocale,
|
|
47
|
-
_options$compilerBabe = options.compilerBabelOptions,
|
|
48
|
-
compilerBabelOptions = _options$compilerBabe === void 0 ? {} : _options$compilerBabe,
|
|
49
|
-
_options$pure = options.pure,
|
|
50
|
-
pure = _options$pure === void 0 ? false : _options$pure;
|
|
51
|
-
var shouldPseudolocalize = locale === pseudoLocale;
|
|
52
|
-
var compiledMessages = R.keys(messages).map(function (key) {
|
|
53
|
-
var value = messages[key]; // If the current ID's value is a context object, create a nested
|
|
54
|
-
// expression, and assign the current ID to that expression
|
|
55
|
-
|
|
56
|
-
if ((0, _typeof2.default)(value) === "object") {
|
|
57
|
-
var contextExpression = t.objectExpression(Object.keys(value).map(function (contextKey) {
|
|
58
|
-
var contextTranslation = value[contextKey];
|
|
59
|
-
return compileSingleKey(contextKey, contextTranslation, shouldPseudolocalize);
|
|
60
|
-
}));
|
|
61
|
-
return t.objectProperty(t.stringLiteral(key), contextExpression);
|
|
62
|
-
} // Don't use `key` as a fallback translation in strict mode.
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
var translation = messages[key] || (!strict ? key : "");
|
|
66
|
-
return compileSingleKey(key, translation, shouldPseudolocalize);
|
|
67
|
-
});
|
|
68
|
-
var ast = pure ? t.objectExpression(compiledMessages) : buildExportStatement(t.objectExpression(compiledMessages), namespace);
|
|
69
|
-
var code = (0, _generator.default)(ast, _objectSpread({
|
|
70
|
-
minified: true,
|
|
71
|
-
jsescOption: {
|
|
72
|
-
minimal: true
|
|
73
|
-
}
|
|
74
|
-
}, compilerBabelOptions)).code;
|
|
75
|
-
return pure ? JSON.parse(code) : "/*eslint-disable*/" + code;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
function buildExportStatement(expression, namespace) {
|
|
79
|
-
if (namespace === "es" || namespace === "ts") {
|
|
80
|
-
// export const messages = { message: "Translation" }
|
|
81
|
-
return t.exportNamedDeclaration(t.variableDeclaration("const", [t.variableDeclarator(t.identifier("messages"), expression)]));
|
|
82
|
-
} else {
|
|
83
|
-
var exportExpression = null;
|
|
84
|
-
var matches = namespace.match(/^(window|global)\.([^.\s]+)$/);
|
|
85
|
-
|
|
86
|
-
if (namespace === "cjs") {
|
|
87
|
-
// module.exports.messages = { message: "Translation" }
|
|
88
|
-
exportExpression = t.memberExpression(t.identifier("module"), t.identifier("exports"));
|
|
89
|
-
} else if (matches) {
|
|
90
|
-
// window.i18nMessages = { messages: { message: "Translation" }}
|
|
91
|
-
exportExpression = t.memberExpression(t.identifier(matches[1]), t.identifier(matches[2]));
|
|
92
|
-
} else {
|
|
93
|
-
throw new Error("Invalid namespace param: \"".concat(namespace, "\""));
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
return t.expressionStatement(t.assignmentExpression("=", exportExpression, t.objectExpression([t.objectProperty(t.identifier("messages"), expression)])));
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
/**
|
|
100
|
-
* Compile string message into AST tree. Message format is parsed/compiled into
|
|
101
|
-
* JS arrays, which are handled in client.
|
|
102
|
-
*/
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
function compile(message) {
|
|
106
|
-
var shouldPseudolocalize = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
107
|
-
var tokens;
|
|
108
|
-
|
|
109
|
-
try {
|
|
110
|
-
tokens = (0, _messageformatParser.parse)(message);
|
|
111
|
-
} catch (e) {
|
|
112
|
-
throw new Error("Can't parse message. Please check correct syntax: \"".concat(message, "\" \n \n Messageformat-parser trace: ").concat(e.message));
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
var ast = processTokens(tokens, shouldPseudolocalize);
|
|
116
|
-
if (isString(ast)) return t.stringLiteral(ast);
|
|
117
|
-
return ast;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
function processTokens(tokens, shouldPseudolocalize) {
|
|
121
|
-
// Shortcut - if the message doesn't include any formatting,
|
|
122
|
-
// simply join all string chunks into one message
|
|
123
|
-
if (!tokens.filter(function (token) {
|
|
124
|
-
return !isString(token);
|
|
125
|
-
}).length) {
|
|
126
|
-
if (shouldPseudolocalize) {
|
|
127
|
-
return tokens.map(function (token) {
|
|
128
|
-
return (0, _pseudoLocalize.default)(token);
|
|
129
|
-
}).join("");
|
|
130
|
-
} else {
|
|
131
|
-
return tokens.join("");
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
return t.arrayExpression(tokens.map(function (token) {
|
|
136
|
-
if (isString(token)) {
|
|
137
|
-
return t.stringLiteral(shouldPseudolocalize ? (0, _pseudoLocalize.default)(token) : token); // # in plural case
|
|
138
|
-
} else if (token.type === "octothorpe") {
|
|
139
|
-
return t.stringLiteral("#"); // simple argument
|
|
140
|
-
} else if (token.type === "argument") {
|
|
141
|
-
return t.arrayExpression([t.stringLiteral(token.arg)]); // argument with custom format (date, number)
|
|
142
|
-
} else if (token.type === "function") {
|
|
143
|
-
var _params = [t.stringLiteral(token.arg), t.stringLiteral(token.key)];
|
|
144
|
-
var format = token.param && token.param.tokens[0];
|
|
145
|
-
|
|
146
|
-
if (format) {
|
|
147
|
-
_params.push(t.stringLiteral(format.trim()));
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
return t.arrayExpression(_params);
|
|
151
|
-
} // complex argument with cases
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
var formatProps = [];
|
|
155
|
-
|
|
156
|
-
if (token.offset) {
|
|
157
|
-
formatProps.push(t.objectProperty(t.identifier("offset"), t.numericLiteral(parseInt(token.offset))));
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
token.cases.forEach(function (item) {
|
|
161
|
-
var inlineTokens = processTokens(item.tokens, shouldPseudolocalize);
|
|
162
|
-
formatProps.push(t.objectProperty( // if starts with number must be wrapped with quotes
|
|
163
|
-
INVALID_OBJECT_KEY_REGEX.test(item.key) ? t.stringLiteral(item.key) : t.identifier(item.key), isString(inlineTokens) ? t.stringLiteral(inlineTokens) : inlineTokens));
|
|
164
|
-
});
|
|
165
|
-
var params = [t.stringLiteral(token.arg), t.stringLiteral(token.type), t.objectExpression(formatProps)];
|
|
166
|
-
return t.arrayExpression(params);
|
|
167
|
-
}));
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
var isString = function isString(s) {
|
|
171
|
-
return typeof s === "string";
|
|
172
|
-
};
|
package/api/extract.js
DELETED
|
@@ -1,192 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");
|
|
4
|
-
|
|
5
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
6
|
-
|
|
7
|
-
Object.defineProperty(exports, "__esModule", {
|
|
8
|
-
value: true
|
|
9
|
-
});
|
|
10
|
-
exports.extract = extract;
|
|
11
|
-
exports.collect = collect;
|
|
12
|
-
|
|
13
|
-
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
14
|
-
|
|
15
|
-
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
16
|
-
|
|
17
|
-
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
18
|
-
|
|
19
|
-
var _fs = _interopRequireDefault(require("fs"));
|
|
20
|
-
|
|
21
|
-
var _path = _interopRequireDefault(require("path"));
|
|
22
|
-
|
|
23
|
-
var _chalk = _interopRequireDefault(require("chalk"));
|
|
24
|
-
|
|
25
|
-
var R = _interopRequireWildcard(require("ramda"));
|
|
26
|
-
|
|
27
|
-
var _utils = require("./utils");
|
|
28
|
-
|
|
29
|
-
var _extractors = _interopRequireDefault(require("./extractors"));
|
|
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
|
-
|
|
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; }
|
|
38
|
-
|
|
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; }
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* Merge origins for messages found in different places. All other attributes
|
|
43
|
-
* should be the same (raise an error if defaults are different).
|
|
44
|
-
*/
|
|
45
|
-
function mergeMessage(msgId, prev, next) {
|
|
46
|
-
if (prev.message && next.message && prev.message !== next.message) {
|
|
47
|
-
throw new Error("Encountered different default translations for message ".concat(_chalk.default.yellow(msgId)) + "\n".concat(_chalk.default.yellow((0, _utils.prettyOrigin)(prev.origin)), " ").concat(prev.message) + "\n".concat(_chalk.default.yellow((0, _utils.prettyOrigin)(next.origin)), " ").concat(next.message));
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
return _objectSpread(_objectSpread({}, next), {}, {
|
|
51
|
-
message: prev.message || next.message,
|
|
52
|
-
origin: R.concat(prev.origin, next.origin)
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
function extract(_x, _x2) {
|
|
57
|
-
return _extract.apply(this, arguments);
|
|
58
|
-
}
|
|
59
|
-
|
|
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);
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
function collect(buildDir) {
|
|
175
|
-
return _fs.default.readdirSync(buildDir).sort().map(function (filename) {
|
|
176
|
-
var filepath = _path.default.join(buildDir, filename);
|
|
177
|
-
|
|
178
|
-
if (_fs.default.lstatSync(filepath).isDirectory()) {
|
|
179
|
-
return collect(filepath);
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
if (!filename.endsWith(".json")) return;
|
|
183
|
-
|
|
184
|
-
try {
|
|
185
|
-
return JSON.parse(_fs.default.readFileSync(filepath).toString());
|
|
186
|
-
} catch (e) {
|
|
187
|
-
return {};
|
|
188
|
-
}
|
|
189
|
-
}).filter(Boolean).reduce(function (catalog, messages) {
|
|
190
|
-
return R.mergeWithKey(mergeMessage, catalog, messages);
|
|
191
|
-
}, {});
|
|
192
|
-
}
|
package/api/extractors/babel.js
DELETED
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
|
-
Object.defineProperty(exports, "__esModule", {
|
|
6
|
-
value: true
|
|
7
|
-
});
|
|
8
|
-
exports.default = void 0;
|
|
9
|
-
|
|
10
|
-
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
|
-
|
|
12
|
-
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
|
|
13
|
-
|
|
14
|
-
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
15
|
-
|
|
16
|
-
var _core = require("@babel/core");
|
|
17
|
-
|
|
18
|
-
var _babelPluginExtractMessages = _interopRequireDefault(require("@lingui/babel-plugin-extract-messages"));
|
|
19
|
-
|
|
20
|
-
var _detect = require("../detect");
|
|
21
|
-
|
|
22
|
-
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; }
|
|
23
|
-
|
|
24
|
-
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; }
|
|
25
|
-
|
|
26
|
-
var babelRe = new RegExp("\\.(" + [].concat((0, _toConsumableArray2.default)(_core.DEFAULT_EXTENSIONS), [".ts", ".tsx"]).map(function (ext) {
|
|
27
|
-
return ext.slice(1);
|
|
28
|
-
}).join("|") + ")$", "i");
|
|
29
|
-
var extractor = {
|
|
30
|
-
match: function match(filename) {
|
|
31
|
-
return babelRe.test(filename);
|
|
32
|
-
},
|
|
33
|
-
extract: function extract(filename, localeDir) {
|
|
34
|
-
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
35
|
-
|
|
36
|
-
var _options$babelOptions = options.babelOptions,
|
|
37
|
-
_babelOptions = _options$babelOptions === void 0 ? {} : _options$babelOptions,
|
|
38
|
-
configPath = options.configPath;
|
|
39
|
-
|
|
40
|
-
var _babelOptions$plugins = _babelOptions.plugins,
|
|
41
|
-
plugins = _babelOptions$plugins === void 0 ? [] : _babelOptions$plugins,
|
|
42
|
-
babelOptions = (0, _objectWithoutProperties2.default)(_babelOptions, ["plugins"]);
|
|
43
|
-
var frameworkOptions = {};
|
|
44
|
-
|
|
45
|
-
if (options.projectType === _detect.projectType.CRA) {
|
|
46
|
-
frameworkOptions.presets = ["react-app"];
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
(0, _core.transformFileSync)(filename, _objectSpread(_objectSpread(_objectSpread({}, babelOptions), frameworkOptions), {}, {
|
|
50
|
-
// we override envName to avoid issues with NODE_ENV=production
|
|
51
|
-
// https://github.com/lingui/js-lingui/issues/952
|
|
52
|
-
envName: "development",
|
|
53
|
-
plugins: ["macros", [_babelPluginExtractMessages.default, {
|
|
54
|
-
localeDir: localeDir,
|
|
55
|
-
configPath: configPath
|
|
56
|
-
}]].concat((0, _toConsumableArray2.default)(plugins))
|
|
57
|
-
}));
|
|
58
|
-
}
|
|
59
|
-
};
|
|
60
|
-
var _default = extractor;
|
|
61
|
-
exports.default = _default;
|
package/api/extractors/index.js
DELETED
|
@@ -1,130 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
|
-
Object.defineProperty(exports, "__esModule", {
|
|
6
|
-
value: true
|
|
7
|
-
});
|
|
8
|
-
exports.default = extract;
|
|
9
|
-
|
|
10
|
-
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
11
|
-
|
|
12
|
-
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
13
|
-
|
|
14
|
-
var _ora = _interopRequireDefault(require("ora"));
|
|
15
|
-
|
|
16
|
-
var _babel = _interopRequireDefault(require("./babel"));
|
|
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
|
-
|
|
24
|
-
var DEFAULT_EXTRACTORS = [_babel.default];
|
|
25
|
-
|
|
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
|
-
}
|
|
68
|
-
|
|
69
|
-
return _context.abrupt("continue", 24);
|
|
70
|
-
|
|
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);
|
|
130
|
-
}
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
|
-
Object.defineProperty(exports, "__esModule", {
|
|
6
|
-
value: true
|
|
7
|
-
});
|
|
8
|
-
exports.default = void 0;
|
|
9
|
-
|
|
10
|
-
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
|
-
|
|
12
|
-
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
13
|
-
|
|
14
|
-
var _fs = _interopRequireDefault(require("fs"));
|
|
15
|
-
|
|
16
|
-
var _core = require("@babel/core");
|
|
17
|
-
|
|
18
|
-
var _babelPluginExtractMessages = _interopRequireDefault(require("@lingui/babel-plugin-extract-messages"));
|
|
19
|
-
|
|
20
|
-
var _detect = require("../detect");
|
|
21
|
-
|
|
22
|
-
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; }
|
|
23
|
-
|
|
24
|
-
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; }
|
|
25
|
-
|
|
26
|
-
var typescriptRe = /(^.?|\.[^d]|[^.]d|[^.][^d])\.tsx?$/i;
|
|
27
|
-
var extractor = {
|
|
28
|
-
match: function match(filename) {
|
|
29
|
-
return typescriptRe.test(filename);
|
|
30
|
-
},
|
|
31
|
-
extract: function extract(filename, localeDir) {
|
|
32
|
-
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
33
|
-
|
|
34
|
-
var ts = require("typescript");
|
|
35
|
-
|
|
36
|
-
var content = _fs.default.readFileSync(filename, "utf8");
|
|
37
|
-
|
|
38
|
-
var isTsx = filename.endsWith(".tsx"); // pass jsx to babel untouched
|
|
39
|
-
|
|
40
|
-
var jsx = isTsx ? ts.JsxEmit.Preserve : ts.JsxEmit.None;
|
|
41
|
-
var stripped = ts.transpileModule(content, {
|
|
42
|
-
compilerOptions: {
|
|
43
|
-
filename: filename,
|
|
44
|
-
jsx: jsx,
|
|
45
|
-
module: ts.ModuleKind.ESNext,
|
|
46
|
-
target: ts.ScriptTarget.ES2016,
|
|
47
|
-
// use ES2015 or ES2016 to preserve tagged template literal
|
|
48
|
-
allowSyntheticDefaultImports: true,
|
|
49
|
-
moduleResolution: ts.ModuleResolutionKind.NodeJs
|
|
50
|
-
}
|
|
51
|
-
});
|
|
52
|
-
var frameworkOptions = {};
|
|
53
|
-
|
|
54
|
-
if (options.projectType === _detect.projectType.CRA) {
|
|
55
|
-
frameworkOptions.presets = ["react-app"];
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
var _options$babelOptions = options.babelOptions,
|
|
59
|
-
babelOptions = _options$babelOptions === void 0 ? {} : _options$babelOptions,
|
|
60
|
-
configPath = options.configPath;
|
|
61
|
-
var plugins = ["macros", [_babelPluginExtractMessages.default, {
|
|
62
|
-
localeDir: localeDir,
|
|
63
|
-
configPath: configPath
|
|
64
|
-
}]].concat((0, _toConsumableArray2.default)(babelOptions.plugins || []));
|
|
65
|
-
|
|
66
|
-
if (isTsx) {
|
|
67
|
-
plugins.unshift(require.resolve("@babel/plugin-syntax-jsx"));
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
(0, _core.transform)(stripped.outputText, _objectSpread(_objectSpread(_objectSpread({}, babelOptions), frameworkOptions), {}, {
|
|
71
|
-
filename: filename,
|
|
72
|
-
plugins: plugins
|
|
73
|
-
}));
|
|
74
|
-
}
|
|
75
|
-
};
|
|
76
|
-
var _default = extractor;
|
|
77
|
-
exports.default = _default;
|