@lingui/cli 4.0.0-next.0 → 4.0.0-next.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/build/api/catalog/getCatalogs.js +7 -2
- package/build/api/catalog/getTranslationsForCatalog.js +3 -3
- package/build/api/catalog.js +45 -43
- package/build/api/compile.js +5 -0
- package/build/api/extractors/babel.js +15 -9
- package/build/api/extractors/index.js +3 -1
- package/build/api/formats/api/formatterWrapper.js +42 -0
- package/build/api/formats/csv.js +11 -24
- package/build/api/formats/index.js +19 -20
- package/build/api/formats/lingui.js +28 -34
- package/build/api/formats/minimal.js +15 -28
- package/build/api/formats/po-gettext.js +44 -44
- package/build/api/formats/po.js +32 -36
- package/build/api/rethrownError.js +14 -0
- package/build/api/utils.js +14 -12
- package/build/extract-experimental/buildExternalizeFilter.js +39 -0
- package/build/extract-experimental/bundleSource.js +69 -0
- package/build/extract-experimental/constants.js +10 -0
- package/build/extract-experimental/getEntryPoints.js +14 -0
- package/build/extract-experimental/getExperimentalCatalogs.js +27 -0
- package/build/extract-experimental/resolveCatalogPath.js +23 -0
- package/build/extract-experimental/resolveTemplatePath.js +17 -0
- package/build/extract-experimental/writeCatalogs.js +59 -0
- package/build/lingui-compile.js +26 -27
- package/build/lingui-extract-experimental.js +103 -0
- package/build/lingui-extract.js +1 -1
- package/build/lingui.js +1 -1
- package/build/services/translationIO.js +27 -30
- package/build/tests.js +21 -0
- package/package.json +12 -13
- package/build/api/locales.js +0 -36
package/build/lingui-compile.js
CHANGED
|
@@ -8,16 +8,15 @@ var _chalk = _interopRequireDefault(require("chalk"));
|
|
|
8
8
|
var _chokidar = _interopRequireDefault(require("chokidar"));
|
|
9
9
|
var _fs = _interopRequireDefault(require("fs"));
|
|
10
10
|
var _commander = require("commander");
|
|
11
|
-
var plurals = _interopRequireWildcard(require("make-plural"));
|
|
12
11
|
var _conf = require("@lingui/conf");
|
|
13
12
|
var _compile = require("./api/compile");
|
|
14
13
|
var _help = require("./api/help");
|
|
15
14
|
var _api = require("./api");
|
|
16
15
|
var _getCatalogs = require("./api/catalog/getCatalogs");
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
var _utils = require("./api/utils");
|
|
17
|
+
var _path = _interopRequireDefault(require("path"));
|
|
19
18
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
20
|
-
function command(config, options) {
|
|
19
|
+
async function command(config, options) {
|
|
21
20
|
const catalogs = (0, _api.getCatalogs)(config);
|
|
22
21
|
|
|
23
22
|
// Check config.compile.merge if catalogs for current locale are to be merged into a single compiled file
|
|
@@ -25,16 +24,9 @@ function command(config, options) {
|
|
|
25
24
|
let mergedCatalogs = {};
|
|
26
25
|
console.log("Compiling message catalogs…");
|
|
27
26
|
for (const locale of config.locales) {
|
|
28
|
-
const [language] = locale.split(/[_-]/);
|
|
29
|
-
// todo: this validation should be in @lingui/conf
|
|
30
|
-
// todo: validate locales according bcp47, instead of plurals
|
|
31
|
-
if (locale !== config.pseudoLocale && !plurals[language]) {
|
|
32
|
-
console.error(_chalk.default.red(`Error: Invalid locale ${_chalk.default.bold(locale)} (missing plural rules)!`));
|
|
33
|
-
console.error();
|
|
34
|
-
}
|
|
35
27
|
for (const catalog of catalogs) {
|
|
36
28
|
const missingMessages = [];
|
|
37
|
-
const messages = catalog.getTranslations(locale, {
|
|
29
|
+
const messages = await catalog.getTranslations(locale, {
|
|
38
30
|
fallbackLocales: config.fallbackLocales,
|
|
39
31
|
sourceLocale: config.sourceLocale,
|
|
40
32
|
onMissing: missing => {
|
|
@@ -68,7 +60,7 @@ function command(config, options) {
|
|
|
68
60
|
pseudoLocale: config.pseudoLocale,
|
|
69
61
|
compilerBabelOptions: config.compilerBabelOptions
|
|
70
62
|
});
|
|
71
|
-
|
|
63
|
+
let compiledPath = await catalog.writeCompiled(locale, compiledCatalog, namespace);
|
|
72
64
|
if (options.typescript) {
|
|
73
65
|
const typescriptPath = compiledPath.replace(/\.ts?$/, "") + ".d.ts";
|
|
74
66
|
_fs.default.writeFileSync(typescriptPath, `import { Messages } from '@lingui/core';
|
|
@@ -76,6 +68,7 @@ function command(config, options) {
|
|
|
76
68
|
export { messages };
|
|
77
69
|
`);
|
|
78
70
|
}
|
|
71
|
+
compiledPath = (0, _utils.normalizeSlashes)(_path.default.relative(config.rootDir, compiledPath));
|
|
79
72
|
options.verbose && console.error(_chalk.default.green(`${locale} ⇒ ${compiledPath}`));
|
|
80
73
|
}
|
|
81
74
|
}
|
|
@@ -88,7 +81,8 @@ function command(config, options) {
|
|
|
88
81
|
pseudoLocale: config.pseudoLocale,
|
|
89
82
|
compilerBabelOptions: config.compilerBabelOptions
|
|
90
83
|
});
|
|
91
|
-
|
|
84
|
+
let compiledPath = await compileCatalog.writeCompiled(locale, compiledCatalog, namespace);
|
|
85
|
+
compiledPath = (0, _utils.normalizeSlashes)(_path.default.relative(config.rootDir, compiledPath));
|
|
92
86
|
options.verbose && console.log(_chalk.default.green(`${locale} ⇒ ${compiledPath}`));
|
|
93
87
|
}
|
|
94
88
|
}
|
|
@@ -109,17 +103,21 @@ if (require.main === module) {
|
|
|
109
103
|
const config = (0, _conf.getConfig)({
|
|
110
104
|
configPath: options.config
|
|
111
105
|
});
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
106
|
+
let previousRun = Promise.resolve(true);
|
|
107
|
+
const compile = () => {
|
|
108
|
+
previousRun = previousRun.then(() => command(config, {
|
|
109
|
+
verbose: options.watch || options.verbose || false,
|
|
110
|
+
allowEmpty: !options.strict,
|
|
111
|
+
typescript: options.typescript || config.compileNamespace === "ts" || false,
|
|
112
|
+
namespace: options.namespace // we want this to be undefined if user does not specify so default can be used
|
|
113
|
+
}));
|
|
118
114
|
|
|
115
|
+
return previousRun;
|
|
116
|
+
};
|
|
119
117
|
let debounceTimer;
|
|
120
118
|
const dispatchCompile = () => {
|
|
121
119
|
// Skip debouncing if not enabled
|
|
122
|
-
if (!options.debounce)
|
|
120
|
+
if (!options.debounce) compile();
|
|
123
121
|
|
|
124
122
|
// CLear the previous timer if there is any, and schedule the next
|
|
125
123
|
debounceTimer && clearTimeout(debounceTimer);
|
|
@@ -131,7 +129,7 @@ if (require.main === module) {
|
|
|
131
129
|
console.info(_chalk.default.bold("Initializing Watch Mode..."));
|
|
132
130
|
const catalogs = (0, _api.getCatalogs)(config);
|
|
133
131
|
let paths = [];
|
|
134
|
-
const catalogExtension = (0, _api.getFormat)(config.format).
|
|
132
|
+
const catalogExtension = (0, _api.getFormat)(config.format, config.formatOptions).getCatalogExtension();
|
|
135
133
|
config.locales.forEach(locale => {
|
|
136
134
|
catalogs.forEach(catalog => {
|
|
137
135
|
paths.push(`${catalog.path.replace(/{locale}/g, locale).replace(/{name}/g, "*")}${catalogExtension}`);
|
|
@@ -146,10 +144,11 @@ if (require.main === module) {
|
|
|
146
144
|
};
|
|
147
145
|
watcher.on("ready", () => onReady());
|
|
148
146
|
} else {
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
147
|
+
compile().then(results => {
|
|
148
|
+
if (!results) {
|
|
149
|
+
process.exit(1);
|
|
150
|
+
}
|
|
151
|
+
console.log("Done!");
|
|
152
|
+
});
|
|
154
153
|
}
|
|
155
154
|
}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = command;
|
|
7
|
+
var _commander = require("commander");
|
|
8
|
+
var _conf = require("@lingui/conf");
|
|
9
|
+
var _path = _interopRequireDefault(require("path"));
|
|
10
|
+
var _os = _interopRequireDefault(require("os"));
|
|
11
|
+
var _formats = require("./api/formats");
|
|
12
|
+
var _promises = _interopRequireDefault(require("fs/promises"));
|
|
13
|
+
var _extractFromFiles = require("./api/catalog/extractFromFiles");
|
|
14
|
+
var _utils = require("./api/utils");
|
|
15
|
+
var _bundleSource = require("./extract-experimental/bundleSource");
|
|
16
|
+
var _writeCatalogs = require("./extract-experimental/writeCatalogs");
|
|
17
|
+
var _getEntryPoints = require("./extract-experimental/getEntryPoints");
|
|
18
|
+
var _chalk = _interopRequireDefault(require("chalk"));
|
|
19
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
20
|
+
async function command(linguiConfig, options) {
|
|
21
|
+
var _linguiConfig$experim;
|
|
22
|
+
options.verbose && console.log("Extracting messages from source files…");
|
|
23
|
+
const config = (_linguiConfig$experim = linguiConfig.experimental) === null || _linguiConfig$experim === void 0 ? void 0 : _linguiConfig$experim.extractor;
|
|
24
|
+
if (!config) {
|
|
25
|
+
throw new Error("The configuration for experimental extractor is empty. Please read the docs.");
|
|
26
|
+
}
|
|
27
|
+
console.log(_chalk.default.yellow(["You have using an experimental feature", "Experimental features are not covered by semver, and may cause unexpected or broken application behavior." + " Use at your own risk.", ""].join("\n")));
|
|
28
|
+
const tempDir = await _promises.default.mkdtemp(_path.default.join(_os.default.tmpdir(), "js-lingui-extract-"));
|
|
29
|
+
await _promises.default.rm(tempDir, {
|
|
30
|
+
recursive: true,
|
|
31
|
+
force: true
|
|
32
|
+
});
|
|
33
|
+
const bundleResult = await (0, _bundleSource.bundleSource)(config, (0, _getEntryPoints.getEntryPoints)(config.entries), tempDir, linguiConfig.rootDir);
|
|
34
|
+
const stats = [];
|
|
35
|
+
let commandSuccess = true;
|
|
36
|
+
const format = (0, _formats.getFormat)(linguiConfig.format, linguiConfig.formatOptions);
|
|
37
|
+
for (const outFile of Object.keys(bundleResult.metafile.outputs)) {
|
|
38
|
+
const messages = await (0, _extractFromFiles.extractFromFiles)([outFile], linguiConfig);
|
|
39
|
+
const {
|
|
40
|
+
entryPoint
|
|
41
|
+
} = bundleResult.metafile.outputs[outFile];
|
|
42
|
+
let output;
|
|
43
|
+
if (!messages) {
|
|
44
|
+
commandSuccess = false;
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
47
|
+
if (options.template) {
|
|
48
|
+
output = (await (0, _writeCatalogs.writeTemplate)({
|
|
49
|
+
linguiConfig,
|
|
50
|
+
clean: options.clean,
|
|
51
|
+
format,
|
|
52
|
+
messages,
|
|
53
|
+
entryPoint,
|
|
54
|
+
outputPattern: config.output
|
|
55
|
+
})).statMessage;
|
|
56
|
+
} else {
|
|
57
|
+
output = (await (0, _writeCatalogs.writeCatalogs)({
|
|
58
|
+
locales: options.locales || linguiConfig.locales,
|
|
59
|
+
linguiConfig,
|
|
60
|
+
clean: options.clean,
|
|
61
|
+
format,
|
|
62
|
+
messages,
|
|
63
|
+
entryPoint,
|
|
64
|
+
overwrite: options.overwrite,
|
|
65
|
+
outputPattern: config.output
|
|
66
|
+
})).statMessage;
|
|
67
|
+
}
|
|
68
|
+
stats.push({
|
|
69
|
+
entry: (0, _utils.normalizeSlashes)(_path.default.relative(linguiConfig.rootDir, entryPoint)),
|
|
70
|
+
content: output
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// cleanup temp directory
|
|
75
|
+
await _promises.default.rm(tempDir, {
|
|
76
|
+
recursive: true,
|
|
77
|
+
force: true
|
|
78
|
+
});
|
|
79
|
+
stats.forEach(({
|
|
80
|
+
entry,
|
|
81
|
+
content
|
|
82
|
+
}) => {
|
|
83
|
+
console.log([`Catalog statistics for ${entry}:`, content, ""].join("\n"));
|
|
84
|
+
});
|
|
85
|
+
return commandSuccess;
|
|
86
|
+
}
|
|
87
|
+
if (require.main === module) {
|
|
88
|
+
var _options$locale;
|
|
89
|
+
_commander.program.option("--config <path>", "Path to the config file").option("--template", "Extract to template").option("--overwrite", "Overwrite translations for source locale").option("--clean", "Remove obsolete translations").option("--locale <locale, [...]>", "Only extract the specified locales").option("--verbose", "Verbose output").parse(process.argv);
|
|
90
|
+
const options = _commander.program.opts();
|
|
91
|
+
const config = (0, _conf.getConfig)({
|
|
92
|
+
configPath: options.config
|
|
93
|
+
});
|
|
94
|
+
const result = command(config, {
|
|
95
|
+
verbose: options.verbose || false,
|
|
96
|
+
template: options.template,
|
|
97
|
+
locales: (_options$locale = options.locale) === null || _options$locale === void 0 ? void 0 : _options$locale.split(","),
|
|
98
|
+
overwrite: options.overwrite,
|
|
99
|
+
clean: options.clean
|
|
100
|
+
}).then(() => {
|
|
101
|
+
if (!result) process.exit(1);
|
|
102
|
+
});
|
|
103
|
+
}
|
package/build/lingui-extract.js
CHANGED
|
@@ -49,7 +49,7 @@ async function command(config, options) {
|
|
|
49
49
|
// If service key is present in configuration, synchronize with cloud translation platform
|
|
50
50
|
if (typeof config.service === "object" && config.service.name && config.service.name.length) {
|
|
51
51
|
const moduleName = config.service.name.charAt(0).toLowerCase() + config.service.name.slice(1);
|
|
52
|
-
(specifier => new Promise(r => r(specifier)).then(s => _interopRequireWildcard(require(s))))(`./services/${moduleName}`).then(module => module.default(config, options)).catch(err => console.error(`Can't load service module ${moduleName}`, err));
|
|
52
|
+
await (specifier => new Promise(r => r(specifier)).then(s => _interopRequireWildcard(require(s))))(`./services/${moduleName}`).then(module => module.default(config, options)).catch(err => console.error(`Can't load service module ${moduleName}`, err));
|
|
53
53
|
}
|
|
54
54
|
return commandSuccess;
|
|
55
55
|
}
|
package/build/lingui.js
CHANGED
|
@@ -3,4 +3,4 @@
|
|
|
3
3
|
|
|
4
4
|
var _commander = require("commander");
|
|
5
5
|
var _package = require("../package.json");
|
|
6
|
-
_commander.program.version(_package.version).command("extract [files...]", "Extracts messages from source files").command("extract-template", "Extracts messages from source files to a .pot template").command("compile", "Compile message catalogs").parse(process.argv);
|
|
6
|
+
_commander.program.version(_package.version).command("extract [files...]", "Extracts messages from source files").command("extract-experimental", "Extracts messages from source files traversing dependency tree").command("extract-template", "Extracts messages from source files to a .pot template").command("compile", "Compile message catalogs").parse(process.argv);
|
|
@@ -52,18 +52,18 @@ function init(config, options, successCallback, failCallback) {
|
|
|
52
52
|
const sourceLocale = config.sourceLocale || "en";
|
|
53
53
|
const targetLocales = getTargetLocales(config);
|
|
54
54
|
const paths = poPathsPerLocale(config);
|
|
55
|
-
|
|
55
|
+
const segments = {};
|
|
56
56
|
targetLocales.forEach(targetLocale => {
|
|
57
57
|
segments[targetLocale] = [];
|
|
58
58
|
});
|
|
59
59
|
|
|
60
60
|
// Create segments from source locale PO items
|
|
61
61
|
paths[sourceLocale].forEach(path => {
|
|
62
|
-
|
|
63
|
-
|
|
62
|
+
const raw = _fs.default.readFileSync(path).toString();
|
|
63
|
+
const po = _pofile.default.parse(raw);
|
|
64
64
|
po.items.filter(item => !item["obsolete"]).forEach(item => {
|
|
65
65
|
targetLocales.forEach(targetLocale => {
|
|
66
|
-
|
|
66
|
+
const newSegment = createSegmentFromPoItem(item);
|
|
67
67
|
segments[targetLocale].push(newSegment);
|
|
68
68
|
});
|
|
69
69
|
});
|
|
@@ -72,14 +72,14 @@ function init(config, options, successCallback, failCallback) {
|
|
|
72
72
|
// Add translations to segments from target locale PO items
|
|
73
73
|
targetLocales.forEach(targetLocale => {
|
|
74
74
|
paths[targetLocale].forEach(path => {
|
|
75
|
-
|
|
76
|
-
|
|
75
|
+
const raw = _fs.default.readFileSync(path).toString();
|
|
76
|
+
const po = _pofile.default.parse(raw);
|
|
77
77
|
po.items.filter(item => !item["obsolete"]).forEach((item, index) => {
|
|
78
78
|
segments[targetLocale][index].target = item.msgstr[0];
|
|
79
79
|
});
|
|
80
80
|
});
|
|
81
81
|
});
|
|
82
|
-
|
|
82
|
+
const request = {
|
|
83
83
|
client: "lingui",
|
|
84
84
|
version: require("@lingui/core/package.json").version,
|
|
85
85
|
source_language: sourceLocale,
|
|
@@ -104,29 +104,26 @@ function sync(config, options, successCallback, failCallback) {
|
|
|
104
104
|
const sourceLocale = config.sourceLocale || "en";
|
|
105
105
|
const targetLocales = getTargetLocales(config);
|
|
106
106
|
const paths = poPathsPerLocale(config);
|
|
107
|
-
|
|
107
|
+
const segments = [];
|
|
108
108
|
|
|
109
109
|
// Create segments with correct source
|
|
110
110
|
paths[sourceLocale].forEach(path => {
|
|
111
|
-
|
|
112
|
-
|
|
111
|
+
const raw = _fs.default.readFileSync(path).toString();
|
|
112
|
+
const po = _pofile.default.parse(raw);
|
|
113
113
|
po.items.filter(item => !item["obsolete"]).forEach(item => {
|
|
114
|
-
|
|
114
|
+
const newSegment = createSegmentFromPoItem(item);
|
|
115
115
|
segments.push(newSegment);
|
|
116
116
|
});
|
|
117
117
|
});
|
|
118
|
-
|
|
118
|
+
const request = {
|
|
119
119
|
client: "lingui",
|
|
120
120
|
version: require("@lingui/core/package.json").version,
|
|
121
121
|
source_language: sourceLocale,
|
|
122
122
|
target_languages: targetLocales,
|
|
123
|
-
segments: segments
|
|
123
|
+
segments: segments,
|
|
124
|
+
// Sync and then remove unused segments (not present in the local application) from Translation.io
|
|
125
|
+
purge: Boolean(options.clean)
|
|
124
126
|
};
|
|
125
|
-
|
|
126
|
-
// Sync and then remove unused segments (not present in the local application) from Translation.io
|
|
127
|
-
if (options.clean) {
|
|
128
|
-
request["purge"] = true;
|
|
129
|
-
}
|
|
130
127
|
postTio("sync", request, config.service.apiKey, response => {
|
|
131
128
|
if (response.errors) {
|
|
132
129
|
failCallback(response.errors);
|
|
@@ -139,8 +136,8 @@ function sync(config, options, successCallback, failCallback) {
|
|
|
139
136
|
});
|
|
140
137
|
}
|
|
141
138
|
function createSegmentFromPoItem(item) {
|
|
142
|
-
|
|
143
|
-
|
|
139
|
+
const itemHasId = item.msgid != item.msgstr[0] && item.msgstr[0].length;
|
|
140
|
+
const segment = {
|
|
144
141
|
type: "source",
|
|
145
142
|
// No way to edit text for source language (inside code), so not using "key" here
|
|
146
143
|
source: itemHasId ? item.msgstr[0] : item.msgid,
|
|
@@ -161,7 +158,7 @@ function createSegmentFromPoItem(item) {
|
|
|
161
158
|
return segment;
|
|
162
159
|
}
|
|
163
160
|
function createPoItemFromSegment(segment) {
|
|
164
|
-
|
|
161
|
+
const item = new _pofile.default.Item();
|
|
165
162
|
item.msgid = segment.context ? segment.context : segment.source;
|
|
166
163
|
item.msgstr = [segment.target];
|
|
167
164
|
item.references = segment.references && segment.references.length ? segment.references : [];
|
|
@@ -190,11 +187,11 @@ function saveSegmentsToTargetPos(config, paths, segmentsPerLocale) {
|
|
|
190
187
|
// Find target path (ignoring {name})
|
|
191
188
|
const localePath = "".concat(config.catalogs[0].path.replace(/{locale}/g, targetLocale).replace(/{name}/g, ""), ".po");
|
|
192
189
|
const segments = segmentsPerLocale[targetLocale];
|
|
193
|
-
|
|
190
|
+
const po = new _pofile.default();
|
|
194
191
|
po.headers = getCreateHeaders(targetLocale);
|
|
195
|
-
|
|
192
|
+
const items = [];
|
|
196
193
|
segments.forEach(segment => {
|
|
197
|
-
|
|
194
|
+
const item = createPoItemFromSegment(segment);
|
|
198
195
|
items.push(item);
|
|
199
196
|
});
|
|
200
197
|
|
|
@@ -224,7 +221,7 @@ function saveSegmentsToTargetPos(config, paths, segmentsPerLocale) {
|
|
|
224
221
|
});
|
|
225
222
|
}
|
|
226
223
|
function poPathsPerLocale(config) {
|
|
227
|
-
const paths =
|
|
224
|
+
const paths = {};
|
|
228
225
|
config.locales.forEach(locale => {
|
|
229
226
|
paths[locale] = [];
|
|
230
227
|
config.catalogs.forEach(catalog => {
|
|
@@ -241,23 +238,23 @@ function poPathsPerLocale(config) {
|
|
|
241
238
|
return paths;
|
|
242
239
|
}
|
|
243
240
|
function postTio(action, request, apiKey, successCallback, failCallback) {
|
|
244
|
-
|
|
245
|
-
|
|
241
|
+
const jsonRequest = JSON.stringify(request);
|
|
242
|
+
const options = {
|
|
246
243
|
hostname: "translation.io",
|
|
247
|
-
path:
|
|
244
|
+
path: `/api/v1/segments/${action}.json?api_key=${apiKey}`,
|
|
248
245
|
method: "POST",
|
|
249
246
|
headers: {
|
|
250
247
|
"Content-Type": "application/json"
|
|
251
248
|
}
|
|
252
249
|
};
|
|
253
|
-
|
|
250
|
+
const req = _https.default.request(options, res => {
|
|
254
251
|
res.setEncoding("utf8");
|
|
255
252
|
let body = "";
|
|
256
253
|
res.on("data", chunk => {
|
|
257
254
|
body = body.concat(chunk);
|
|
258
255
|
});
|
|
259
256
|
res.on("end", () => {
|
|
260
|
-
|
|
257
|
+
const response = JSON.parse(body);
|
|
261
258
|
successCallback(response);
|
|
262
259
|
});
|
|
263
260
|
});
|
package/build/tests.js
CHANGED
|
@@ -4,6 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.copyFixture = copyFixture;
|
|
7
|
+
exports.createFixtures = createFixtures;
|
|
7
8
|
exports.defaultMergeOptions = exports.defaultMakeTemplateOptions = exports.defaultMakeOptions = void 0;
|
|
8
9
|
exports.listingToHumanReadable = listingToHumanReadable;
|
|
9
10
|
exports.makeCatalog = void 0;
|
|
@@ -93,6 +94,26 @@ function listingToHumanReadable(listing) {
|
|
|
93
94
|
});
|
|
94
95
|
return output.join("\n");
|
|
95
96
|
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Create fixtures from provided listing in temp folder
|
|
100
|
+
* Alternative for mock-fs which is also mocking nodejs require calls
|
|
101
|
+
* @param listing
|
|
102
|
+
*/
|
|
103
|
+
async function createFixtures(listing) {
|
|
104
|
+
const tmpDir = await _fs.default.promises.mkdtemp(_path.default.join(_os.default.tmpdir(), `lingui-test-${process.pid}`));
|
|
105
|
+
async function create(listing) {
|
|
106
|
+
for (const [filename, value] of Object.entries(listing)) {
|
|
107
|
+
if (typeof value === "string") {
|
|
108
|
+
await _fs.default.promises.writeFile(_path.default.join(tmpDir, filename), value);
|
|
109
|
+
} else {
|
|
110
|
+
await create(value);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
await create(listing);
|
|
115
|
+
return tmpDir;
|
|
116
|
+
}
|
|
96
117
|
function readFsToJson(directory, filter) {
|
|
97
118
|
const out = {};
|
|
98
119
|
_fs.default.readdirSync(directory).map(filename => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lingui/cli",
|
|
3
|
-
"version": "4.0.0-next.
|
|
3
|
+
"version": "4.0.0-next.2",
|
|
4
4
|
"description": "CLI for working wit message catalogs",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cli",
|
|
@@ -45,33 +45,32 @@
|
|
|
45
45
|
"build/"
|
|
46
46
|
],
|
|
47
47
|
"dependencies": {
|
|
48
|
-
"@babel/core": "^7.
|
|
49
|
-
"@babel/generator": "^7.
|
|
50
|
-
"@babel/parser": "^7.
|
|
51
|
-
"@babel/
|
|
52
|
-
"@babel/
|
|
53
|
-
"@babel
|
|
54
|
-
"@lingui/
|
|
55
|
-
"@lingui/
|
|
56
|
-
"@lingui/core": "^4.0.0-next.0",
|
|
48
|
+
"@babel/core": "^7.21.0",
|
|
49
|
+
"@babel/generator": "^7.21.1",
|
|
50
|
+
"@babel/parser": "^7.21.2",
|
|
51
|
+
"@babel/runtime": "^7.21.0",
|
|
52
|
+
"@babel/types": "^7.21.2",
|
|
53
|
+
"@lingui/babel-plugin-extract-messages": "^4.0.0-next.2",
|
|
54
|
+
"@lingui/conf": "^4.0.0-next.2",
|
|
55
|
+
"@lingui/core": "^4.0.0-next.2",
|
|
57
56
|
"@messageformat/parser": "^5.0.0",
|
|
58
57
|
"babel-plugin-macros": "^3.0.1",
|
|
59
|
-
"bcp-47": "^1.0.7",
|
|
60
58
|
"chalk": "^4.1.0",
|
|
61
59
|
"chokidar": "3.5.1",
|
|
62
60
|
"cli-table": "0.3.6",
|
|
63
61
|
"commander": "^10.0.0",
|
|
64
62
|
"convert-source-map": "^2.0.0",
|
|
65
63
|
"date-fns": "^2.16.1",
|
|
64
|
+
"esbuild": "^0.17.10",
|
|
66
65
|
"glob": "^7.1.4",
|
|
67
66
|
"inquirer": "^7.3.3",
|
|
68
|
-
"make-plural": "^6.2.2",
|
|
69
67
|
"micromatch": "4.0.2",
|
|
70
68
|
"mkdirp": "^1.0.4",
|
|
71
69
|
"node-gettext": "^3.0.0",
|
|
72
70
|
"normalize-path": "^3.0.0",
|
|
73
71
|
"ora": "^5.1.0",
|
|
74
72
|
"papaparse": "^5.3.0",
|
|
73
|
+
"pkg-up": "^3.1.0",
|
|
75
74
|
"plurals-cldr": "^1.0.4",
|
|
76
75
|
"pofile": "^1.1.4",
|
|
77
76
|
"pseudolocale": "^1.1.0",
|
|
@@ -88,5 +87,5 @@
|
|
|
88
87
|
"mock-fs": "^5.2.0",
|
|
89
88
|
"mockdate": "^3.0.2"
|
|
90
89
|
},
|
|
91
|
-
"gitHead": "
|
|
90
|
+
"gitHead": "556ab57e20c2ac9d384a22424c6a90c2ba0dd133"
|
|
92
91
|
}
|
package/build/api/locales.js
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.isValid = isValid;
|
|
7
|
-
exports.parse = parse;
|
|
8
|
-
var plurals = _interopRequireWildcard(require("make-plural/plurals"));
|
|
9
|
-
var _bcp = _interopRequireDefault(require("bcp-47"));
|
|
10
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
-
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
12
|
-
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
13
|
-
/**
|
|
14
|
-
* Check that locale is valid according to BCP47 and we have plurals for it
|
|
15
|
-
* @param locale: string - Locale in BCP47 format
|
|
16
|
-
* @return {boolean}
|
|
17
|
-
*/
|
|
18
|
-
function isValid(locale) {
|
|
19
|
-
const localeData = parse(locale);
|
|
20
|
-
return localeData !== null && localeData !== undefined && localeData.language in plurals;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Parse locale in BCP47 format and
|
|
25
|
-
* @param locale - Locale in BCP47 format
|
|
26
|
-
* @return {LocaleInfo}
|
|
27
|
-
*/
|
|
28
|
-
function parse(locale) {
|
|
29
|
-
if (typeof locale !== "string") return null;
|
|
30
|
-
const schema = _bcp.default.parse(locale.replace("_", "-"));
|
|
31
|
-
if (!schema.language) return null;
|
|
32
|
-
return {
|
|
33
|
-
locale: _bcp.default.stringify(schema),
|
|
34
|
-
language: schema.language
|
|
35
|
-
};
|
|
36
|
-
}
|