@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
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
3
|
Object.defineProperty(exports, "__esModule", {
|
|
6
4
|
value: true
|
|
7
5
|
});
|
|
@@ -10,21 +8,32 @@ exports.projectType = void 0;
|
|
|
10
8
|
|
|
11
9
|
var _fs = _interopRequireDefault(require("fs"));
|
|
12
10
|
|
|
11
|
+
var _path = _interopRequireDefault(require("path"));
|
|
12
|
+
|
|
13
13
|
var _pkgUp = _interopRequireDefault(require("pkg-up"));
|
|
14
14
|
|
|
15
|
-
var
|
|
15
|
+
var _package = _interopRequireDefault(require("../../package.json"));
|
|
16
|
+
|
|
17
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
18
|
+
|
|
19
|
+
const projectType = {
|
|
16
20
|
CRA: "CRA",
|
|
17
21
|
REACT: "REACT"
|
|
18
22
|
};
|
|
19
23
|
exports.projectType = projectType;
|
|
20
24
|
|
|
21
|
-
function getPackageJson() {
|
|
22
|
-
|
|
25
|
+
function getPackageJson(cwd) {
|
|
26
|
+
const packageJsonPath = _pkgUp.default.sync({
|
|
27
|
+
cwd
|
|
28
|
+
});
|
|
23
29
|
|
|
24
30
|
try {
|
|
25
|
-
|
|
31
|
+
const json = _fs.default.readFileSync(packageJsonPath, "utf8");
|
|
26
32
|
|
|
27
|
-
return
|
|
33
|
+
return {
|
|
34
|
+
path: packageJsonPath,
|
|
35
|
+
content: JSON.parse(json)
|
|
36
|
+
};
|
|
28
37
|
} catch (e) {
|
|
29
38
|
console.error(e);
|
|
30
39
|
return null;
|
|
@@ -48,7 +57,12 @@ function detectFramework(pkg) {
|
|
|
48
57
|
}
|
|
49
58
|
|
|
50
59
|
function detect() {
|
|
51
|
-
|
|
60
|
+
let pkg = getPackageJson();
|
|
52
61
|
if (!pkg) return null;
|
|
53
|
-
|
|
62
|
+
|
|
63
|
+
if (pkg.content.name === _package.default.name) {
|
|
64
|
+
pkg = getPackageJson(_path.default.dirname(pkg.path));
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
return detectFramework(pkg.content);
|
|
54
68
|
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.extract = extract;
|
|
7
|
+
exports.collect = collect;
|
|
8
|
+
|
|
9
|
+
var _fs = _interopRequireDefault(require("fs"));
|
|
10
|
+
|
|
11
|
+
var _path = _interopRequireDefault(require("path"));
|
|
12
|
+
|
|
13
|
+
var _chalk = _interopRequireDefault(require("chalk"));
|
|
14
|
+
|
|
15
|
+
var R = _interopRequireWildcard(require("ramda"));
|
|
16
|
+
|
|
17
|
+
var _utils = require("./utils");
|
|
18
|
+
|
|
19
|
+
var _extractors = _interopRequireDefault(require("./extractors"));
|
|
20
|
+
|
|
21
|
+
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
|
|
22
|
+
|
|
23
|
+
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (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; }
|
|
24
|
+
|
|
25
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Merge origins for messages found in different places. All other attributes
|
|
29
|
+
* should be the same (raise an error if defaults are different).
|
|
30
|
+
*/
|
|
31
|
+
function mergeMessage(msgId, prev, next) {
|
|
32
|
+
if (prev.message && next.message && prev.message !== next.message) {
|
|
33
|
+
throw new Error(`Encountered different default translations for message ${_chalk.default.yellow(msgId)}` + `\n${_chalk.default.yellow((0, _utils.prettyOrigin)(prev.origin))} ${prev.message}` + `\n${_chalk.default.yellow((0, _utils.prettyOrigin)(next.origin))} ${next.message}`);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return { ...next,
|
|
37
|
+
message: prev.message || next.message,
|
|
38
|
+
origin: R.concat(prev.origin, next.origin)
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
async function extract(srcPaths, targetPath, options = {}) {
|
|
43
|
+
const {
|
|
44
|
+
ignore = []
|
|
45
|
+
} = options;
|
|
46
|
+
const ignorePattern = ignore.length ? new RegExp(ignore.join("|"), "i") : null;
|
|
47
|
+
|
|
48
|
+
for (let srcFilename of srcPaths) {
|
|
49
|
+
if (!_fs.default.existsSync(srcFilename) || ignorePattern && ignorePattern.test(srcFilename)) continue;
|
|
50
|
+
|
|
51
|
+
if (_fs.default.statSync(srcFilename).isDirectory()) {
|
|
52
|
+
const subdirs = _fs.default.readdirSync(srcFilename).sort().map(filename => _path.default.join(srcFilename, filename));
|
|
53
|
+
|
|
54
|
+
await extract(subdirs, targetPath, options);
|
|
55
|
+
continue;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
await (0, _extractors.default)(srcFilename, targetPath, options);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function collect(buildDir) {
|
|
63
|
+
return _fs.default.readdirSync(buildDir).sort().map(filename => {
|
|
64
|
+
const filepath = _path.default.join(buildDir, filename);
|
|
65
|
+
|
|
66
|
+
if (_fs.default.lstatSync(filepath).isDirectory()) {
|
|
67
|
+
return collect(filepath);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
if (!filename.endsWith(".json")) return;
|
|
71
|
+
|
|
72
|
+
try {
|
|
73
|
+
return JSON.parse(_fs.default.readFileSync(filepath).toString());
|
|
74
|
+
} catch (e) {
|
|
75
|
+
return {};
|
|
76
|
+
}
|
|
77
|
+
}).filter(Boolean).reduce((catalog, messages) => R.mergeWithKey(mergeMessage, catalog, messages), {});
|
|
78
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
|
|
8
|
+
var _core = require("@babel/core");
|
|
9
|
+
|
|
10
|
+
var _babelPluginExtractMessages = _interopRequireDefault(require("@lingui/babel-plugin-extract-messages"));
|
|
11
|
+
|
|
12
|
+
var _detect = require("../detect");
|
|
13
|
+
|
|
14
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
15
|
+
|
|
16
|
+
const babelRe = new RegExp("\\.(" + [..._core.DEFAULT_EXTENSIONS, ".ts", ".tsx"].map(ext => ext.slice(1)).join("|") + ")$", "i");
|
|
17
|
+
const extractor = {
|
|
18
|
+
match(filename) {
|
|
19
|
+
return babelRe.test(filename);
|
|
20
|
+
},
|
|
21
|
+
|
|
22
|
+
extract(filename, localeDir, options = {}) {
|
|
23
|
+
const {
|
|
24
|
+
babelOptions: _babelOptions = {},
|
|
25
|
+
configPath
|
|
26
|
+
} = options;
|
|
27
|
+
const {
|
|
28
|
+
plugins = [],
|
|
29
|
+
...babelOptions
|
|
30
|
+
} = _babelOptions;
|
|
31
|
+
const frameworkOptions = {};
|
|
32
|
+
|
|
33
|
+
if (options.projectType === _detect.projectType.CRA) {
|
|
34
|
+
frameworkOptions.presets = ["react-app"];
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
(0, _core.transformFileSync)(filename, { ...babelOptions,
|
|
38
|
+
...frameworkOptions,
|
|
39
|
+
// we override envName to avoid issues with NODE_ENV=production
|
|
40
|
+
// https://github.com/lingui/js-lingui/issues/952
|
|
41
|
+
envName: "development",
|
|
42
|
+
plugins: ["macros", [_babelPluginExtractMessages.default, {
|
|
43
|
+
localeDir,
|
|
44
|
+
configPath
|
|
45
|
+
}], ...plugins]
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
};
|
|
50
|
+
var _default = extractor;
|
|
51
|
+
exports.default = _default;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = extract;
|
|
7
|
+
|
|
8
|
+
var _ora = _interopRequireDefault(require("ora"));
|
|
9
|
+
|
|
10
|
+
var _babel = _interopRequireDefault(require("./babel"));
|
|
11
|
+
|
|
12
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
|
+
|
|
14
|
+
const DEFAULT_EXTRACTORS = [_babel.default];
|
|
15
|
+
|
|
16
|
+
async function extract(filename, targetPath, options) {
|
|
17
|
+
const extractorsToExtract = options.extractors ?? DEFAULT_EXTRACTORS;
|
|
18
|
+
|
|
19
|
+
for (let e of extractorsToExtract) {
|
|
20
|
+
let ext = e;
|
|
21
|
+
|
|
22
|
+
if (typeof e === "string") {
|
|
23
|
+
// in case of the user using require.resolve in their extractors, we require that module
|
|
24
|
+
ext = require(e);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
if (ext.default) {
|
|
28
|
+
ext = ext.default;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
if (!ext.match(filename)) continue;
|
|
32
|
+
let spinner;
|
|
33
|
+
if (options.verbose) spinner = (0, _ora.default)().start(filename);
|
|
34
|
+
|
|
35
|
+
try {
|
|
36
|
+
await ext.extract(filename, targetPath, options);
|
|
37
|
+
if (options.verbose && spinner) spinner.succeed();
|
|
38
|
+
return true;
|
|
39
|
+
} catch (e) {
|
|
40
|
+
if (options.verbose && spinner) {
|
|
41
|
+
spinner.fail(e.message);
|
|
42
|
+
} else {
|
|
43
|
+
console.error(`Cannot process file ${e.message}`);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return true;
|
|
51
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
|
|
8
|
+
var _fs = _interopRequireDefault(require("fs"));
|
|
9
|
+
|
|
10
|
+
var _core = require("@babel/core");
|
|
11
|
+
|
|
12
|
+
var _babelPluginExtractMessages = _interopRequireDefault(require("@lingui/babel-plugin-extract-messages"));
|
|
13
|
+
|
|
14
|
+
var _detect = require("../detect");
|
|
15
|
+
|
|
16
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
17
|
+
|
|
18
|
+
const typescriptRe = /(^.?|\.[^d]|[^.]d|[^.][^d])\.tsx?$/i;
|
|
19
|
+
const extractor = {
|
|
20
|
+
match(filename) {
|
|
21
|
+
return typescriptRe.test(filename);
|
|
22
|
+
},
|
|
23
|
+
|
|
24
|
+
extract(filename, localeDir, options = {}) {
|
|
25
|
+
const ts = require("typescript");
|
|
26
|
+
|
|
27
|
+
const content = _fs.default.readFileSync(filename, "utf8");
|
|
28
|
+
|
|
29
|
+
const isTsx = filename.endsWith(".tsx"); // pass jsx to babel untouched
|
|
30
|
+
|
|
31
|
+
const jsx = isTsx ? ts.JsxEmit.Preserve : ts.JsxEmit.None;
|
|
32
|
+
const stripped = ts.transpileModule(content, {
|
|
33
|
+
compilerOptions: {
|
|
34
|
+
filename,
|
|
35
|
+
jsx,
|
|
36
|
+
module: ts.ModuleKind.ESNext,
|
|
37
|
+
target: ts.ScriptTarget.ES2016,
|
|
38
|
+
// use ES2015 or ES2016 to preserve tagged template literal
|
|
39
|
+
allowSyntheticDefaultImports: true,
|
|
40
|
+
moduleResolution: ts.ModuleResolutionKind.NodeJs
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
const frameworkOptions = {};
|
|
44
|
+
|
|
45
|
+
if (options.projectType === _detect.projectType.CRA) {
|
|
46
|
+
frameworkOptions.presets = ["react-app"];
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const {
|
|
50
|
+
babelOptions = {},
|
|
51
|
+
configPath
|
|
52
|
+
} = options;
|
|
53
|
+
const plugins = ["macros", [_babelPluginExtractMessages.default, {
|
|
54
|
+
localeDir,
|
|
55
|
+
configPath
|
|
56
|
+
}], ...(babelOptions.plugins || [])];
|
|
57
|
+
|
|
58
|
+
if (isTsx) {
|
|
59
|
+
plugins.unshift(require.resolve("@babel/plugin-syntax-jsx"));
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
(0, _core.transform)(stripped.outputText, { ...babelOptions,
|
|
63
|
+
...frameworkOptions,
|
|
64
|
+
filename,
|
|
65
|
+
plugins
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
};
|
|
70
|
+
var _default = extractor;
|
|
71
|
+
exports.default = _default;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
|
|
8
|
+
var _fs = _interopRequireDefault(require("fs"));
|
|
9
|
+
|
|
10
|
+
var _papaparse = _interopRequireDefault(require("papaparse"));
|
|
11
|
+
|
|
12
|
+
var _utils = require("../utils");
|
|
13
|
+
|
|
14
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
15
|
+
|
|
16
|
+
const serialize = catalog => {
|
|
17
|
+
const rawArr = Object.keys(catalog).map(key => [key, catalog[key].translation]);
|
|
18
|
+
return _papaparse.default.unparse(rawArr);
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
const deserialize = raw => {
|
|
22
|
+
const rawCatalog = _papaparse.default.parse(raw);
|
|
23
|
+
|
|
24
|
+
const messages = {};
|
|
25
|
+
|
|
26
|
+
if (rawCatalog.errors.length) {
|
|
27
|
+
throw new Error(rawCatalog.errors.map(err => JSON.stringify(err)).join(";"));
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
rawCatalog.data.forEach(([key, translation]) => {
|
|
31
|
+
messages[key] = {
|
|
32
|
+
translation,
|
|
33
|
+
obsolete: false,
|
|
34
|
+
message: null,
|
|
35
|
+
origin: []
|
|
36
|
+
};
|
|
37
|
+
});
|
|
38
|
+
return messages;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
const csv = {
|
|
42
|
+
catalogExtension: ".csv",
|
|
43
|
+
|
|
44
|
+
write(filename, catalog) {
|
|
45
|
+
const messages = serialize(catalog);
|
|
46
|
+
(0, _utils.writeFileIfChanged)(filename, messages);
|
|
47
|
+
},
|
|
48
|
+
|
|
49
|
+
read(filename) {
|
|
50
|
+
const raw = _fs.default.readFileSync(filename).toString();
|
|
51
|
+
|
|
52
|
+
try {
|
|
53
|
+
return deserialize(raw);
|
|
54
|
+
} catch (e) {
|
|
55
|
+
throw new Error(`Cannot read ${filename}: ${e.message}`);
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
|
|
59
|
+
parse(content) {
|
|
60
|
+
return deserialize(content);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
};
|
|
64
|
+
var _default = csv;
|
|
65
|
+
exports.default = _default;
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
3
|
Object.defineProperty(exports, "__esModule", {
|
|
6
4
|
value: true
|
|
7
5
|
});
|
|
@@ -17,19 +15,24 @@ var _po = _interopRequireDefault(require("./po"));
|
|
|
17
15
|
|
|
18
16
|
var _poGettext = _interopRequireDefault(require("./po-gettext"));
|
|
19
17
|
|
|
20
|
-
|
|
18
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
19
|
+
|
|
20
|
+
const formats = {
|
|
21
21
|
lingui: _lingui.default,
|
|
22
22
|
minimal: _minimal.default,
|
|
23
23
|
po: _po.default,
|
|
24
24
|
csv: _csv.default,
|
|
25
25
|
"po-gettext": _poGettext.default
|
|
26
26
|
};
|
|
27
|
+
/**
|
|
28
|
+
* @internal
|
|
29
|
+
*/
|
|
27
30
|
|
|
28
31
|
function getFormat(name) {
|
|
29
|
-
|
|
32
|
+
const format = formats[name];
|
|
30
33
|
|
|
31
34
|
if (!format) {
|
|
32
|
-
throw new Error(
|
|
35
|
+
throw new Error(`Unknown format "${name}". Use one of following: ${Object.keys(formats).join(", ")}`);
|
|
33
36
|
}
|
|
34
37
|
|
|
35
38
|
return format;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
|
|
8
|
+
var _fs = _interopRequireDefault(require("fs"));
|
|
9
|
+
|
|
10
|
+
var R = _interopRequireWildcard(require("ramda"));
|
|
11
|
+
|
|
12
|
+
var _utils = require("../utils");
|
|
13
|
+
|
|
14
|
+
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
|
|
15
|
+
|
|
16
|
+
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (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; }
|
|
17
|
+
|
|
18
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
19
|
+
|
|
20
|
+
const removeOrigins = R.map(({
|
|
21
|
+
origin,
|
|
22
|
+
...message
|
|
23
|
+
}) => message);
|
|
24
|
+
const removeLineNumbers = R.map(message => {
|
|
25
|
+
if (message.origin) {
|
|
26
|
+
message.origin.map(originValue => {
|
|
27
|
+
originValue.pop();
|
|
28
|
+
return originValue;
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return message;
|
|
33
|
+
});
|
|
34
|
+
const lingui = {
|
|
35
|
+
catalogExtension: ".json",
|
|
36
|
+
|
|
37
|
+
write(filename, catalog, options) {
|
|
38
|
+
let outputCatalog = catalog;
|
|
39
|
+
|
|
40
|
+
if (options.origins === false) {
|
|
41
|
+
outputCatalog = removeOrigins(catalog);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
if (options.origins !== false && options.lineNumbers === false) {
|
|
45
|
+
outputCatalog = removeLineNumbers(outputCatalog);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
(0, _utils.writeFileIfChanged)(filename, JSON.stringify(outputCatalog, null, 2));
|
|
49
|
+
},
|
|
50
|
+
|
|
51
|
+
read(filename) {
|
|
52
|
+
const raw = _fs.default.readFileSync(filename).toString();
|
|
53
|
+
|
|
54
|
+
try {
|
|
55
|
+
return JSON.parse(raw);
|
|
56
|
+
} catch (e) {
|
|
57
|
+
throw new Error(`Cannot read ${filename}: ${e.message}`);
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
|
|
61
|
+
parse(content) {
|
|
62
|
+
return content;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
};
|
|
66
|
+
var _default = lingui;
|
|
67
|
+
exports.default = _default;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
|
|
8
|
+
var _fs = _interopRequireDefault(require("fs"));
|
|
9
|
+
|
|
10
|
+
var R = _interopRequireWildcard(require("ramda"));
|
|
11
|
+
|
|
12
|
+
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
|
|
13
|
+
|
|
14
|
+
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (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; }
|
|
15
|
+
|
|
16
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
17
|
+
|
|
18
|
+
const serialize = R.map(message => message.translation || "");
|
|
19
|
+
const deserialize = R.map(translation => ({
|
|
20
|
+
translation,
|
|
21
|
+
obsolete: false,
|
|
22
|
+
message: null,
|
|
23
|
+
origin: []
|
|
24
|
+
}));
|
|
25
|
+
const minimal = {
|
|
26
|
+
catalogExtension: ".json",
|
|
27
|
+
|
|
28
|
+
write(filename, catalog) {
|
|
29
|
+
const messages = serialize(catalog);
|
|
30
|
+
let file = null;
|
|
31
|
+
|
|
32
|
+
try {
|
|
33
|
+
file = _fs.default.readFileSync(filename, 'utf8');
|
|
34
|
+
} catch (error) {
|
|
35
|
+
if (error.code !== "ENOENT") {
|
|
36
|
+
throw error;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const shouldUseTrailingNewline = file === null || file?.endsWith("\n");
|
|
41
|
+
const trailingNewLine = shouldUseTrailingNewline ? "\n" : "";
|
|
42
|
+
|
|
43
|
+
_fs.default.writeFileSync(filename, `${JSON.stringify(messages, null, 2)}${trailingNewLine}`);
|
|
44
|
+
},
|
|
45
|
+
|
|
46
|
+
read(filename) {
|
|
47
|
+
const raw = _fs.default.readFileSync(filename).toString();
|
|
48
|
+
|
|
49
|
+
try {
|
|
50
|
+
const rawCatalog = JSON.parse(raw);
|
|
51
|
+
return deserialize(rawCatalog);
|
|
52
|
+
} catch (e) {
|
|
53
|
+
throw new Error(`Cannot read ${filename}: ${e.message}`);
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
|
|
57
|
+
parse(content) {
|
|
58
|
+
return deserialize(content);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
};
|
|
62
|
+
var _default = minimal;
|
|
63
|
+
exports.default = _default;
|