@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,534 @@
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.XGettext = void 0;
27
+ const fs_1 = require("fs");
28
+ const path = __importStar(require("path"));
29
+ const runtime_1 = require("@esgettext/runtime");
30
+ const catalog_1 = require("../pot/catalog");
31
+ const po_1 = require("../parser/po");
32
+ const files_collector_1 = require("./xgettext/files-collector");
33
+ const typescript_1 = require("../parser/typescript");
34
+ const javascript_1 = require("../parser/javascript");
35
+ const keyword_1 = require("../pot/keyword");
36
+ const gtx = runtime_1.Textdomain.getInstance('com.cantanea.esgettext-tools');
37
+ class XGettext {
38
+ // The date is only passed for testing.
39
+ constructor(configuration, date) {
40
+ this.catalog = undefined;
41
+ this.exclude = undefined;
42
+ this.options = undefined;
43
+ this.date = date;
44
+ this.configuration = configuration;
45
+ }
46
+ synopsis() {
47
+ return `[${gtx._('INPUTFILE')}...]`;
48
+ }
49
+ description() {
50
+ return gtx._('Extract translatable strings from given input files.');
51
+ }
52
+ aliases() {
53
+ return ['extract'];
54
+ }
55
+ args() {
56
+ var _a, _b, _c, _d, _e, _f, _g, _h;
57
+ const outputFile = ((_a = this.configuration.package) === null || _a === void 0 ? void 0 : _a.textdomain)
58
+ ? `${this.configuration.package.textdomain}.pot`
59
+ : undefined;
60
+ return {
61
+ 'files-from': {
62
+ group: gtx._('Input file location:'),
63
+ type: 'string',
64
+ array: true,
65
+ describe: gtx._('get list of input files from FILE'),
66
+ default: (_b = this.configuration.package) === null || _b === void 0 ? void 0 : _b['files-from'],
67
+ },
68
+ directory: {
69
+ group: gtx._('Input file location:'),
70
+ type: 'string',
71
+ array: true,
72
+ describe: gtx._('add directory to list for input files search\nIf input file is -, standard input is read.'),
73
+ },
74
+ 'default-domain': {
75
+ group: gtx._('Output file location:'),
76
+ alias: 'd',
77
+ type: 'string',
78
+ describe: gtx._('use NAME.po for output (instead of messages.po)'),
79
+ },
80
+ output: {
81
+ group: gtx._('Output file location:'),
82
+ alias: 'o',
83
+ type: 'string',
84
+ describe: gtx._('write output to specified file'),
85
+ default: outputFile,
86
+ },
87
+ 'output-dir': {
88
+ group: gtx._('Output file location:'),
89
+ alias: 'p',
90
+ type: 'string',
91
+ describe: gtx._('output files will be placed in directory DIR. If output file is -, output is written to standard output.'),
92
+ default: (_d = (_c = this.configuration.po) === null || _c === void 0 ? void 0 : _c.directory) !== null && _d !== void 0 ? _d : '.',
93
+ },
94
+ language: {
95
+ group: gtx._('Choice of input file language:'),
96
+ alias: 'L',
97
+ type: 'string',
98
+ choices: ['javascript', 'typescript'],
99
+ coerce: arg => arg.toLowerCase(),
100
+ describe: gtx._('recognise the specified language (JavaScript, TypeScript, HTML). Default is to auto-detect language based on filename extension.'),
101
+ },
102
+ 'from-code': {
103
+ group: gtx._('Interpretation of input files:'),
104
+ type: 'string',
105
+ describe: gtx._('encoding of input files'),
106
+ default: 'ASCII',
107
+ },
108
+ 'join-existing': {
109
+ group: gtx._('Operation mode:'),
110
+ alias: 'j',
111
+ type: 'boolean',
112
+ describe: gtx._('join messages with existing file'),
113
+ },
114
+ 'exclude-file': {
115
+ group: gtx._('Operation mode:'),
116
+ alias: 'x',
117
+ type: 'string',
118
+ describe: gtx._('entries from FILE.po are not extracted'),
119
+ array: true,
120
+ },
121
+ 'add-comments': {
122
+ group: gtx._('Operation mode:'),
123
+ alias: 'c',
124
+ type: 'string',
125
+ describe: gtx._('place comment blocks starting with TAG and preceding keyword lines in output file'),
126
+ array: true,
127
+ },
128
+ 'add-all-comments': {
129
+ group: gtx._('Operation mode:'),
130
+ describe: gtx._('place all comment blocks preceding keyword lines in output file'),
131
+ type: 'boolean',
132
+ },
133
+ 'extract-all': {
134
+ group: gtx._('Language specific options:'),
135
+ alias: 'a',
136
+ type: 'boolean',
137
+ describe: gtx._('extract all strings'),
138
+ },
139
+ keyword: {
140
+ group: gtx._('Language specific options:'),
141
+ type: 'string',
142
+ describe: gtx._('look for WORD as an additional keyword'),
143
+ array: true,
144
+ },
145
+ flag: {
146
+ group: gtx._('Language specific options:'),
147
+ type: 'string',
148
+ describe: gtx._('argument: WORD:ARG:FLAG, additional flag for strings inside the argument number ARG of keyword WORD'),
149
+ array: true,
150
+ },
151
+ instance: {
152
+ group: gtx._('Language specific options:'),
153
+ type: 'string',
154
+ describe: gtx._('only accept method calls of specified instance names'),
155
+ array: true,
156
+ },
157
+ 'force-po': {
158
+ group: gtx._('Output details:'),
159
+ type: 'boolean',
160
+ describe: gtx._('write PO file even if empty'),
161
+ },
162
+ width: {
163
+ group: gtx._('Output details:'),
164
+ type: 'number',
165
+ describe: gtx._('set output page width'),
166
+ },
167
+ 'no-wrap': {
168
+ group: gtx._('Output details:'),
169
+ type: 'boolean',
170
+ describe: gtx._('do not break long message lines,' +
171
+ ' longer than' +
172
+ ' the output page width, into' +
173
+ ' several lines'),
174
+ },
175
+ 'sort-output': {
176
+ group: gtx._('Output details:'),
177
+ alias: 's',
178
+ type: 'boolean',
179
+ describe: gtx._('generate sorted output'),
180
+ },
181
+ 'sort-by-file': {
182
+ group: gtx._('Output details:'),
183
+ alias: 'F',
184
+ type: 'boolean',
185
+ describe: gtx._('sort output by file location'),
186
+ },
187
+ 'omit-header': {
188
+ group: gtx._('Output details:'),
189
+ type: 'boolean',
190
+ describe: gtx._("don't write header with msgid '\"\"' entry"),
191
+ },
192
+ 'copyright-holder': {
193
+ group: gtx._('Output details:'),
194
+ type: 'string',
195
+ describe: gtx._('set copyright holder in output'),
196
+ default: (_e = this.configuration.package) === null || _e === void 0 ? void 0 : _e['copyright-holder'],
197
+ },
198
+ 'foreign-user': {
199
+ group: gtx._('Output details:'),
200
+ type: 'string',
201
+ describe: gtx._('omit FSF copyright in output for foreign user'),
202
+ },
203
+ 'package-name': {
204
+ group: gtx._('Output details:'),
205
+ type: 'string',
206
+ describe: gtx._('set package name in output'),
207
+ default: (_f = this.configuration.package) === null || _f === void 0 ? void 0 : _f.name,
208
+ },
209
+ 'package-version': {
210
+ group: gtx._('Output details:'),
211
+ type: 'string',
212
+ describe: gtx._('set package version in output'),
213
+ default: (_g = this.configuration.package) === null || _g === void 0 ? void 0 : _g.version,
214
+ },
215
+ 'msgid-bugs-address': {
216
+ group: gtx._('Output details:'),
217
+ type: 'string',
218
+ describe: gtx._('set report address for msgid bugs'),
219
+ default: (_h = this.configuration.package) === null || _h === void 0 ? void 0 : _h['msgid-bugs-address'],
220
+ },
221
+ 'msgstr-prefix': {
222
+ group: gtx._('Output details:'),
223
+ alias: 'm',
224
+ type: 'string',
225
+ describe: gtx._('use STRING or "" as prefix for msgstr values'),
226
+ },
227
+ 'msgstr-suffix': {
228
+ group: gtx._('Output details:'),
229
+ alias: 'M',
230
+ type: 'string',
231
+ describe: gtx._('use STRING or "" as suffix for msgstr values'),
232
+ },
233
+ verbose: {
234
+ alias: 'V',
235
+ type: 'boolean',
236
+ describe: gtx._('Enable verbose output'),
237
+ },
238
+ };
239
+ }
240
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
241
+ additional(_) { }
242
+ init(argv) {
243
+ var _a, _b, _c, _d, _e;
244
+ const options = argv;
245
+ this.options = options;
246
+ const conf = this.configuration;
247
+ const catalogProperties = { date: this.date };
248
+ catalogProperties.package = (_a = conf.package) === null || _a === void 0 ? void 0 : _a.name;
249
+ catalogProperties.version = (_b = conf.package) === null || _b === void 0 ? void 0 : _b.version;
250
+ catalogProperties.msgidBugsAddress = (_c = conf.package) === null || _c === void 0 ? void 0 : _c['msgid-bugs-address'];
251
+ catalogProperties.copyrightHolder = (_d = conf.package) === null || _d === void 0 ? void 0 : _d['copyright-holder'];
252
+ if (typeof options.output === 'undefined' && ((_e = conf.package) === null || _e === void 0 ? void 0 : _e.textdomain)) {
253
+ if (typeof options.outputDir === 'undefined') {
254
+ options.output = conf.package.textdomain + '.pot';
255
+ }
256
+ else {
257
+ options.output = path.join(options.outputDir, conf.package.textdomain + '.pot');
258
+ }
259
+ }
260
+ if (typeof options.packageName !== 'undefined') {
261
+ catalogProperties.package = options.packageName;
262
+ }
263
+ if (typeof options.packageVersion !== 'undefined') {
264
+ catalogProperties.version = options.version;
265
+ }
266
+ if (typeof options.msgidBugsAddress !== 'undefined') {
267
+ catalogProperties.msgidBugsAddress = options.msgidBugsAddress;
268
+ }
269
+ this.catalog = new catalog_1.Catalog(catalogProperties);
270
+ if (typeof options.language !== 'undefined') {
271
+ const language = options.language.toLowerCase();
272
+ if (!['javascript', 'typescript'].includes(language)) {
273
+ throw new Error(gtx._x('language "{language}" unknown', {
274
+ language: this.options.language,
275
+ }));
276
+ }
277
+ this.options.language = language;
278
+ }
279
+ }
280
+ doRun() {
281
+ let exitCode = 0;
282
+ this.exclude = {};
283
+ if (this.options.excludeFile) {
284
+ try {
285
+ if (!this.fillExclusionCatalog(this.options.excludeFile)) {
286
+ return 1;
287
+ }
288
+ }
289
+ catch (e) {
290
+ const error = e;
291
+ console.error(gtx._x('{programName}: Error: {message}', {
292
+ programName: this.options.$0,
293
+ message: error.message,
294
+ }));
295
+ return 1;
296
+ }
297
+ }
298
+ if (this.options.joinExisting) {
299
+ if (this.options.output === '-') {
300
+ console.error(gtx._x('{programName}: Error: --join-existing' +
301
+ ' cannot be used, when output is written to stdout', {
302
+ programName: this.options.$0,
303
+ }));
304
+ return 1;
305
+ }
306
+ const parserOptions = this.getParserOptions();
307
+ const parser = new po_1.PoParser(this.catalog, parserOptions);
308
+ const filename = this.options.output;
309
+ try {
310
+ if (!parser.parse(this.readFile(filename), filename)) {
311
+ exitCode = 1;
312
+ }
313
+ }
314
+ catch (msg) {
315
+ console.error(`${filename}: ${msg}`);
316
+ exitCode = 1;
317
+ }
318
+ }
319
+ let fileCollector;
320
+ try {
321
+ fileCollector = new files_collector_1.FilesCollector(this.options.filesFrom, this.options._);
322
+ }
323
+ catch (e) {
324
+ console.error(`${this.options.$0}: ${e}`);
325
+ return 1;
326
+ }
327
+ // FIXME! The file collector must interpret all filenames relative to
328
+ // the files-from file's director.
329
+ fileCollector.filenames.forEach(filename => {
330
+ try {
331
+ if (!this.parse(this.readFile(filename), filename)) {
332
+ exitCode = 1;
333
+ }
334
+ }
335
+ catch (msg) {
336
+ if ('-' === filename) {
337
+ filename = gtx._('[standard input]');
338
+ }
339
+ console.error(`${filename}: ${msg}`);
340
+ exitCode = 1;
341
+ }
342
+ });
343
+ if (!exitCode) {
344
+ try {
345
+ this.output();
346
+ }
347
+ catch (exception) {
348
+ console.error(gtx._x('{programName}: {exception}', {
349
+ programName: this.options['$0'],
350
+ exception: exception,
351
+ }));
352
+ exitCode = 1;
353
+ }
354
+ }
355
+ return exitCode;
356
+ }
357
+ run(argv) {
358
+ this.init(argv);
359
+ return new Promise(resolve => {
360
+ try {
361
+ resolve(this.doRun());
362
+ }
363
+ catch (e) {
364
+ console.error(e);
365
+ resolve(1);
366
+ }
367
+ });
368
+ }
369
+ parse(code, filename) {
370
+ let parser;
371
+ const parserOptions = this.getParserOptions();
372
+ if (typeof this.options.language !== 'undefined') {
373
+ parser = this.getParserByLanguage(this.options.language, parserOptions);
374
+ }
375
+ else {
376
+ parser = this.getParserByFilename(filename, parserOptions);
377
+ }
378
+ return parser.parse(code, filename);
379
+ }
380
+ readFile(filename) {
381
+ if ('-' === filename) {
382
+ return process.stdin.read();
383
+ }
384
+ const directories = this.options.directory || [''];
385
+ // Avoid ugly absolute paths.
386
+ const resolve = (dir, file) => {
387
+ if (dir === '') {
388
+ return file;
389
+ }
390
+ else {
391
+ return dir + path.sep + file;
392
+ }
393
+ };
394
+ for (let i = 0; i < directories.length - 1; ++i) {
395
+ try {
396
+ const fullName = resolve(directories[i], filename);
397
+ return (0, fs_1.readFileSync)(fullName);
398
+ }
399
+ catch (e) {
400
+ /* ignore */
401
+ }
402
+ }
403
+ return (0, fs_1.readFileSync)(resolve(directories[directories.length - 1], filename));
404
+ }
405
+ getParserByFilename(filename, parserOptions) {
406
+ let parser;
407
+ const ext = path.extname(filename);
408
+ switch (ext.toLocaleLowerCase()) {
409
+ case '.ts':
410
+ case '.tsx':
411
+ parser = new typescript_1.TypeScriptParser(this.catalog, parserOptions);
412
+ break;
413
+ case '.js':
414
+ case '.jsx':
415
+ parser = new javascript_1.JavaScriptParser(this.catalog, parserOptions);
416
+ break;
417
+ case '.po':
418
+ case '.pot':
419
+ parser = new po_1.PoParser(this.catalog, parserOptions);
420
+ break;
421
+ default:
422
+ if ('-' === filename) {
423
+ this.warn(gtx._('language for standard input is unknown without' +
424
+ ' option "--language"; will try JavaScript'));
425
+ }
426
+ else {
427
+ this.warn(gtx._x('file "{filename}" extension "{extname}"' +
428
+ ' is unknown; will try JavaScript instead', {
429
+ filename,
430
+ extname: ext,
431
+ }));
432
+ }
433
+ parser = new javascript_1.JavaScriptParser(this.catalog, parserOptions);
434
+ break;
435
+ }
436
+ return parser;
437
+ }
438
+ getParserByLanguage(language, parserOptions) {
439
+ let parser;
440
+ switch (language.toLocaleLowerCase()) {
441
+ case 'typescript':
442
+ parser = new typescript_1.TypeScriptParser(this.catalog, parserOptions);
443
+ break;
444
+ case 'javascript':
445
+ default:
446
+ parser = new javascript_1.JavaScriptParser(this.catalog, parserOptions);
447
+ break;
448
+ }
449
+ return parser;
450
+ }
451
+ warn(msg) {
452
+ console.warn(gtx._x('{programName}: Warning: {msg}', {
453
+ msg,
454
+ programName: this.options.$0,
455
+ }));
456
+ }
457
+ output() {
458
+ Object.keys(this.exclude)
459
+ .filter(msgctxt => Object.prototype.hasOwnProperty.call(this.exclude, msgctxt))
460
+ .forEach(msgctxt => {
461
+ this.exclude[msgctxt].forEach(msgid => {
462
+ this.catalog.deleteEntry(msgid, msgctxt);
463
+ });
464
+ });
465
+ if (!this.options.forcePo) {
466
+ if (this.catalog.entries.length < 2) {
467
+ return;
468
+ }
469
+ }
470
+ const renderOptions = {};
471
+ if (typeof this.options.width !== 'undefined') {
472
+ renderOptions.width = this.options.width;
473
+ }
474
+ const po = this.catalog.toString(renderOptions);
475
+ if (this.options.output === '-') {
476
+ process.stdout.write(po);
477
+ return;
478
+ }
479
+ let filename;
480
+ if (typeof this.options.output === 'undefined') {
481
+ const domain = typeof this.options.defaultDomain === 'undefined'
482
+ ? 'messages'
483
+ : this.options.defaultDomain;
484
+ filename = `${domain}.po`;
485
+ }
486
+ else {
487
+ filename = this.options.output;
488
+ }
489
+ const outputDir = typeof this.options.outputDir === 'undefined'
490
+ ? ''
491
+ : this.options.outputDir;
492
+ (0, fs_1.writeFileSync)(path.join(outputDir, filename), po);
493
+ }
494
+ fillExclusionCatalog(catalogs) {
495
+ const catalog = new catalog_1.Catalog();
496
+ const parser = new po_1.PoParser(catalog);
497
+ let success = true;
498
+ catalogs.forEach(filename => {
499
+ if (!parser.parse(this.readFile(filename), filename)) {
500
+ success = false;
501
+ }
502
+ });
503
+ if (!success) {
504
+ return false;
505
+ }
506
+ catalog.deleteEntry('');
507
+ catalog.entries.forEach(entry => {
508
+ if (typeof this.exclude[entry.properties.msgctxt] === 'undefined') {
509
+ this.exclude[entry.properties.msgctxt] = [];
510
+ }
511
+ if (entry.properties.msgid) {
512
+ this.exclude[entry.properties.msgctxt].push(entry.properties.msgid);
513
+ }
514
+ });
515
+ return true;
516
+ }
517
+ getParserOptions() {
518
+ const parserOptions = (({ fromCode, addComments, addAllComments, extractAll, }) => ({
519
+ fromCode,
520
+ addComments,
521
+ addAllComments,
522
+ extractAll,
523
+ }))(this.options);
524
+ if (this.options.keyword) {
525
+ const cookedKeywords = new Array();
526
+ this.options.keyword.forEach(raw => {
527
+ cookedKeywords.push(keyword_1.Keyword.from(raw));
528
+ });
529
+ parserOptions.keyword = cookedKeywords;
530
+ }
531
+ return parserOptions;
532
+ }
533
+ }
534
+ exports.XGettext = XGettext;