@esgettext/tools 1.0.0 → 1.2.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/LICENSE +1 -1
- package/README.md +197 -22
- package/dist/command.js +2 -0
- package/dist/commands/convert.js +286 -0
- package/dist/commands/install.js +257 -0
- package/dist/commands/msgfmt-all.js +219 -0
- package/dist/commands/msgmerge-all.js +230 -0
- package/dist/commands/xgettext/file-resolver.js +20 -0
- package/dist/commands/xgettext/files-collector.js +39 -0
- package/dist/commands/xgettext.js +534 -0
- package/dist/configuration.js +277 -0
- package/dist/esgettext-package-json.js +2 -0
- package/dist/index.js +135 -0
- package/dist/package.js +10 -12
- package/dist/parser/javascript.js +9 -28
- package/dist/parser/parser.js +176 -148
- package/dist/parser/po.js +144 -128
- package/dist/parser/typescript.js +10 -28
- package/dist/pot/catalog.js +134 -83
- package/dist/pot/entry.js +173 -115
- package/dist/pot/keyword.js +66 -92
- package/package.json +38 -25
- package/bin/esgettext-install.js +0 -5
- package/bin/esgettext-mo2json.js +0 -5
- package/bin/esgettext-msgfmt-all.js +0 -5
- package/bin/esgettext-msgmerge-all.js +0 -5
- package/bin/esgettext-xgettext.js +0 -5
- package/dist/cli/getopt.d.ts +0 -34
- package/dist/cli/getopt.js +0 -150
- package/dist/cli/getopt.js.map +0 -1
- package/dist/cli/getopt.spec.d.ts +0 -1
- package/dist/cli/getopt.spec.js +0 -164
- package/dist/cli/getopt.spec.js.map +0 -1
- package/dist/cli/install.d.ts +0 -1
- package/dist/cli/install.js +0 -91
- package/dist/cli/install.js.map +0 -1
- package/dist/cli/mo2json-cli.d.ts +0 -1
- package/dist/cli/mo2json-cli.js +0 -48
- package/dist/cli/mo2json-cli.js.map +0 -1
- package/dist/cli/msgfmt-all.d.ts +0 -1
- package/dist/cli/msgfmt-all.js +0 -99
- package/dist/cli/msgfmt-all.js.map +0 -1
- package/dist/cli/msgmerge-all.d.ts +0 -1
- package/dist/cli/msgmerge-all.js +0 -85
- package/dist/cli/msgmerge-all.js.map +0 -1
- package/dist/cli/xgettext-cli.d.ts +0 -1
- package/dist/cli/xgettext-cli.js +0 -303
- package/dist/cli/xgettext-cli.js.map +0 -1
- package/dist/install/install.d.ts +0 -10
- package/dist/install/install.js +0 -157
- package/dist/install/install.js.map +0 -1
- package/dist/msgfmt-all/msgfmt-all.d.ts +0 -8
- package/dist/msgfmt-all/msgfmt-all.js +0 -142
- package/dist/msgfmt-all/msgfmt-all.js.map +0 -1
- package/dist/msgmerge-all/msgmerge-all.d.ts +0 -9
- package/dist/msgmerge-all/msgmerge-all.js +0 -157
- package/dist/msgmerge-all/msgmerge-all.js.map +0 -1
- package/dist/package.d.ts +0 -4
- package/dist/package.js.map +0 -1
- package/dist/parser/__snapshots__/javascript.spec.js.snap +0 -56
- package/dist/parser/__snapshots__/po.spec.js.snap +0 -176
- package/dist/parser/javascript.d.ts +0 -4
- package/dist/parser/javascript.js.map +0 -1
- package/dist/parser/javascript.spec.d.ts +0 -1
- package/dist/parser/javascript.spec.js +0 -436
- package/dist/parser/javascript.spec.js.map +0 -1
- package/dist/parser/parser.d.ts +0 -45
- package/dist/parser/parser.js.map +0 -1
- package/dist/parser/po.d.ts +0 -22
- package/dist/parser/po.js.map +0 -1
- package/dist/parser/po.spec.d.ts +0 -1
- package/dist/parser/po.spec.js +0 -296
- package/dist/parser/po.spec.js.map +0 -1
- package/dist/parser/typescript.d.ts +0 -4
- package/dist/parser/typescript.js.map +0 -1
- package/dist/parser/typescript.spec.d.ts +0 -1
- package/dist/parser/typescript.spec.js +0 -106
- package/dist/parser/typescript.spec.js.map +0 -1
- package/dist/pot/__snapshots__/catalog.spec.js.snap +0 -591
- package/dist/pot/catalog.d.ts +0 -26
- package/dist/pot/catalog.js.map +0 -1
- package/dist/pot/catalog.spec.d.ts +0 -1
- package/dist/pot/catalog.spec.js +0 -240
- package/dist/pot/catalog.spec.js.map +0 -1
- package/dist/pot/entry.d.ts +0 -35
- package/dist/pot/entry.js.map +0 -1
- package/dist/pot/entry.spec.d.ts +0 -1
- package/dist/pot/entry.spec.js +0 -317
- package/dist/pot/entry.spec.js.map +0 -1
- package/dist/pot/keyword.d.ts +0 -17
- package/dist/pot/keyword.js.map +0 -1
- package/dist/pot/keyword.spec.d.ts +0 -1
- package/dist/pot/keyword.spec.js +0 -54
- package/dist/pot/keyword.spec.js.map +0 -1
- package/dist/xgettext/__snapshots__/xgettext.spec.js.snap +0 -462
- package/dist/xgettext/file-resolver.d.ts +0 -5
- package/dist/xgettext/file-resolver.js +0 -23
- package/dist/xgettext/file-resolver.js.map +0 -1
- package/dist/xgettext/file-resolver.spec.d.ts +0 -1
- package/dist/xgettext/file-resolver.spec.js +0 -22
- package/dist/xgettext/file-resolver.spec.js.map +0 -1
- package/dist/xgettext/files-collector.d.ts +0 -5
- package/dist/xgettext/files-collector.js +0 -41
- package/dist/xgettext/files-collector.js.map +0 -1
- package/dist/xgettext/files-collector.spec.d.ts +0 -1
- package/dist/xgettext/files-collector.spec.js +0 -78
- package/dist/xgettext/files-collector.spec.js.map +0 -1
- package/dist/xgettext/xgettext.d.ts +0 -16
- package/dist/xgettext/xgettext.js +0 -335
- package/dist/xgettext/xgettext.js.map +0 -1
- package/dist/xgettext/xgettext.spec.d.ts +0 -1
- package/dist/xgettext/xgettext.spec.js +0 -743
- package/dist/xgettext/xgettext.spec.js.map +0 -1
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
35
|
+
exports.MsgmergeAll = void 0;
|
|
36
|
+
const path = __importStar(require("path"));
|
|
37
|
+
const fs = __importStar(require("fs"));
|
|
38
|
+
const childProcess = __importStar(require("child_process"));
|
|
39
|
+
const runtime_1 = require("@esgettext/runtime");
|
|
40
|
+
const package_1 = require("../package");
|
|
41
|
+
const gtx = runtime_1.Textdomain.getInstance('com.cantanea.esgettext-tools');
|
|
42
|
+
class MsgmergeAll {
|
|
43
|
+
constructor(configuration) {
|
|
44
|
+
var _a, _b;
|
|
45
|
+
this.locales = [];
|
|
46
|
+
this.options = {};
|
|
47
|
+
this.configuration = configuration;
|
|
48
|
+
if (((_a = configuration.package) === null || _a === void 0 ? void 0 : _a.textdomain) &&
|
|
49
|
+
typeof ((_b = configuration.po) === null || _b === void 0 ? void 0 : _b.directory) !== 'undefined') {
|
|
50
|
+
const filename = `${configuration.package.textdomain}.pot`;
|
|
51
|
+
const potfile = path.join(configuration.po.directory, filename);
|
|
52
|
+
if (fs.existsSync(potfile)) {
|
|
53
|
+
this.potfile = potfile;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
synopsis() {
|
|
58
|
+
if (typeof this.potfile === 'undefined') {
|
|
59
|
+
return `<${gtx._('POTFILE')}>`;
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
return `[${gtx._('POTFILE')}]`;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
description() {
|
|
66
|
+
return gtx._("Invoke 'msgmerge' for multiple files.");
|
|
67
|
+
}
|
|
68
|
+
aliases() {
|
|
69
|
+
return [];
|
|
70
|
+
}
|
|
71
|
+
args() {
|
|
72
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
73
|
+
const options = {
|
|
74
|
+
locales: {
|
|
75
|
+
alias: 'l',
|
|
76
|
+
type: 'array',
|
|
77
|
+
describe: gtx._('List of locale identifiers'),
|
|
78
|
+
demandOption: true,
|
|
79
|
+
default: (_a = this.configuration.po) === null || _a === void 0 ? void 0 : _a.locales,
|
|
80
|
+
group: gtx._('Input file options:'),
|
|
81
|
+
},
|
|
82
|
+
directory: {
|
|
83
|
+
alias: 'D',
|
|
84
|
+
type: 'string',
|
|
85
|
+
describe: gtx._("Search '.po' files in DIRECTORY"),
|
|
86
|
+
default: (_c = (_b = this.configuration.po) === null || _b === void 0 ? void 0 : _b.directory) !== null && _c !== void 0 ? _c : '.',
|
|
87
|
+
group: gtx._('Input file options:'),
|
|
88
|
+
},
|
|
89
|
+
msgmerge: {
|
|
90
|
+
type: 'string',
|
|
91
|
+
describe: gtx._('msgmerge program if not in PATH [string]'),
|
|
92
|
+
default: (_f = (_e = (_d = this.configuration.programs) === null || _d === void 0 ? void 0 : _d.msgmerge) === null || _e === void 0 ? void 0 : _e.path) !== null && _f !== void 0 ? _f : 'msgmerge',
|
|
93
|
+
group: gtx._('Mode of operation:'),
|
|
94
|
+
},
|
|
95
|
+
options: {
|
|
96
|
+
type: 'string',
|
|
97
|
+
array: true,
|
|
98
|
+
describe: gtx._x("Options to pass to '{program}' program (without hyphens)", { program: 'msgmerge' }),
|
|
99
|
+
default: (_h = (_g = this.configuration.programs) === null || _g === void 0 ? void 0 : _g.msgfmt) === null || _h === void 0 ? void 0 : _h.options,
|
|
100
|
+
group: gtx._('Mode of operation:'),
|
|
101
|
+
},
|
|
102
|
+
verbose: {
|
|
103
|
+
alias: 'V',
|
|
104
|
+
type: 'boolean',
|
|
105
|
+
describe: gtx._('Enable verbose output'),
|
|
106
|
+
},
|
|
107
|
+
};
|
|
108
|
+
for (const name of ['locales', 'options']) {
|
|
109
|
+
if (!options[name].default) {
|
|
110
|
+
delete options[name].default;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
return options;
|
|
114
|
+
}
|
|
115
|
+
additional(argv) {
|
|
116
|
+
argv.positional(gtx._('POTFILE'), {
|
|
117
|
+
type: 'string',
|
|
118
|
+
describe: gtx._('Catalog file with up-to-date message ids'),
|
|
119
|
+
default: this.potfile,
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
init(argv) {
|
|
123
|
+
var _a, _b;
|
|
124
|
+
const options = argv;
|
|
125
|
+
this.options = options;
|
|
126
|
+
const conf = this.configuration;
|
|
127
|
+
this.potfile = options[gtx._('POTFILE')];
|
|
128
|
+
if (!options.locales && ((_a = conf.po) === null || _a === void 0 ? void 0 : _a.locales)) {
|
|
129
|
+
options.locales = (_b = conf.po) === null || _b === void 0 ? void 0 : _b.locales;
|
|
130
|
+
}
|
|
131
|
+
if (!options.locales || !options.locales.length) {
|
|
132
|
+
throw new Error(gtx._('no locales given'));
|
|
133
|
+
}
|
|
134
|
+
this.locales = [];
|
|
135
|
+
for (let i = 0; i < options.locales.length; ++i) {
|
|
136
|
+
const locales = options.locales[i].split(/[ \t]*,[ \t]*/);
|
|
137
|
+
for (let j = 0; j < locales.length; ++j) {
|
|
138
|
+
this.locales.push(locales[j]);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
run(argv) {
|
|
143
|
+
this.init(argv);
|
|
144
|
+
return new Promise(resolve => {
|
|
145
|
+
const promises = this.locales.map(locale => this.msgmergeLocale(locale));
|
|
146
|
+
Promise.all(promises)
|
|
147
|
+
.then(results => {
|
|
148
|
+
const hasOne = results.some(result => result === 1);
|
|
149
|
+
resolve(hasOne ? 1 : 0);
|
|
150
|
+
})
|
|
151
|
+
.catch(() => {
|
|
152
|
+
resolve(1);
|
|
153
|
+
});
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
convertOptions(options) {
|
|
157
|
+
const msgmergeOptions = [];
|
|
158
|
+
let errors = 0;
|
|
159
|
+
if (options) {
|
|
160
|
+
options.forEach(name => {
|
|
161
|
+
if (name.substring(0, 1) === '-') {
|
|
162
|
+
console.error(gtx._x("{programName}: option '{option}': Options passed to '{program}' must not start with a hyphen", {
|
|
163
|
+
programName: package_1.Package.getName(),
|
|
164
|
+
program: 'msgfmt',
|
|
165
|
+
option: name,
|
|
166
|
+
}));
|
|
167
|
+
++errors;
|
|
168
|
+
}
|
|
169
|
+
if (name.length > 1) {
|
|
170
|
+
msgmergeOptions.push(`--${name}`);
|
|
171
|
+
}
|
|
172
|
+
else if (name.length === 1) {
|
|
173
|
+
msgmergeOptions.push(`-${name}`);
|
|
174
|
+
}
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
return errors ? null : msgmergeOptions;
|
|
178
|
+
}
|
|
179
|
+
msgmergeLocale(locale) {
|
|
180
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
181
|
+
return new Promise(resolve => {
|
|
182
|
+
const args = this.convertOptions(this.options.options);
|
|
183
|
+
if (!args)
|
|
184
|
+
return resolve(1);
|
|
185
|
+
const poFile = this.options.directory + '/' + locale + '.po';
|
|
186
|
+
const oldPoFile = this.options.directory + '/' + locale + '.old.po';
|
|
187
|
+
args.push(oldPoFile, this.potfile, '-o', poFile);
|
|
188
|
+
console.log(gtx._x("Merging '{pot}' into '{po}'.", {
|
|
189
|
+
pot: this.potfile,
|
|
190
|
+
po: poFile,
|
|
191
|
+
}));
|
|
192
|
+
try {
|
|
193
|
+
fs.renameSync(poFile, oldPoFile);
|
|
194
|
+
const msgmerge = childProcess.spawn(this.options.msgmerge, args, {
|
|
195
|
+
windowsHide: true,
|
|
196
|
+
});
|
|
197
|
+
msgmerge.on('error', err => {
|
|
198
|
+
throw new Error(gtx._x("Failed to run '{prg}': {err}", {
|
|
199
|
+
prg: this.options.msgmerge,
|
|
200
|
+
err,
|
|
201
|
+
}));
|
|
202
|
+
});
|
|
203
|
+
msgmerge.stdout.on('data', (data) => process.stdout.write(data.toString()));
|
|
204
|
+
msgmerge.stderr.on('data', (data) => process.stderr.write(data.toString()));
|
|
205
|
+
msgmerge.on('close', code => {
|
|
206
|
+
if (code) {
|
|
207
|
+
fs.renameSync(oldPoFile, poFile);
|
|
208
|
+
resolve(1);
|
|
209
|
+
}
|
|
210
|
+
else {
|
|
211
|
+
fs.unlinkSync(oldPoFile);
|
|
212
|
+
resolve(0);
|
|
213
|
+
}
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
catch (err) {
|
|
217
|
+
try {
|
|
218
|
+
fs.renameSync(oldPoFile, poFile);
|
|
219
|
+
}
|
|
220
|
+
catch (err1) {
|
|
221
|
+
console.error(err1);
|
|
222
|
+
}
|
|
223
|
+
console.error(err);
|
|
224
|
+
resolve(1);
|
|
225
|
+
}
|
|
226
|
+
});
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
exports.MsgmergeAll = MsgmergeAll;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FileResolver = void 0;
|
|
4
|
+
const path_1 = require("path");
|
|
5
|
+
const fs_1 = require("fs");
|
|
6
|
+
class FileResolver {
|
|
7
|
+
constructor(directories = ['']) {
|
|
8
|
+
this.directories = directories;
|
|
9
|
+
}
|
|
10
|
+
resolve(filename) {
|
|
11
|
+
for (let i = 0; i < this.directories.length; ++i) {
|
|
12
|
+
const resolved = (0, path_1.join)(this.directories[i], filename);
|
|
13
|
+
if ((0, fs_1.existsSync)(resolved)) {
|
|
14
|
+
return resolved;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
exports.FileResolver = FileResolver;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FilesCollector = void 0;
|
|
4
|
+
const fs_1 = require("fs");
|
|
5
|
+
const runtime_1 = require("@esgettext/runtime");
|
|
6
|
+
const gtx = runtime_1.Textdomain.getInstance('tools');
|
|
7
|
+
class FilesCollector {
|
|
8
|
+
constructor(filesFrom, args) {
|
|
9
|
+
if (typeof filesFrom === 'undefined' && args.length === 0) {
|
|
10
|
+
throw new Error(gtx._('no input file given'));
|
|
11
|
+
}
|
|
12
|
+
const filenames = new Array();
|
|
13
|
+
if (typeof filesFrom !== 'undefined') {
|
|
14
|
+
filesFrom.forEach(fromFile => {
|
|
15
|
+
this.getFilesFromFile(fromFile).forEach(filename => {
|
|
16
|
+
filenames.push(filename);
|
|
17
|
+
});
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
args.forEach(filename => filenames.push(filename));
|
|
21
|
+
// Make filenames unique.
|
|
22
|
+
this.filenames = Array.from(new Set(filenames));
|
|
23
|
+
}
|
|
24
|
+
getFilesFromFile(filename) {
|
|
25
|
+
let content;
|
|
26
|
+
if ('-' === filename) {
|
|
27
|
+
content = process.stdin.read();
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
content = (0, fs_1.readFileSync)(filename);
|
|
31
|
+
}
|
|
32
|
+
return content
|
|
33
|
+
.toString()
|
|
34
|
+
.split('\n')
|
|
35
|
+
.map(line => line.replace(/#.*/, '').trim())
|
|
36
|
+
.filter(line => line.length);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
exports.FilesCollector = FilesCollector;
|