@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.
Files changed (113) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +197 -22
  3. package/dist/command.js +2 -0
  4. package/dist/commands/convert.js +286 -0
  5. package/dist/commands/install.js +257 -0
  6. package/dist/commands/msgfmt-all.js +219 -0
  7. package/dist/commands/msgmerge-all.js +230 -0
  8. package/dist/commands/xgettext/file-resolver.js +20 -0
  9. package/dist/commands/xgettext/files-collector.js +39 -0
  10. package/dist/commands/xgettext.js +534 -0
  11. package/dist/configuration.js +277 -0
  12. package/dist/esgettext-package-json.js +2 -0
  13. package/dist/index.js +135 -0
  14. package/dist/package.js +10 -12
  15. package/dist/parser/javascript.js +9 -28
  16. package/dist/parser/parser.js +176 -148
  17. package/dist/parser/po.js +144 -128
  18. package/dist/parser/typescript.js +10 -28
  19. package/dist/pot/catalog.js +134 -83
  20. package/dist/pot/entry.js +173 -115
  21. package/dist/pot/keyword.js +66 -92
  22. package/package.json +38 -25
  23. package/bin/esgettext-install.js +0 -5
  24. package/bin/esgettext-mo2json.js +0 -5
  25. package/bin/esgettext-msgfmt-all.js +0 -5
  26. package/bin/esgettext-msgmerge-all.js +0 -5
  27. package/bin/esgettext-xgettext.js +0 -5
  28. package/dist/cli/getopt.d.ts +0 -34
  29. package/dist/cli/getopt.js +0 -150
  30. package/dist/cli/getopt.js.map +0 -1
  31. package/dist/cli/getopt.spec.d.ts +0 -1
  32. package/dist/cli/getopt.spec.js +0 -164
  33. package/dist/cli/getopt.spec.js.map +0 -1
  34. package/dist/cli/install.d.ts +0 -1
  35. package/dist/cli/install.js +0 -91
  36. package/dist/cli/install.js.map +0 -1
  37. package/dist/cli/mo2json-cli.d.ts +0 -1
  38. package/dist/cli/mo2json-cli.js +0 -48
  39. package/dist/cli/mo2json-cli.js.map +0 -1
  40. package/dist/cli/msgfmt-all.d.ts +0 -1
  41. package/dist/cli/msgfmt-all.js +0 -99
  42. package/dist/cli/msgfmt-all.js.map +0 -1
  43. package/dist/cli/msgmerge-all.d.ts +0 -1
  44. package/dist/cli/msgmerge-all.js +0 -85
  45. package/dist/cli/msgmerge-all.js.map +0 -1
  46. package/dist/cli/xgettext-cli.d.ts +0 -1
  47. package/dist/cli/xgettext-cli.js +0 -303
  48. package/dist/cli/xgettext-cli.js.map +0 -1
  49. package/dist/install/install.d.ts +0 -10
  50. package/dist/install/install.js +0 -157
  51. package/dist/install/install.js.map +0 -1
  52. package/dist/msgfmt-all/msgfmt-all.d.ts +0 -8
  53. package/dist/msgfmt-all/msgfmt-all.js +0 -142
  54. package/dist/msgfmt-all/msgfmt-all.js.map +0 -1
  55. package/dist/msgmerge-all/msgmerge-all.d.ts +0 -9
  56. package/dist/msgmerge-all/msgmerge-all.js +0 -157
  57. package/dist/msgmerge-all/msgmerge-all.js.map +0 -1
  58. package/dist/package.d.ts +0 -4
  59. package/dist/package.js.map +0 -1
  60. package/dist/parser/__snapshots__/javascript.spec.js.snap +0 -56
  61. package/dist/parser/__snapshots__/po.spec.js.snap +0 -176
  62. package/dist/parser/javascript.d.ts +0 -4
  63. package/dist/parser/javascript.js.map +0 -1
  64. package/dist/parser/javascript.spec.d.ts +0 -1
  65. package/dist/parser/javascript.spec.js +0 -436
  66. package/dist/parser/javascript.spec.js.map +0 -1
  67. package/dist/parser/parser.d.ts +0 -45
  68. package/dist/parser/parser.js.map +0 -1
  69. package/dist/parser/po.d.ts +0 -22
  70. package/dist/parser/po.js.map +0 -1
  71. package/dist/parser/po.spec.d.ts +0 -1
  72. package/dist/parser/po.spec.js +0 -296
  73. package/dist/parser/po.spec.js.map +0 -1
  74. package/dist/parser/typescript.d.ts +0 -4
  75. package/dist/parser/typescript.js.map +0 -1
  76. package/dist/parser/typescript.spec.d.ts +0 -1
  77. package/dist/parser/typescript.spec.js +0 -106
  78. package/dist/parser/typescript.spec.js.map +0 -1
  79. package/dist/pot/__snapshots__/catalog.spec.js.snap +0 -591
  80. package/dist/pot/catalog.d.ts +0 -26
  81. package/dist/pot/catalog.js.map +0 -1
  82. package/dist/pot/catalog.spec.d.ts +0 -1
  83. package/dist/pot/catalog.spec.js +0 -240
  84. package/dist/pot/catalog.spec.js.map +0 -1
  85. package/dist/pot/entry.d.ts +0 -35
  86. package/dist/pot/entry.js.map +0 -1
  87. package/dist/pot/entry.spec.d.ts +0 -1
  88. package/dist/pot/entry.spec.js +0 -317
  89. package/dist/pot/entry.spec.js.map +0 -1
  90. package/dist/pot/keyword.d.ts +0 -17
  91. package/dist/pot/keyword.js.map +0 -1
  92. package/dist/pot/keyword.spec.d.ts +0 -1
  93. package/dist/pot/keyword.spec.js +0 -54
  94. package/dist/pot/keyword.spec.js.map +0 -1
  95. package/dist/xgettext/__snapshots__/xgettext.spec.js.snap +0 -462
  96. package/dist/xgettext/file-resolver.d.ts +0 -5
  97. package/dist/xgettext/file-resolver.js +0 -23
  98. package/dist/xgettext/file-resolver.js.map +0 -1
  99. package/dist/xgettext/file-resolver.spec.d.ts +0 -1
  100. package/dist/xgettext/file-resolver.spec.js +0 -22
  101. package/dist/xgettext/file-resolver.spec.js.map +0 -1
  102. package/dist/xgettext/files-collector.d.ts +0 -5
  103. package/dist/xgettext/files-collector.js +0 -41
  104. package/dist/xgettext/files-collector.js.map +0 -1
  105. package/dist/xgettext/files-collector.spec.d.ts +0 -1
  106. package/dist/xgettext/files-collector.spec.js +0 -78
  107. package/dist/xgettext/files-collector.spec.js.map +0 -1
  108. package/dist/xgettext/xgettext.d.ts +0 -16
  109. package/dist/xgettext/xgettext.js +0 -335
  110. package/dist/xgettext/xgettext.js.map +0 -1
  111. package/dist/xgettext/xgettext.spec.d.ts +0 -1
  112. package/dist/xgettext/xgettext.spec.js +0 -743
  113. package/dist/xgettext/xgettext.spec.js.map +0 -1
@@ -0,0 +1,257 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.Install = void 0;
27
+ const fs_1 = require("fs");
28
+ const runtime_1 = require("@esgettext/runtime");
29
+ const mkdirp = __importStar(require("mkdirp"));
30
+ const gtx = runtime_1.Textdomain.getInstance('com.cantanea.esgettext-tools');
31
+ class Install {
32
+ constructor(configuration) {
33
+ this.locales = undefined;
34
+ this.options = undefined;
35
+ this.configuration = configuration;
36
+ }
37
+ synopsis() {
38
+ return gtx._('[OPTIONS]');
39
+ }
40
+ description() {
41
+ return gtx._('Install translation catalogs.');
42
+ }
43
+ aliases() {
44
+ return [];
45
+ }
46
+ args() {
47
+ var _a, _b, _c, _d, _e, _f;
48
+ return {
49
+ locales: {
50
+ alias: 'l',
51
+ type: 'array',
52
+ describe: gtx._('List of locale identifiers'),
53
+ demandOption: true,
54
+ default: (_a = this.configuration.po) === null || _a === void 0 ? void 0 : _a.locales,
55
+ group: gtx._('Input file options:'),
56
+ },
57
+ directory: {
58
+ alias: 'D',
59
+ type: 'string',
60
+ describe: gtx._('Where to search message catalog files'),
61
+ default: (_c = (_b = this.configuration.po) === null || _b === void 0 ? void 0 : _b.directory) !== null && _c !== void 0 ? _c : '.',
62
+ group: gtx._('Input file options:'),
63
+ },
64
+ 'input-format': {
65
+ type: 'string',
66
+ describe: gtx._('Input file type'),
67
+ default: 'gmo',
68
+ choices: ['gmo', 'mo'],
69
+ group: gtx._('Input file options:'),
70
+ },
71
+ 'default-domain': {
72
+ type: 'string',
73
+ describe: gtx._('The textdomain to use'),
74
+ default: (_d = this.configuration.package) === null || _d === void 0 ? void 0 : _d.textdomain,
75
+ group: gtx._('Output file options'),
76
+ },
77
+ 'output-directory': {
78
+ type: 'string',
79
+ describe: gtx._('Output directory'),
80
+ default: (_f = (_e = this.configuration.install) === null || _e === void 0 ? void 0 : _e.directory) !== null && _f !== void 0 ? _f : 'src/locale',
81
+ group: gtx._('Output file options:'),
82
+ },
83
+ 'output-format': {
84
+ type: 'string',
85
+ describe: gtx._('Output format'),
86
+ default: 'mo.json',
87
+ choices: ['mo.json', 'json', 'mo'],
88
+ group: gtx._('Output file options:'),
89
+ },
90
+ verbose: {
91
+ alias: 'V',
92
+ type: 'boolean',
93
+ describe: gtx._('Enable verbose output'),
94
+ },
95
+ };
96
+ }
97
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
98
+ additional(_) { }
99
+ init(argv) {
100
+ var _a, _b, _c, _d;
101
+ const options = argv;
102
+ this.options = options;
103
+ const conf = this.configuration;
104
+ if (!options.locales && ((_a = this.configuration.po) === null || _a === void 0 ? void 0 : _a.locales)) {
105
+ options.locales = (_b = conf.po) === null || _b === void 0 ? void 0 : _b.locales;
106
+ }
107
+ if (!options.locales || !options.locales.length) {
108
+ throw new Error(gtx._('no locales given'));
109
+ }
110
+ if (options.outputFormat !== 'mo.json' &&
111
+ options.outputFormat !== 'mo' &&
112
+ options.outputFormat !== 'json') {
113
+ throw new Error(gtx._("only 'mo.json', 'mo', and 'json' are allowed as output formats!"));
114
+ }
115
+ if (typeof options.directory === 'undefined') {
116
+ if ((_d = (_c = conf.po) === null || _c === void 0 ? void 0 : _c.directory) === null || _d === void 0 ? void 0 : _d.length) {
117
+ options.directory = conf.po.directory;
118
+ }
119
+ else {
120
+ options.directory = '.';
121
+ }
122
+ }
123
+ this.locales = [];
124
+ for (let i = 0; i < options.locales.length; ++i) {
125
+ const locales = options.locales[i].split(/[ \t]*,[ \t]*/);
126
+ for (let j = 0; j < locales.length; ++j) {
127
+ this.locales.push(locales[j]);
128
+ }
129
+ }
130
+ }
131
+ run(argv) {
132
+ this.init(argv);
133
+ return new Promise(resolve => {
134
+ const promises = [];
135
+ for (let i = 0; i < this.locales.length; ++i) {
136
+ const locale = this.locales[i];
137
+ promises.push(this.installLocale(locale));
138
+ }
139
+ Promise.all(promises)
140
+ .then(codes => {
141
+ const failures = codes.filter(v => v !== 0);
142
+ if (failures.length) {
143
+ resolve(1);
144
+ }
145
+ else {
146
+ resolve(0);
147
+ }
148
+ })
149
+ .catch(err => {
150
+ console.error(err);
151
+ resolve(1);
152
+ });
153
+ });
154
+ }
155
+ installMoLocale(inFile, outFile) {
156
+ return new Promise(resolve => {
157
+ if (this.options.verbose) {
158
+ console.log(gtx._x("Installing '{inFile}' as '{outFile}' ...", {
159
+ inFile,
160
+ outFile,
161
+ }));
162
+ }
163
+ (0, fs_1.copyFile)(inFile, outFile, err => {
164
+ if (err) {
165
+ throw err;
166
+ }
167
+ else {
168
+ resolve(0);
169
+ }
170
+ });
171
+ });
172
+ }
173
+ installMoJsonLocale(inFile, outFile) {
174
+ return new Promise(resolve => {
175
+ if (this.options.verbose) {
176
+ console.log(gtx._x("Compiling '{inFile}' into '{outFile}' ...", {
177
+ inFile,
178
+ outFile,
179
+ }));
180
+ }
181
+ const input = (0, fs_1.readFileSync)(inFile);
182
+ const catalog = (0, runtime_1.parseMoCatalog)(input);
183
+ const json = JSON.stringify(catalog);
184
+ (0, fs_1.writeFile)(outFile, json, err => {
185
+ if (err) {
186
+ console.error(gtx._x('{outfile}: Write error: {err}', {
187
+ outFile,
188
+ err,
189
+ }));
190
+ resolve(1);
191
+ }
192
+ else {
193
+ resolve(0);
194
+ }
195
+ });
196
+ });
197
+ }
198
+ installJsonLocale(inFile, outFile) {
199
+ return new Promise(resolve => {
200
+ if (this.options.verbose) {
201
+ console.log(gtx._x("Compiling '{inFile}' into '{outFile}' ...", {
202
+ inFile,
203
+ outFile,
204
+ }));
205
+ }
206
+ const input = (0, fs_1.readFileSync)(inFile);
207
+ const catalog = (0, runtime_1.parseMoCatalog)(input);
208
+ const msgs = {};
209
+ for (const msgid in catalog.entries) {
210
+ const msgstr = catalog.entries[msgid];
211
+ if (msgstr.length > 1) {
212
+ console.error(gtx._x("{inFile}: plural expressions are not allowed for '.json' output!", { inFile }));
213
+ resolve(1);
214
+ return;
215
+ }
216
+ msgs[msgid] = msgstr[0];
217
+ }
218
+ const json = JSON.stringify(msgs);
219
+ (0, fs_1.writeFile)(outFile, json, err => {
220
+ if (err) {
221
+ console.error(gtx._x('{outfile}: Write error: {err}', {
222
+ outFile,
223
+ err,
224
+ }));
225
+ resolve(1);
226
+ }
227
+ else {
228
+ resolve(0);
229
+ }
230
+ });
231
+ });
232
+ }
233
+ installLocale(locale) {
234
+ try {
235
+ const directory = this.options.outputDirectory + '/' + locale + '/LC_MESSAGES';
236
+ const outFile = directory + '/' + this.options.defaultDomain + '.' + this.options.outputFormat;
237
+ const inFile = this.options.directory + '/' + locale + '.' + this.options.inputFormat;
238
+ if (!(0, fs_1.existsSync)(directory)) {
239
+ mkdirp.sync(directory);
240
+ }
241
+ if (this.options.outputFormat === 'mo.json') {
242
+ return this.installMoJsonLocale(inFile, outFile);
243
+ }
244
+ else if (this.options.outputFormat === 'json') {
245
+ return this.installJsonLocale(inFile, outFile);
246
+ }
247
+ else {
248
+ return this.installMoLocale(inFile, outFile);
249
+ }
250
+ }
251
+ catch (err) {
252
+ console.error(err);
253
+ throw err;
254
+ }
255
+ }
256
+ }
257
+ exports.Install = Install;
@@ -0,0 +1,219 @@
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.MsgfmtAll = void 0;
36
+ const fs = __importStar(require("fs"));
37
+ const childProcess = __importStar(require("child_process"));
38
+ const runtime_1 = require("@esgettext/runtime");
39
+ const package_1 = require("../package");
40
+ const gtx = runtime_1.Textdomain.getInstance('com.cantanea.esgettext-tools');
41
+ class MsgfmtAll {
42
+ constructor(configuration) {
43
+ this.locales = undefined;
44
+ this.options = undefined;
45
+ this.configuration = configuration;
46
+ }
47
+ synopsis() {
48
+ return '';
49
+ }
50
+ description() {
51
+ return gtx._("Invoke 'msgfmt' for multiple files.");
52
+ }
53
+ aliases() {
54
+ return [];
55
+ }
56
+ args() {
57
+ var _a, _b, _c, _d, _e, _f, _g, _h;
58
+ const options = {
59
+ locales: {
60
+ alias: 'l',
61
+ type: 'array',
62
+ describe: gtx._('List of locale identifiers'),
63
+ demandOption: true,
64
+ default: (_a = this.configuration.po) === null || _a === void 0 ? void 0 : _a.locales,
65
+ group: gtx._('Input file options:'),
66
+ },
67
+ directory: {
68
+ alias: 'D',
69
+ type: 'string',
70
+ describe: gtx._("Search '.po' files in DIRECTORY"),
71
+ default: (_c = (_b = this.configuration.po) === null || _b === void 0 ? void 0 : _b.directory) !== null && _c !== void 0 ? _c : '.',
72
+ group: gtx._('Input file options:'),
73
+ },
74
+ format: {
75
+ type: 'string',
76
+ describe: gtx._('Output file format'),
77
+ default: 'gmo',
78
+ group: gtx._('Output file options:'),
79
+ },
80
+ msgfmt: {
81
+ type: 'string',
82
+ describe: gtx._('msgfmt program if not in PATH [string]'),
83
+ default: (_f = (_e = (_d = this.configuration.programs) === null || _d === void 0 ? void 0 : _d.msgfmt) === null || _e === void 0 ? void 0 : _e.path) !== null && _f !== void 0 ? _f : 'msgfmt',
84
+ group: gtx._('Mode of operation:'),
85
+ },
86
+ options: {
87
+ type: 'string',
88
+ array: true,
89
+ describe: gtx._x("Options to pass to '{program}' program (without hyphens)", { program: 'msgfmt' }),
90
+ default: ((_h = (_g = this.configuration.programs) === null || _g === void 0 ? void 0 : _g.msgfmt) === null || _h === void 0 ? void 0 : _h.options) || [
91
+ 'check',
92
+ 'statistics',
93
+ 'verbose',
94
+ ],
95
+ group: gtx._('Mode of operation:'),
96
+ },
97
+ verbose: {
98
+ alias: 'V',
99
+ type: 'boolean',
100
+ describe: gtx._('Enable verbose output'),
101
+ },
102
+ };
103
+ for (const name of ['locales', 'options']) {
104
+ if (!options[name].default) {
105
+ delete options[name].default;
106
+ }
107
+ }
108
+ return options;
109
+ }
110
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
111
+ additional(_) { }
112
+ init(argv) {
113
+ var _a, _b;
114
+ const options = argv;
115
+ this.options = options;
116
+ const conf = this.configuration;
117
+ if (!options.locales && ((_a = conf.po) === null || _a === void 0 ? void 0 : _a.locales)) {
118
+ options.locales = (_b = conf.po) === null || _b === void 0 ? void 0 : _b.locales;
119
+ }
120
+ if (!options.locales || !options.locales.length) {
121
+ throw new Error(gtx._('no locales given'));
122
+ }
123
+ this.locales = [];
124
+ for (let i = 0; i < options.locales.length; ++i) {
125
+ const locales = options.locales[i].split(/[ \t]*,[ \t]*/);
126
+ for (let j = 0; j < locales.length; ++j) {
127
+ this.locales.push(locales[j]);
128
+ }
129
+ }
130
+ }
131
+ run(argv) {
132
+ this.init(argv);
133
+ return new Promise(resolve => {
134
+ const promises = this.locales.map(locale => this.msgfmtLocale(locale));
135
+ Promise.all(promises)
136
+ .then(results => {
137
+ const hasOne = results.some(result => result === 1);
138
+ resolve(hasOne ? 1 : 0);
139
+ })
140
+ .catch(() => {
141
+ resolve(1);
142
+ });
143
+ });
144
+ }
145
+ convertOptions(options) {
146
+ const msgmergeOptions = [];
147
+ let errors = 0;
148
+ if (options) {
149
+ options.forEach(name => {
150
+ if (name.substring(0, 1) === '-') {
151
+ console.error(gtx._x("{programName}: option '{option}': Options passed to '{program}' must not start with a hyphen", {
152
+ programName: package_1.Package.getName(),
153
+ program: 'msgfmt',
154
+ option: name,
155
+ }));
156
+ ++errors;
157
+ }
158
+ if (name.length > 1) {
159
+ msgmergeOptions.push(`--${name}`);
160
+ }
161
+ else if (name.length === 1) {
162
+ msgmergeOptions.push(`-${name}`);
163
+ }
164
+ });
165
+ }
166
+ return errors ? null : msgmergeOptions;
167
+ }
168
+ msgfmtLocale(locale) {
169
+ return __awaiter(this, void 0, void 0, function* () {
170
+ return new Promise(resolve => {
171
+ const args = this.convertOptions(this.options.options);
172
+ if (!args)
173
+ return resolve(1);
174
+ const poFile = this.options.directory + '/' + locale + '.po';
175
+ const moFile = this.options.directory + '/' + locale + '.' + this.options.format;
176
+ args.push('-o', moFile, poFile);
177
+ if (this.options.verbose) {
178
+ console.log(gtx._x("Compiling '{po}' into '{mo}'.", {
179
+ po: poFile,
180
+ mo: moFile,
181
+ }));
182
+ }
183
+ try {
184
+ const msgfmt = childProcess.spawn(this.options.msgfmt, args, {
185
+ windowsHide: true,
186
+ });
187
+ msgfmt.stdout.on('data', (data) => process.stdout.write(data.toString()));
188
+ msgfmt.stderr.on('data', (data) => process.stderr.write(data.toString()));
189
+ msgfmt.on('close', code => {
190
+ if (code) {
191
+ fs.unlinkSync(moFile);
192
+ resolve(1);
193
+ }
194
+ else {
195
+ resolve(0);
196
+ }
197
+ });
198
+ msgfmt.on('error', err => {
199
+ throw new Error(gtx._x("Failed to run '{prg}': {err}", {
200
+ prg: this.options.msgfmt,
201
+ err,
202
+ }));
203
+ });
204
+ }
205
+ catch (err) {
206
+ try {
207
+ fs.unlinkSync(moFile);
208
+ }
209
+ catch (err1) {
210
+ console.error(err1);
211
+ }
212
+ console.error(err);
213
+ resolve(1);
214
+ }
215
+ });
216
+ });
217
+ }
218
+ }
219
+ exports.MsgfmtAll = MsgfmtAll;