@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
|
@@ -12,6 +12,7 @@ var _catalog = require("../catalog");
|
|
|
12
12
|
var _utils = require("../utils");
|
|
13
13
|
var _micromatch = _interopRequireDefault(require("micromatch"));
|
|
14
14
|
var _formats = require("../formats");
|
|
15
|
+
var _getExperimentalCatalogs = require("../../extract-experimental/getExperimentalCatalogs");
|
|
15
16
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
16
17
|
const NAME_PH = "{name}";
|
|
17
18
|
const LOCALE_PH = "{locale}";
|
|
@@ -20,6 +21,7 @@ const LOCALE_PH = "{locale}";
|
|
|
20
21
|
* Parse `config.catalogs` and return a list of configured Catalog instances.
|
|
21
22
|
*/
|
|
22
23
|
function getCatalogs(config) {
|
|
24
|
+
var _config$experimental, _config$experimental$;
|
|
23
25
|
const catalogsConfig = config.catalogs;
|
|
24
26
|
const catalogs = [];
|
|
25
27
|
catalogsConfig.forEach(catalog => {
|
|
@@ -65,6 +67,9 @@ function getCatalogs(config) {
|
|
|
65
67
|
}, config));
|
|
66
68
|
});
|
|
67
69
|
});
|
|
70
|
+
if ((_config$experimental = config.experimental) !== null && _config$experimental !== void 0 && (_config$experimental$ = _config$experimental.extractor) !== null && _config$experimental$ !== void 0 && _config$experimental$.entries.length) {
|
|
71
|
+
catalogs.push(...(0, _getExperimentalCatalogs.getExperimentalCatalogs)(config));
|
|
72
|
+
}
|
|
68
73
|
return catalogs;
|
|
69
74
|
}
|
|
70
75
|
|
|
@@ -90,7 +95,7 @@ function getCatalogForMerge(config) {
|
|
|
90
95
|
}
|
|
91
96
|
function getCatalogForFile(file, catalogs) {
|
|
92
97
|
for (const catalog of catalogs) {
|
|
93
|
-
const catalogFile = `${catalog.path}${catalog.format.
|
|
98
|
+
const catalogFile = `${catalog.path}${catalog.format.getCatalogExtension()}`;
|
|
94
99
|
const catalogGlob = (0, _utils.replacePlaceholders)(catalogFile, {
|
|
95
100
|
locale: "*"
|
|
96
101
|
});
|
|
@@ -112,7 +117,7 @@ function validateCatalogPath(path, config) {
|
|
|
112
117
|
if (!path.endsWith(_utils.PATHSEP)) {
|
|
113
118
|
return;
|
|
114
119
|
}
|
|
115
|
-
const extension = (0, _formats.getFormat)(config.format).
|
|
120
|
+
const extension = (0, _formats.getFormat)(config.format, config.formatOptions).getCatalogExtension();
|
|
116
121
|
const correctPath = path.slice(0, -1);
|
|
117
122
|
const examplePath = (0, _utils.replacePlaceholders)(correctPath, {
|
|
118
123
|
locale: (config.locales || [])[0] || "en"
|
|
@@ -4,9 +4,9 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.getTranslationsForCatalog = getTranslationsForCatalog;
|
|
7
|
-
function getTranslationsForCatalog(catalog, locale, options) {
|
|
8
|
-
const catalogs = catalog.readAll();
|
|
9
|
-
const template = catalog.readTemplate() || {};
|
|
7
|
+
async function getTranslationsForCatalog(catalog, locale, options) {
|
|
8
|
+
const catalogs = await catalog.readAll();
|
|
9
|
+
const template = (await catalog.readTemplate()) || {};
|
|
10
10
|
const sourceLocaleCatalog = catalogs[options.sourceLocale] || {};
|
|
11
11
|
const input = {
|
|
12
12
|
...template,
|
package/build/api/catalog.js
CHANGED
|
@@ -5,8 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.cleanObsolete = exports.Catalog = void 0;
|
|
7
7
|
exports.order = order;
|
|
8
|
-
exports.
|
|
9
|
-
exports.orderByOrigin = orderByOrigin;
|
|
8
|
+
exports.orderByMessage = orderByMessage;
|
|
10
9
|
var _fs = _interopRequireDefault(require("fs"));
|
|
11
10
|
var _path = _interopRequireDefault(require("path"));
|
|
12
11
|
var R = _interopRequireWildcard(require("ramda"));
|
|
@@ -35,15 +34,15 @@ class Catalog {
|
|
|
35
34
|
this.path = (0, _utils.normalizeRelativePath)(path);
|
|
36
35
|
this.include = include.map(_utils.normalizeRelativePath);
|
|
37
36
|
this.exclude = [this.localeDir, ...exclude.map(_utils.normalizeRelativePath)];
|
|
38
|
-
this.format = (0, _formats.getFormat)(config.format);
|
|
39
|
-
this.templateFile = templatePath || getTemplatePath(this.format, this.path);
|
|
37
|
+
this.format = (0, _formats.getFormat)(config.format, config.formatOptions);
|
|
38
|
+
this.templateFile = templatePath || getTemplatePath(this.format.getTemplateExtension(), this.path);
|
|
40
39
|
}
|
|
41
40
|
async make(options) {
|
|
42
41
|
const nextCatalog = await this.collect({
|
|
43
42
|
files: options.files
|
|
44
43
|
});
|
|
45
44
|
if (!nextCatalog) return false;
|
|
46
|
-
const prevCatalogs = this.readAll();
|
|
45
|
+
const prevCatalogs = await this.readAll();
|
|
47
46
|
const catalogs = this.merge(prevCatalogs, nextCatalog, {
|
|
48
47
|
overwrite: options.overwrite,
|
|
49
48
|
files: options.files
|
|
@@ -56,11 +55,8 @@ class Catalog {
|
|
|
56
55
|
// Sort messages
|
|
57
56
|
order(options.orderBy)));
|
|
58
57
|
const sortedCatalogs = cleanAndSort(catalogs);
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
} else {
|
|
62
|
-
this.writeAll(sortedCatalogs);
|
|
63
|
-
}
|
|
58
|
+
const locales = options.locale ? [options.locale] : this.locales;
|
|
59
|
+
await Promise.all(locales.map(locale => this.write(locale, sortedCatalogs[locale])));
|
|
64
60
|
return sortedCatalogs;
|
|
65
61
|
}
|
|
66
62
|
async makeTemplate(options) {
|
|
@@ -69,7 +65,7 @@ class Catalog {
|
|
|
69
65
|
});
|
|
70
66
|
if (!catalog) return false;
|
|
71
67
|
const sorted = order(options.orderBy)(catalog);
|
|
72
|
-
this.writeTemplate(sorted);
|
|
68
|
+
await this.writeTemplate(sorted);
|
|
73
69
|
return sorted;
|
|
74
70
|
}
|
|
75
71
|
|
|
@@ -111,33 +107,22 @@ class Catalog {
|
|
|
111
107
|
return (0, _mergeCatalog.mergeCatalog)(prevCatalog, nextCatalog, this.config.sourceLocale === locale, options);
|
|
112
108
|
}, prevCatalogs);
|
|
113
109
|
}
|
|
114
|
-
getTranslations(locale, options) {
|
|
115
|
-
return (0, _getTranslationsForCatalog.getTranslationsForCatalog)(this, locale, options);
|
|
110
|
+
async getTranslations(locale, options) {
|
|
111
|
+
return await (0, _getTranslationsForCatalog.getTranslationsForCatalog)(this, locale, options);
|
|
116
112
|
}
|
|
117
|
-
write(locale, messages) {
|
|
113
|
+
async write(locale, messages) {
|
|
118
114
|
const filename = (0, _utils.replacePlaceholders)(this.path, {
|
|
119
115
|
locale
|
|
120
|
-
}) + this.format.
|
|
116
|
+
}) + this.format.getCatalogExtension();
|
|
121
117
|
const created = !_fs.default.existsSync(filename);
|
|
122
|
-
|
|
123
|
-
...this.config.formatOptions,
|
|
124
|
-
locale
|
|
125
|
-
};
|
|
126
|
-
this.format.write(filename, messages, options);
|
|
118
|
+
await this.format.write(filename, messages, locale);
|
|
127
119
|
return [created, filename];
|
|
128
120
|
}
|
|
129
|
-
|
|
130
|
-
this.locales.forEach(locale => this.write(locale, catalogs[locale]));
|
|
131
|
-
}
|
|
132
|
-
writeTemplate(messages) {
|
|
121
|
+
async writeTemplate(messages) {
|
|
133
122
|
const filename = this.templateFile;
|
|
134
|
-
|
|
135
|
-
...this.config.formatOptions,
|
|
136
|
-
locale: undefined
|
|
137
|
-
};
|
|
138
|
-
this.format.write(filename, messages, options);
|
|
123
|
+
await this.format.write(filename, messages, undefined);
|
|
139
124
|
}
|
|
140
|
-
writeCompiled(locale, compiledCatalog, namespace) {
|
|
125
|
+
async writeCompiled(locale, compiledCatalog, namespace) {
|
|
141
126
|
let ext;
|
|
142
127
|
if (namespace === "es") {
|
|
143
128
|
ext = "mjs";
|
|
@@ -149,23 +134,29 @@ class Catalog {
|
|
|
149
134
|
const filename = `${(0, _utils.replacePlaceholders)(this.path, {
|
|
150
135
|
locale
|
|
151
136
|
})}.${ext}`;
|
|
152
|
-
(0, _utils.writeFile)(filename, compiledCatalog);
|
|
137
|
+
await (0, _utils.writeFile)(filename, compiledCatalog);
|
|
153
138
|
return filename;
|
|
154
139
|
}
|
|
155
|
-
read(locale) {
|
|
140
|
+
async read(locale) {
|
|
156
141
|
const filename = (0, _utils.replacePlaceholders)(this.path, {
|
|
157
142
|
locale
|
|
158
|
-
}) + this.format.
|
|
159
|
-
return this.format.read(filename);
|
|
143
|
+
}) + this.format.getCatalogExtension();
|
|
144
|
+
return await this.format.read(filename, locale);
|
|
160
145
|
}
|
|
161
|
-
readAll() {
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
146
|
+
async readAll() {
|
|
147
|
+
const res = {};
|
|
148
|
+
await Promise.all(this.locales.map(async locale => res[locale] = await this.read(locale)));
|
|
149
|
+
|
|
150
|
+
// statement above will save locales in object in undetermined order
|
|
151
|
+
// resort here to have keys order the same as in locales definition
|
|
152
|
+
return this.locales.reduce((acc, locale) => {
|
|
153
|
+
acc[locale] = res[locale];
|
|
154
|
+
return acc;
|
|
155
|
+
}, {});
|
|
156
|
+
}
|
|
157
|
+
async readTemplate() {
|
|
167
158
|
const filename = this.templateFile;
|
|
168
|
-
return this.format.read(filename);
|
|
159
|
+
return await this.format.read(filename, undefined);
|
|
169
160
|
}
|
|
170
161
|
get sourcePaths() {
|
|
171
162
|
const includeGlobs = this.include.map(includePath => {
|
|
@@ -194,8 +185,7 @@ class Catalog {
|
|
|
194
185
|
}
|
|
195
186
|
}
|
|
196
187
|
exports.Catalog = Catalog;
|
|
197
|
-
function getTemplatePath(
|
|
198
|
-
const ext = format.templateExtension || format.catalogExtension;
|
|
188
|
+
function getTemplatePath(ext, path) {
|
|
199
189
|
return path.replace(LOCALE_SUFFIX_RE, "messages" + ext);
|
|
200
190
|
}
|
|
201
191
|
const cleanObsolete = R.filter(message => !message.obsolete);
|
|
@@ -203,6 +193,7 @@ exports.cleanObsolete = cleanObsolete;
|
|
|
203
193
|
function order(by) {
|
|
204
194
|
return {
|
|
205
195
|
messageId: orderByMessageId,
|
|
196
|
+
message: orderByMessage,
|
|
206
197
|
origin: orderByOrigin
|
|
207
198
|
}[by];
|
|
208
199
|
}
|
|
@@ -240,4 +231,15 @@ function orderByOrigin(messages) {
|
|
|
240
231
|
acc[key] = messages[key];
|
|
241
232
|
return acc;
|
|
242
233
|
}, {});
|
|
234
|
+
}
|
|
235
|
+
function orderByMessage(messages) {
|
|
236
|
+
return Object.keys(messages).sort((a, b) => {
|
|
237
|
+
const aMsg = messages[a].message || "";
|
|
238
|
+
const bMsg = messages[b].message || "";
|
|
239
|
+
return aMsg.localeCompare(bMsg);
|
|
240
|
+
}).reduce((acc, key) => {
|
|
241
|
+
;
|
|
242
|
+
acc[key] = messages[key];
|
|
243
|
+
return acc;
|
|
244
|
+
}, {});
|
|
243
245
|
}
|
package/build/api/compile.js
CHANGED
|
@@ -26,6 +26,11 @@ function createCompiledCatalog(locale, messages, options) {
|
|
|
26
26
|
obj[key] = compile(translation, shouldPseudolocalize);
|
|
27
27
|
return obj;
|
|
28
28
|
}, {});
|
|
29
|
+
if (namespace === "json") {
|
|
30
|
+
return JSON.stringify({
|
|
31
|
+
messages: compiledMessages
|
|
32
|
+
});
|
|
33
|
+
}
|
|
29
34
|
const ast = buildExportStatement(
|
|
30
35
|
//build JSON.parse(<compiledMessages>) statement
|
|
31
36
|
t.callExpression(t.memberExpression(t.identifier("JSON"), t.identifier("parse")), [t.stringLiteral(JSON.stringify(compiledMessages))]), namespace);
|
|
@@ -16,17 +16,23 @@ const extractor = {
|
|
|
16
16
|
match(filename) {
|
|
17
17
|
return babelRe.test(filename);
|
|
18
18
|
},
|
|
19
|
-
async extract(filename, code, onMessageExtracted,
|
|
20
|
-
const parserOptions = linguiConfig.extractorParserOptions;
|
|
21
|
-
|
|
19
|
+
async extract(filename, code, onMessageExtracted, ctx) {
|
|
20
|
+
const parserOptions = ctx.linguiConfig.extractorParserOptions;
|
|
21
|
+
|
|
22
22
|
// https://babeljs.io/docs/en/babel-parser#latest-ecmascript-features
|
|
23
|
-
[
|
|
24
|
-
decoratorsBeforeExport: (parserOptions === null || parserOptions === void 0 ? void 0 : parserOptions.decoratorsBeforeExport) || true
|
|
25
|
-
}]];
|
|
23
|
+
const parserPlugins = [];
|
|
26
24
|
if ([/\.ts$/, /\.mts$/, /\.cts$/, /\.tsx$/].some(r => filename.match(r))) {
|
|
27
25
|
parserPlugins.push("typescript");
|
|
28
|
-
|
|
29
|
-
|
|
26
|
+
if (parserOptions.tsExperimentalDecorators) {
|
|
27
|
+
parserPlugins.push("decorators-legacy");
|
|
28
|
+
} else {
|
|
29
|
+
parserPlugins.push("decorators");
|
|
30
|
+
}
|
|
31
|
+
} else {
|
|
32
|
+
parserPlugins.push("decorators");
|
|
33
|
+
if (parserOptions !== null && parserOptions !== void 0 && parserOptions.flow) {
|
|
34
|
+
parserPlugins.push("flow");
|
|
35
|
+
}
|
|
30
36
|
}
|
|
31
37
|
if ([/\.jsx$/, /\.tsx$/].some(r => filename.match(r))) {
|
|
32
38
|
parserPlugins.push("jsx");
|
|
@@ -58,7 +64,7 @@ const extractor = {
|
|
|
58
64
|
resolvePath: source => require.resolve(source),
|
|
59
65
|
lingui: {
|
|
60
66
|
extract: true,
|
|
61
|
-
linguiConfig
|
|
67
|
+
linguiConfig: ctx.linguiConfig
|
|
62
68
|
}
|
|
63
69
|
}], [_babelPluginExtractMessages.default, {
|
|
64
70
|
onMessageExtracted: msg => {
|
|
@@ -22,7 +22,9 @@ async function extract(filename, onMessageExtracted, linguiConfig, options) {
|
|
|
22
22
|
if (!ext.match(filename)) continue;
|
|
23
23
|
try {
|
|
24
24
|
const file = await _promises.default.readFile(filename);
|
|
25
|
-
await ext.extract(filename, file.toString(), onMessageExtracted,
|
|
25
|
+
await ext.extract(filename, file.toString(), onMessageExtracted, {
|
|
26
|
+
linguiConfig
|
|
27
|
+
});
|
|
26
28
|
return true;
|
|
27
29
|
} catch (e) {
|
|
28
30
|
console.error(`Cannot process file ${filename} ${e.message}`);
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.FormatterWrapper = void 0;
|
|
7
|
+
var _utils = require("../../utils");
|
|
8
|
+
var _rethrownError = require("../../rethrownError");
|
|
9
|
+
class FormatterWrapper {
|
|
10
|
+
constructor(f) {
|
|
11
|
+
this.f = f;
|
|
12
|
+
}
|
|
13
|
+
getCatalogExtension() {
|
|
14
|
+
return this.f.catalogExtension;
|
|
15
|
+
}
|
|
16
|
+
getTemplateExtension() {
|
|
17
|
+
return this.f.templateExtension || this.f.catalogExtension;
|
|
18
|
+
}
|
|
19
|
+
async write(filename, catalog, locale) {
|
|
20
|
+
const content = await this.f.serialize(catalog, {
|
|
21
|
+
locale,
|
|
22
|
+
existing: await (0, _utils.readFile)(filename),
|
|
23
|
+
filename
|
|
24
|
+
});
|
|
25
|
+
await (0, _utils.writeFileIfChanged)(filename, content);
|
|
26
|
+
}
|
|
27
|
+
async read(filename, locale) {
|
|
28
|
+
const content = await (0, _utils.readFile)(filename);
|
|
29
|
+
if (!content) {
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
try {
|
|
33
|
+
return this.f.parse(content, {
|
|
34
|
+
locale,
|
|
35
|
+
filename
|
|
36
|
+
});
|
|
37
|
+
} catch (e) {
|
|
38
|
+
throw new _rethrownError.RethrownError(`Cannot read ${filename}`, e);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
exports.FormatterWrapper = FormatterWrapper;
|
package/build/api/formats/csv.js
CHANGED
|
@@ -3,9 +3,8 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.default =
|
|
6
|
+
exports.default = _default;
|
|
7
7
|
var _papaparse = _interopRequireDefault(require("papaparse"));
|
|
8
|
-
var _utils = require("../utils");
|
|
9
8
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
10
9
|
const serialize = catalog => {
|
|
11
10
|
const rawArr = Object.keys(catalog).map(key => [key, catalog[key].translation]);
|
|
@@ -27,26 +26,14 @@ const deserialize = raw => {
|
|
|
27
26
|
});
|
|
28
27
|
return messages;
|
|
29
28
|
};
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
if (!raw) {
|
|
39
|
-
return null;
|
|
29
|
+
function _default() {
|
|
30
|
+
return {
|
|
31
|
+
catalogExtension: ".csv",
|
|
32
|
+
parse(content) {
|
|
33
|
+
return deserialize(content);
|
|
34
|
+
},
|
|
35
|
+
serialize(catalog) {
|
|
36
|
+
return serialize(catalog);
|
|
40
37
|
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
} catch (e) {
|
|
44
|
-
throw new Error(`Cannot read ${filename}: ${e.message}`);
|
|
45
|
-
}
|
|
46
|
-
},
|
|
47
|
-
parse(content) {
|
|
48
|
-
return deserialize(content);
|
|
49
|
-
}
|
|
50
|
-
};
|
|
51
|
-
var _default = csv;
|
|
52
|
-
exports.default = _default;
|
|
38
|
+
};
|
|
39
|
+
}
|
|
@@ -3,29 +3,28 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
Object.defineProperty(exports, "FormatterWrapper", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function () {
|
|
9
|
+
return _formatterWrapper.FormatterWrapper;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
6
12
|
exports.getFormat = getFormat;
|
|
7
|
-
var
|
|
8
|
-
var _lingui = _interopRequireDefault(require("./lingui"));
|
|
9
|
-
var _minimal = _interopRequireDefault(require("./minimal"));
|
|
10
|
-
var _po = _interopRequireDefault(require("./po"));
|
|
11
|
-
var _poGettext = _interopRequireDefault(require("./po-gettext"));
|
|
12
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
|
+
var _formatterWrapper = require("./api/formatterWrapper");
|
|
13
14
|
const formats = {
|
|
14
|
-
lingui:
|
|
15
|
-
minimal:
|
|
16
|
-
po:
|
|
17
|
-
csv:
|
|
18
|
-
"po-gettext":
|
|
15
|
+
lingui: () => require("./lingui").default,
|
|
16
|
+
minimal: () => require("./minimal").default,
|
|
17
|
+
po: () => require("./po").default,
|
|
18
|
+
csv: () => require("./csv").default,
|
|
19
|
+
"po-gettext": () => require("./po-gettext").default
|
|
19
20
|
};
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
function getFormat(name) {
|
|
26
|
-
const format = formats[name];
|
|
21
|
+
function getFormat(_format, options) {
|
|
22
|
+
if (typeof _format !== "string") {
|
|
23
|
+
return new _formatterWrapper.FormatterWrapper(_format);
|
|
24
|
+
}
|
|
25
|
+
const format = formats[_format];
|
|
27
26
|
if (!format) {
|
|
28
|
-
throw new Error(`Unknown format "${
|
|
27
|
+
throw new Error(`Unknown format "${_format}". Use one of following: ${Object.keys(formats).join(", ")}`);
|
|
29
28
|
}
|
|
30
|
-
return format;
|
|
29
|
+
return new _formatterWrapper.FormatterWrapper(format()(options));
|
|
31
30
|
}
|
|
@@ -3,9 +3,8 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.default =
|
|
6
|
+
exports.default = _default;
|
|
7
7
|
var R = _interopRequireWildcard(require("ramda"));
|
|
8
|
-
var _utils = require("../utils");
|
|
9
8
|
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); }
|
|
10
9
|
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; }
|
|
11
10
|
const removeOrigins = R.map(({
|
|
@@ -14,39 +13,34 @@ const removeOrigins = R.map(({
|
|
|
14
13
|
}) => message);
|
|
15
14
|
const removeLineNumbers = R.map(message => {
|
|
16
15
|
if (message.origin) {
|
|
17
|
-
message.origin.map(
|
|
18
|
-
originValue.pop();
|
|
19
|
-
return originValue;
|
|
20
|
-
});
|
|
16
|
+
message.origin = message.origin.map(([file]) => [file]);
|
|
21
17
|
}
|
|
22
18
|
return message;
|
|
23
19
|
});
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
20
|
+
function _default(options = {}) {
|
|
21
|
+
options = {
|
|
22
|
+
origins: true,
|
|
23
|
+
lineNumbers: true,
|
|
24
|
+
...options
|
|
25
|
+
};
|
|
26
|
+
return {
|
|
27
|
+
catalogExtension: ".json",
|
|
28
|
+
serialize(catalog, {
|
|
29
|
+
existing
|
|
30
|
+
}) {
|
|
31
|
+
let outputCatalog = catalog;
|
|
32
|
+
if (options.origins === false) {
|
|
33
|
+
outputCatalog = removeOrigins(outputCatalog);
|
|
34
|
+
}
|
|
35
|
+
if (options.origins !== false && options.lineNumbers === false) {
|
|
36
|
+
outputCatalog = removeLineNumbers(outputCatalog);
|
|
37
|
+
}
|
|
38
|
+
const shouldUseTrailingNewline = existing === null || (existing === null || existing === void 0 ? void 0 : existing.endsWith("\n"));
|
|
39
|
+
const trailingNewLine = shouldUseTrailingNewline ? "\n" : "";
|
|
40
|
+
return JSON.stringify(outputCatalog, null, 2) + trailingNewLine;
|
|
41
|
+
},
|
|
42
|
+
parse(content) {
|
|
43
|
+
return JSON.parse(content);
|
|
30
44
|
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
}
|
|
34
|
-
(0, _utils.writeFileIfChanged)(filename, JSON.stringify(outputCatalog, null, 2));
|
|
35
|
-
},
|
|
36
|
-
read(filename) {
|
|
37
|
-
const raw = (0, _utils.readFile)(filename);
|
|
38
|
-
if (!raw) {
|
|
39
|
-
return null;
|
|
40
|
-
}
|
|
41
|
-
try {
|
|
42
|
-
return JSON.parse(raw);
|
|
43
|
-
} catch (e) {
|
|
44
|
-
throw new Error(`Cannot read ${filename}: ${e.message}`);
|
|
45
|
-
}
|
|
46
|
-
},
|
|
47
|
-
parse(content) {
|
|
48
|
-
return content;
|
|
49
|
-
}
|
|
50
|
-
};
|
|
51
|
-
var _default = lingui;
|
|
52
|
-
exports.default = _default;
|
|
45
|
+
};
|
|
46
|
+
}
|
|
@@ -3,9 +3,8 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.default =
|
|
6
|
+
exports.default = _default;
|
|
7
7
|
var R = _interopRequireWildcard(require("ramda"));
|
|
8
|
-
var _utils = require("../utils");
|
|
9
8
|
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); }
|
|
10
9
|
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; }
|
|
11
10
|
const serialize = R.map(message => message.translation || "");
|
|
@@ -15,30 +14,18 @@ const deserialize = R.map(translation => ({
|
|
|
15
14
|
message: null,
|
|
16
15
|
origin: []
|
|
17
16
|
}));
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
return null;
|
|
17
|
+
function _default() {
|
|
18
|
+
return {
|
|
19
|
+
catalogExtension: ".json",
|
|
20
|
+
serialize(catalog, {
|
|
21
|
+
existing
|
|
22
|
+
}) {
|
|
23
|
+
const shouldUseTrailingNewline = existing === null || (existing === null || existing === void 0 ? void 0 : existing.endsWith("\n"));
|
|
24
|
+
const trailingNewLine = shouldUseTrailingNewline ? "\n" : "";
|
|
25
|
+
return JSON.stringify(serialize(catalog), null, 2) + trailingNewLine;
|
|
26
|
+
},
|
|
27
|
+
parse(content) {
|
|
28
|
+
return deserialize(JSON.parse(content));
|
|
31
29
|
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
return deserialize(rawCatalog);
|
|
35
|
-
} catch (e) {
|
|
36
|
-
throw new Error(`Cannot read ${filename}: ${e.message}`);
|
|
37
|
-
}
|
|
38
|
-
},
|
|
39
|
-
parse(content) {
|
|
40
|
-
return deserialize(content);
|
|
41
|
-
}
|
|
42
|
-
};
|
|
43
|
-
var _default = minimal;
|
|
44
|
-
exports.default = _default;
|
|
30
|
+
};
|
|
31
|
+
}
|