@lingui/cli 3.14.0 → 3.16.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +482 -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 +19 -13
- package/api/catalog.js +0 -775
- package/api/compile.js +0 -169
- 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 -50
- 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 -199
- package/lingui-extract-template.js +0 -71
- package/lingui-extract.js +0 -286
package/api/stats.js
DELETED
|
@@ -1,51 +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.getStats = getStats;
|
|
9
|
-
exports.printStats = printStats;
|
|
10
|
-
|
|
11
|
-
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
12
|
-
|
|
13
|
-
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
14
|
-
|
|
15
|
-
var _cliTable = _interopRequireDefault(require("cli-table"));
|
|
16
|
-
|
|
17
|
-
var _chalk = _interopRequireDefault(require("chalk"));
|
|
18
|
-
|
|
19
|
-
function getStats(catalog) {
|
|
20
|
-
return [Object.keys(catalog).length, Object.keys(catalog).filter(function (key) {
|
|
21
|
-
return !catalog[key].translation;
|
|
22
|
-
}).length];
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
function printStats(config, catalogs) {
|
|
26
|
-
var table = new _cliTable.default({
|
|
27
|
-
head: ["Language", "Total count", "Missing"],
|
|
28
|
-
colAligns: ["left", "middle", "middle"],
|
|
29
|
-
style: {
|
|
30
|
-
head: ["green"],
|
|
31
|
-
border: [],
|
|
32
|
-
compact: true
|
|
33
|
-
}
|
|
34
|
-
});
|
|
35
|
-
Object.keys(catalogs).forEach(function (locale) {
|
|
36
|
-
var catalog = catalogs[locale]; // catalog is null if no catalog exists on disk and the locale
|
|
37
|
-
// was not extracted due to a `--locale` filter
|
|
38
|
-
|
|
39
|
-
var _ref = catalog ? getStats(catalog) : ["-", "-"],
|
|
40
|
-
_ref2 = (0, _slicedToArray2.default)(_ref, 2),
|
|
41
|
-
all = _ref2[0],
|
|
42
|
-
translated = _ref2[1];
|
|
43
|
-
|
|
44
|
-
if (config.sourceLocale === locale) {
|
|
45
|
-
table.push((0, _defineProperty2.default)({}, "".concat(_chalk.default.bold(locale), " (source)"), [all, "-"]));
|
|
46
|
-
} else {
|
|
47
|
-
table.push((0, _defineProperty2.default)({}, locale, [all, translated]));
|
|
48
|
-
}
|
|
49
|
-
});
|
|
50
|
-
return table;
|
|
51
|
-
}
|
package/lingui-add-locale.js
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
|
-
var _chalk = _interopRequireDefault(require("chalk"));
|
|
6
|
-
|
|
7
|
-
if (require.main === module) {
|
|
8
|
-
var msg = "lingui add-locale command is deprecated. " + "Please set ".concat(_chalk.default.yellow("'locales'"), " in configuration. ") + _chalk.default.underline("https://lingui.js.org/ref/conf.html#locales");
|
|
9
|
-
|
|
10
|
-
console.error(msg);
|
|
11
|
-
}
|
package/lingui-compile.js
DELETED
|
@@ -1,199 +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
|
-
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
8
|
-
|
|
9
|
-
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
10
|
-
|
|
11
|
-
var _chalk = _interopRequireDefault(require("chalk"));
|
|
12
|
-
|
|
13
|
-
var _chokidar = _interopRequireDefault(require("chokidar"));
|
|
14
|
-
|
|
15
|
-
var _fs = _interopRequireDefault(require("fs"));
|
|
16
|
-
|
|
17
|
-
var R = _interopRequireWildcard(require("ramda"));
|
|
18
|
-
|
|
19
|
-
var _commander = _interopRequireDefault(require("commander"));
|
|
20
|
-
|
|
21
|
-
var plurals = _interopRequireWildcard(require("make-plural"));
|
|
22
|
-
|
|
23
|
-
var _conf = require("@lingui/conf");
|
|
24
|
-
|
|
25
|
-
var _catalog = require("./api/catalog");
|
|
26
|
-
|
|
27
|
-
var _compile = require("./api/compile");
|
|
28
|
-
|
|
29
|
-
var _help = require("./api/help");
|
|
30
|
-
|
|
31
|
-
var _api = require("./api");
|
|
32
|
-
|
|
33
|
-
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; }
|
|
34
|
-
|
|
35
|
-
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; }
|
|
36
|
-
|
|
37
|
-
var noMessages = R.pipe(R.map(R.isEmpty), R.values, R.all(R.equals(true)));
|
|
38
|
-
|
|
39
|
-
function command(config, options) {
|
|
40
|
-
var catalogs = (0, _catalog.getCatalogs)(config);
|
|
41
|
-
|
|
42
|
-
if (noMessages(catalogs)) {
|
|
43
|
-
console.error("Nothing to compile, message catalogs are empty!\n");
|
|
44
|
-
console.error("(use \"".concat(_chalk.default.yellow((0, _help.helpRun)("extract")), "\" to extract messages from source files)"));
|
|
45
|
-
return false;
|
|
46
|
-
} // Check config.compile.merge if catalogs for current locale are to be merged into a single compiled file
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
var doMerge = !!config.catalogsMergePath;
|
|
50
|
-
var mergedCatalogs = {};
|
|
51
|
-
console.error("Compiling message catalogs…");
|
|
52
|
-
config.locales.forEach(function (locale) {
|
|
53
|
-
var _locale$split = locale.split(/[_-]/),
|
|
54
|
-
_locale$split2 = (0, _slicedToArray2.default)(_locale$split, 1),
|
|
55
|
-
language = _locale$split2[0];
|
|
56
|
-
|
|
57
|
-
if (locale !== config.pseudoLocale && !plurals[language]) {
|
|
58
|
-
console.log(_chalk.default.red("Error: Invalid locale ".concat(_chalk.default.bold(locale), " (missing plural rules)!")));
|
|
59
|
-
console.error();
|
|
60
|
-
process.exit(1);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
catalogs.forEach(function (catalog) {
|
|
64
|
-
var messages = catalog.getTranslations(locale, {
|
|
65
|
-
fallbackLocales: config.fallbackLocales,
|
|
66
|
-
sourceLocale: config.sourceLocale
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
if (!options.allowEmpty) {
|
|
70
|
-
var missingMsgIds = R.pipe(R.pickBy(R.isNil), R.keys)(messages);
|
|
71
|
-
|
|
72
|
-
if (missingMsgIds.length > 0) {
|
|
73
|
-
console.error(_chalk.default.red("Error: Failed to compile catalog for locale ".concat(_chalk.default.bold(locale), "!")));
|
|
74
|
-
|
|
75
|
-
if (options.verbose) {
|
|
76
|
-
console.error(_chalk.default.red("Missing translations:"));
|
|
77
|
-
missingMsgIds.forEach(function (msgId) {
|
|
78
|
-
return console.log(msgId);
|
|
79
|
-
});
|
|
80
|
-
} else {
|
|
81
|
-
console.error(_chalk.default.red("Missing ".concat(missingMsgIds.length, " translation(s)")));
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
console.error();
|
|
85
|
-
process.exit(1);
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
if (doMerge) {
|
|
90
|
-
mergedCatalogs = _objectSpread(_objectSpread({}, mergedCatalogs), messages);
|
|
91
|
-
} else {
|
|
92
|
-
var namespace = options.typescript ? "ts" : options.namespace || config.compileNamespace;
|
|
93
|
-
var compiledCatalog = (0, _compile.createCompiledCatalog)(locale, messages, {
|
|
94
|
-
strict: false,
|
|
95
|
-
namespace: namespace,
|
|
96
|
-
pseudoLocale: config.pseudoLocale,
|
|
97
|
-
compilerBabelOptions: config.compilerBabelOptions
|
|
98
|
-
});
|
|
99
|
-
var compiledPath = catalog.writeCompiled(locale, compiledCatalog, namespace);
|
|
100
|
-
|
|
101
|
-
if (options.typescript) {
|
|
102
|
-
var typescriptPath = compiledPath.replace(/\.ts?$/, "") + ".d.ts";
|
|
103
|
-
|
|
104
|
-
_fs.default.writeFileSync(typescriptPath, "import { Messages } from '@lingui/core';\n declare const messages: Messages;\n export { messages };\n ");
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
options.verbose && console.error(_chalk.default.green("".concat(locale, " \u21D2 ").concat(compiledPath)));
|
|
108
|
-
}
|
|
109
|
-
});
|
|
110
|
-
});
|
|
111
|
-
return true;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
if (require.main === module) {
|
|
115
|
-
_commander.default.description("Add compile message catalogs and add language data (plurals) to compiled bundle.").option("--config <path>", "Path to the config file").option("--strict", "Disable defaults for missing translations").option("--verbose", "Verbose output").option("--format <format>", "Format of message catalog").option("--typescript", "Create Typescript definition for compiled bundle").option("--namespace <namespace>", "Specify namespace for compiled bundle. Ex: cjs(default) -> module.exports, es -> export, window.test -> window.test").option("--watch", "Enables Watch Mode").option("--debounce <delay>", "Debounces compilation for given amount of milliseconds").on("--help", function () {
|
|
116
|
-
console.log("\n Examples:\n");
|
|
117
|
-
console.log(" # Compile translations and use defaults or message IDs for missing translations");
|
|
118
|
-
console.log(" $ ".concat((0, _help.helpRun)("compile")));
|
|
119
|
-
console.log("");
|
|
120
|
-
console.log(" # Compile translations but fail when there are missing");
|
|
121
|
-
console.log(" # translations (don't replace missing translations with");
|
|
122
|
-
console.log(" # default messages or message IDs)");
|
|
123
|
-
console.log(" $ ".concat((0, _help.helpRun)("compile --strict")));
|
|
124
|
-
}).parse(process.argv);
|
|
125
|
-
|
|
126
|
-
var config = (0, _conf.getConfig)({
|
|
127
|
-
configPath: _commander.default.config
|
|
128
|
-
});
|
|
129
|
-
|
|
130
|
-
if (_commander.default.format) {
|
|
131
|
-
var msg = "--format option is deprecated and will be removed in @lingui/cli@3.0.0." + " Please set format in configuration https://lingui.js.org/ref/conf.html#format";
|
|
132
|
-
console.warn(msg);
|
|
133
|
-
config.format = _commander.default.format;
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
var compile = function compile() {
|
|
137
|
-
return command(config, {
|
|
138
|
-
verbose: _commander.default.watch || _commander.default.verbose || false,
|
|
139
|
-
allowEmpty: !_commander.default.strict,
|
|
140
|
-
typescript: _commander.default.typescript || config.compileNamespace === "ts" || false,
|
|
141
|
-
namespace: _commander.default.namespace // we want this to be undefined if user does not specify so default can be used
|
|
142
|
-
|
|
143
|
-
});
|
|
144
|
-
};
|
|
145
|
-
|
|
146
|
-
var debounceTimer;
|
|
147
|
-
|
|
148
|
-
var dispatchCompile = function dispatchCompile() {
|
|
149
|
-
// Skip debouncing if not enabled
|
|
150
|
-
if (!_commander.default.debounce) return compile(); // CLear the previous timer if there is any, and schedule the next
|
|
151
|
-
|
|
152
|
-
debounceTimer && clearTimeout(debounceTimer);
|
|
153
|
-
debounceTimer = setTimeout(function () {
|
|
154
|
-
return compile();
|
|
155
|
-
}, _commander.default.debounce);
|
|
156
|
-
}; // Check if Watch Mode is enabled
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
if (_commander.default.watch) {
|
|
160
|
-
var NAME = "{name}";
|
|
161
|
-
var LOCALE = "{locale}";
|
|
162
|
-
console.info(_chalk.default.bold("Initializing Watch Mode..."));
|
|
163
|
-
|
|
164
|
-
var _catalogs = (0, _catalog.getCatalogs)(config);
|
|
165
|
-
|
|
166
|
-
var paths = [];
|
|
167
|
-
var catalogExtension = (0, _api.getFormat)(config.format).catalogExtension;
|
|
168
|
-
config.locales.forEach(function (locale) {
|
|
169
|
-
_catalogs.forEach(function (catalog) {
|
|
170
|
-
paths.push("".concat(catalog.path.replace(LOCALE, locale).replace(NAME, "*")).concat(catalogExtension));
|
|
171
|
-
});
|
|
172
|
-
});
|
|
173
|
-
|
|
174
|
-
var watcher = _chokidar.default.watch(paths, {
|
|
175
|
-
persistent: true
|
|
176
|
-
});
|
|
177
|
-
|
|
178
|
-
var onReady = function onReady() {
|
|
179
|
-
console.info(_chalk.default.green.bold("Watcher is ready!"));
|
|
180
|
-
watcher.on("add", function () {
|
|
181
|
-
return dispatchCompile();
|
|
182
|
-
}).on("change", function () {
|
|
183
|
-
return dispatchCompile();
|
|
184
|
-
});
|
|
185
|
-
};
|
|
186
|
-
|
|
187
|
-
watcher.on("ready", function () {
|
|
188
|
-
return onReady();
|
|
189
|
-
});
|
|
190
|
-
} else {
|
|
191
|
-
var results = compile();
|
|
192
|
-
|
|
193
|
-
if (!results) {
|
|
194
|
-
process.exit(1);
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
console.log("Done!");
|
|
198
|
-
}
|
|
199
|
-
}
|
|
@@ -1,71 +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 = command;
|
|
9
|
-
|
|
10
|
-
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
11
|
-
|
|
12
|
-
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
13
|
-
|
|
14
|
-
var _chalk = _interopRequireDefault(require("chalk"));
|
|
15
|
-
|
|
16
|
-
var _commander = _interopRequireDefault(require("commander"));
|
|
17
|
-
|
|
18
|
-
var _conf = require("@lingui/conf");
|
|
19
|
-
|
|
20
|
-
var _catalog = require("./api/catalog");
|
|
21
|
-
|
|
22
|
-
var _detect = require("./api/detect");
|
|
23
|
-
|
|
24
|
-
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; }
|
|
25
|
-
|
|
26
|
-
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; }
|
|
27
|
-
|
|
28
|
-
function command(config, options) {
|
|
29
|
-
// `react-app` babel plugin used by CRA requires either BABEL_ENV or NODE_ENV to be
|
|
30
|
-
// set. We're setting it here, because lingui macros are going to use them as well.
|
|
31
|
-
if (!process.env.BABEL_ENV && !process.env.NODE_ENV) {
|
|
32
|
-
process.env.BABEL_ENV = "development";
|
|
33
|
-
} // We need macros to keep imports, so extract-messages plugin know what componets
|
|
34
|
-
// to collect. Users usually use both BABEN_ENV and NODE_ENV, so it's probably
|
|
35
|
-
// safer to introduce a new env variable. LINGUI_EXTRACT=1 during `lingui extract`
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
process.env.LINGUI_EXTRACT = "1";
|
|
39
|
-
options.verbose && console.error("Extracting messages from source files…");
|
|
40
|
-
var catalogs = (0, _catalog.getCatalogs)(config);
|
|
41
|
-
var catalogStats = {};
|
|
42
|
-
catalogs.forEach(function (catalog) {
|
|
43
|
-
catalog.makeTemplate(_objectSpread(_objectSpread({}, options), {}, {
|
|
44
|
-
orderBy: config.orderBy,
|
|
45
|
-
projectType: (0, _detect.detect)()
|
|
46
|
-
}));
|
|
47
|
-
catalogStats[catalog.templateFile] = Object.keys(catalog.readTemplate()).length;
|
|
48
|
-
});
|
|
49
|
-
Object.entries(catalogStats).forEach(function (_ref) {
|
|
50
|
-
var _ref2 = (0, _slicedToArray2.default)(_ref, 2),
|
|
51
|
-
key = _ref2[0],
|
|
52
|
-
value = _ref2[1];
|
|
53
|
-
|
|
54
|
-
console.log("Catalog statistics for ".concat(_chalk.default.bold(key), ": ").concat(_chalk.default.green(value), " messages"));
|
|
55
|
-
console.log();
|
|
56
|
-
});
|
|
57
|
-
return true;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
if (require.main === module) {
|
|
61
|
-
_commander.default.option("--config <path>", "Path to the config file").option("--verbose", "Verbose output").parse(process.argv);
|
|
62
|
-
|
|
63
|
-
var config = (0, _conf.getConfig)({
|
|
64
|
-
configPath: _commander.default.config || process.env.LINGUI_CONFIG
|
|
65
|
-
});
|
|
66
|
-
var result = command(config, {
|
|
67
|
-
verbose: _commander.default.verbose || false,
|
|
68
|
-
configPath: _commander.default.config || process.env.LINGUI_CONFIG
|
|
69
|
-
});
|
|
70
|
-
if (!result) process.exit(1);
|
|
71
|
-
}
|
package/lingui-extract.js
DELETED
|
@@ -1,286 +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 = command;
|
|
9
|
-
|
|
10
|
-
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
|
-
|
|
12
|
-
var _interopRequireWildcard2 = _interopRequireDefault(require("@babel/runtime/helpers/interopRequireWildcard"));
|
|
13
|
-
|
|
14
|
-
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
|
|
15
|
-
|
|
16
|
-
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
17
|
-
|
|
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"));
|
|
23
|
-
|
|
24
|
-
var _chalk = _interopRequireDefault(require("chalk"));
|
|
25
|
-
|
|
26
|
-
var _chokidar = _interopRequireDefault(require("chokidar"));
|
|
27
|
-
|
|
28
|
-
var _commander = _interopRequireDefault(require("commander"));
|
|
29
|
-
|
|
30
|
-
var _conf = require("@lingui/conf");
|
|
31
|
-
|
|
32
|
-
var _catalog = require("./api/catalog");
|
|
33
|
-
|
|
34
|
-
var _stats = require("./api/stats");
|
|
35
|
-
|
|
36
|
-
var _detect = require("./api/detect");
|
|
37
|
-
|
|
38
|
-
var _help = require("./api/help");
|
|
39
|
-
|
|
40
|
-
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; }
|
|
41
|
-
|
|
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; }
|
|
43
|
-
|
|
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; } } }; }
|
|
45
|
-
|
|
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); }
|
|
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; }
|
|
49
|
-
|
|
50
|
-
function command(_x, _x2) {
|
|
51
|
-
return _command.apply(this, arguments);
|
|
52
|
-
}
|
|
53
|
-
|
|
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);
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
if (require.main === module) {
|
|
159
|
-
_commander.default.option("--config <path>", "Path to the config file").option("--locale <locale>", "Only extract the specified locale").option("--overwrite", "Overwrite translations for source locale").option("--clean", "Remove obsolete translations").option("--debounce <delay>", "Debounces extraction for given amount of milliseconds").option("--verbose", "Verbose output").option("--convert-from <format>", "Convert from previous format of message catalogs").option("--watch", "Enables Watch Mode") // Obsolete options
|
|
160
|
-
.option("--babelOptions", "Babel options passed to transform/extract plugins").option("--format <format>", "Format of message catalogs").parse(process.argv);
|
|
161
|
-
|
|
162
|
-
var config = (0, _conf.getConfig)({
|
|
163
|
-
configPath: _commander.default.config || process.env.LINGUI_CONFIG
|
|
164
|
-
});
|
|
165
|
-
var hasErrors = false;
|
|
166
|
-
|
|
167
|
-
if (_commander.default.format) {
|
|
168
|
-
hasErrors = true;
|
|
169
|
-
var msg = "--format option is deprecated." + " Please set format in configuration https://lingui.js.org/ref/conf.html#format";
|
|
170
|
-
console.error(msg);
|
|
171
|
-
console.error();
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
if (_commander.default.babelOptions) {
|
|
175
|
-
hasErrors = true;
|
|
176
|
-
|
|
177
|
-
var _msg = "--babelOptions option is deprecated." + " Please set extractBabelOptions in configuration https://lingui.js.org/ref/conf.html#extractBabelOptions";
|
|
178
|
-
|
|
179
|
-
console.error(_msg);
|
|
180
|
-
console.error();
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
var prevFormat = _commander.default.convertFrom;
|
|
184
|
-
|
|
185
|
-
if (prevFormat && config.format === prevFormat) {
|
|
186
|
-
hasErrors = true;
|
|
187
|
-
console.error("Trying to migrate message catalog to the same format");
|
|
188
|
-
console.error("Set ".concat(_chalk.default.bold("new"), " format in LinguiJS configuration\n") + " and ".concat(_chalk.default.bold("previous"), " format using --convert-from option."));
|
|
189
|
-
console.log();
|
|
190
|
-
console.log("Example: Convert from lingui format to minimal");
|
|
191
|
-
console.log(_chalk.default.yellow((0, _help.helpRun)("extract --convert-from lingui")));
|
|
192
|
-
process.exit(1);
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
if (_commander.default.locale && !config.locales.includes(_commander.default.locale)) {
|
|
196
|
-
hasErrors = true;
|
|
197
|
-
console.error("Locale ".concat(_chalk.default.bold(_commander.default.locale), " does not exist."));
|
|
198
|
-
console.error();
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
if (hasErrors) process.exit(1);
|
|
202
|
-
|
|
203
|
-
var extract = function extract(filePath) {
|
|
204
|
-
return command(config, {
|
|
205
|
-
verbose: _commander.default.watch || _commander.default.verbose || false,
|
|
206
|
-
clean: _commander.default.watch ? false : _commander.default.clean || false,
|
|
207
|
-
overwrite: _commander.default.watch || _commander.default.overwrite || false,
|
|
208
|
-
locale: _commander.default.locale,
|
|
209
|
-
configPath: _commander.default.config || process.env.LINGUI_CONFIG,
|
|
210
|
-
watch: _commander.default.watch || false,
|
|
211
|
-
files: (filePath === null || filePath === void 0 ? void 0 : filePath.length) ? filePath : undefined,
|
|
212
|
-
prevFormat: prevFormat
|
|
213
|
-
});
|
|
214
|
-
};
|
|
215
|
-
|
|
216
|
-
var changedPaths = new Set();
|
|
217
|
-
var debounceTimer;
|
|
218
|
-
|
|
219
|
-
var dispatchExtract = function dispatchExtract(filePath) {
|
|
220
|
-
// Skip debouncing if not enabled
|
|
221
|
-
if (!_commander.default.debounce) return extract(filePath);
|
|
222
|
-
filePath === null || filePath === void 0 ? void 0 : filePath.forEach(function (path) {
|
|
223
|
-
return changedPaths.add(path);
|
|
224
|
-
}); // CLear the previous timer if there is any, and schedule the next
|
|
225
|
-
|
|
226
|
-
debounceTimer && clearTimeout(debounceTimer);
|
|
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);
|
|
245
|
-
}; // Check if Watch Mode is enabled
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
if (_commander.default.watch) {
|
|
249
|
-
console.info(_chalk.default.bold("Initializing Watch Mode..."));
|
|
250
|
-
var catalogs = (0, _catalog.getCatalogs)(config);
|
|
251
|
-
var paths = [];
|
|
252
|
-
var ignored = [];
|
|
253
|
-
catalogs.forEach(function (catalog) {
|
|
254
|
-
paths.push.apply(paths, (0, _toConsumableArray2.default)(catalog.include));
|
|
255
|
-
ignored.push.apply(ignored, (0, _toConsumableArray2.default)(catalog.exclude));
|
|
256
|
-
});
|
|
257
|
-
|
|
258
|
-
var watcher = _chokidar.default.watch(paths, {
|
|
259
|
-
ignored: ["/(^|[/\\])../"].concat(ignored),
|
|
260
|
-
persistent: true
|
|
261
|
-
});
|
|
262
|
-
|
|
263
|
-
var onReady = function onReady() {
|
|
264
|
-
console.info(_chalk.default.green.bold("Watcher is ready!"));
|
|
265
|
-
watcher.on("add", function (path) {
|
|
266
|
-
return dispatchExtract([path]);
|
|
267
|
-
}).on("change", function (path) {
|
|
268
|
-
return dispatchExtract([path]);
|
|
269
|
-
});
|
|
270
|
-
};
|
|
271
|
-
|
|
272
|
-
watcher.on("ready", function () {
|
|
273
|
-
return onReady();
|
|
274
|
-
});
|
|
275
|
-
} else if (_commander.default.args) {
|
|
276
|
-
// this behaviour occurs when we extract files by his name
|
|
277
|
-
// for ex: lingui extract src/app, this will extract only files included in src/app
|
|
278
|
-
extract(_commander.default.args).then(function (result) {
|
|
279
|
-
if (!result) process.exit(1);
|
|
280
|
-
});
|
|
281
|
-
} else {
|
|
282
|
-
extract().then(function (result) {
|
|
283
|
-
if (!result) process.exit(1);
|
|
284
|
-
});
|
|
285
|
-
}
|
|
286
|
-
}
|