@esgettext/tools 1.1.0 → 1.3.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 (91) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +1 -1
  3. package/dist/command.js +0 -1
  4. package/dist/commands/add-language.js +100 -0
  5. package/dist/commands/convert.js +17 -15
  6. package/dist/commands/init.js +743 -0
  7. package/dist/commands/install.js +21 -6
  8. package/dist/commands/msgfmt-all.js +72 -50
  9. package/dist/commands/msgmerge-all.js +71 -49
  10. package/dist/commands/potfiles.js +165 -0
  11. package/dist/commands/xgettext/file-resolver.js +0 -1
  12. package/dist/commands/xgettext/files-collector.js +1 -1
  13. package/dist/commands/xgettext.js +37 -17
  14. package/dist/configuration.js +174 -115
  15. package/dist/esgettext-package-json.js +0 -1
  16. package/dist/index.js +97 -29
  17. package/dist/optspec.js +28 -0
  18. package/dist/package.js +4 -2
  19. package/dist/parser/javascript.js +2 -1
  20. package/dist/parser/parser.js +17 -2
  21. package/dist/parser/po.js +34 -1
  22. package/dist/parser/typescript.js +2 -1
  23. package/dist/pot/catalog.js +36 -1
  24. package/dist/pot/entry.js +71 -1
  25. package/dist/pot/keyword.js +10 -5
  26. package/package.json +11 -6
  27. package/dist/command.d.ts +0 -11
  28. package/dist/command.js.map +0 -1
  29. package/dist/commands/convert.d.ts +0 -24
  30. package/dist/commands/convert.js.map +0 -1
  31. package/dist/commands/install.d.ts +0 -22
  32. package/dist/commands/install.js.map +0 -1
  33. package/dist/commands/msgfmt-all.d.ts +0 -20
  34. package/dist/commands/msgfmt-all.js.map +0 -1
  35. package/dist/commands/msgmerge-all.d.ts +0 -21
  36. package/dist/commands/msgmerge-all.js.map +0 -1
  37. package/dist/commands/xgettext/file-resolver.d.ts +0 -5
  38. package/dist/commands/xgettext/file-resolver.js.map +0 -1
  39. package/dist/commands/xgettext/file-resolver.spec.d.ts +0 -1
  40. package/dist/commands/xgettext/file-resolver.spec.js +0 -22
  41. package/dist/commands/xgettext/file-resolver.spec.js.map +0 -1
  42. package/dist/commands/xgettext/files-collector.d.ts +0 -5
  43. package/dist/commands/xgettext/files-collector.js.map +0 -1
  44. package/dist/commands/xgettext/files-collector.spec.d.ts +0 -1
  45. package/dist/commands/xgettext/files-collector.spec.js +0 -96
  46. package/dist/commands/xgettext/files-collector.spec.js.map +0 -1
  47. package/dist/commands/xgettext.d.ts +0 -29
  48. package/dist/commands/xgettext.js.map +0 -1
  49. package/dist/commands/xgettext.spec.d.ts +0 -1
  50. package/dist/commands/xgettext.spec.js +0 -897
  51. package/dist/commands/xgettext.spec.js.map +0 -1
  52. package/dist/configuration.d.ts +0 -36
  53. package/dist/configuration.js.map +0 -1
  54. package/dist/esgettext-package-json.d.ts +0 -15
  55. package/dist/esgettext-package-json.js.map +0 -1
  56. package/dist/index.d.ts +0 -2
  57. package/dist/index.js.map +0 -1
  58. package/dist/package.d.ts +0 -5
  59. package/dist/package.js.map +0 -1
  60. package/dist/parser/javascript.d.ts +0 -4
  61. package/dist/parser/javascript.js.map +0 -1
  62. package/dist/parser/javascript.spec.d.ts +0 -1
  63. package/dist/parser/javascript.spec.js +0 -535
  64. package/dist/parser/javascript.spec.js.map +0 -1
  65. package/dist/parser/parser.d.ts +0 -45
  66. package/dist/parser/parser.js.map +0 -1
  67. package/dist/parser/po.d.ts +0 -22
  68. package/dist/parser/po.js.map +0 -1
  69. package/dist/parser/po.spec.d.ts +0 -1
  70. package/dist/parser/po.spec.js +0 -486
  71. package/dist/parser/po.spec.js.map +0 -1
  72. package/dist/parser/typescript.d.ts +0 -4
  73. package/dist/parser/typescript.js.map +0 -1
  74. package/dist/parser/typescript.spec.d.ts +0 -1
  75. package/dist/parser/typescript.spec.js +0 -121
  76. package/dist/parser/typescript.spec.js.map +0 -1
  77. package/dist/pot/catalog.d.ts +0 -26
  78. package/dist/pot/catalog.js.map +0 -1
  79. package/dist/pot/catalog.spec.d.ts +0 -1
  80. package/dist/pot/catalog.spec.js +0 -244
  81. package/dist/pot/catalog.spec.js.map +0 -1
  82. package/dist/pot/entry.d.ts +0 -35
  83. package/dist/pot/entry.js.map +0 -1
  84. package/dist/pot/entry.spec.d.ts +0 -1
  85. package/dist/pot/entry.spec.js +0 -433
  86. package/dist/pot/entry.spec.js.map +0 -1
  87. package/dist/pot/keyword.d.ts +0 -17
  88. package/dist/pot/keyword.js.map +0 -1
  89. package/dist/pot/keyword.spec.d.ts +0 -1
  90. package/dist/pot/keyword.spec.js +0 -54
  91. package/dist/pot/keyword.spec.js.map +0 -1
package/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- This software is Copyright (C) 2020 by Guido Flohr.
1
+ This software is Copyright (C) 2020-2024 by Guido Flohr.
2
2
 
3
3
  This is free software, licensed under:
4
4
 
package/README.md CHANGED
@@ -294,7 +294,7 @@ for example `['verbose']` or `['v']`, and not `['--verbose']` or `['-v']`.
294
294
 
295
295
  ## Copyright
296
296
 
297
- Copyright (C) 2020 Guido Flohr <guido.flohr@cantanea.com>, all
297
+ Copyright (C) 2020-2024 Guido Flohr <guido.flohr@cantanea.com>, all
298
298
  rights reserved.
299
299
 
300
300
  This software is available under the terms and conditions of the
package/dist/command.js CHANGED
@@ -1,3 +1,2 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- //# sourceMappingURL=command.js.map
@@ -0,0 +1,100 @@
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.AddLanguage = void 0;
27
+ const path = __importStar(require("path"));
28
+ const runtime_1 = require("@esgettext/runtime");
29
+ const gtx = runtime_1.Textdomain.getInstance('com.cantanea.esgettext-tools');
30
+ class AddLanguage {
31
+ constructor(configuration) {
32
+ this.options = undefined;
33
+ this.configuration = configuration;
34
+ }
35
+ synopsis() {
36
+ return '';
37
+ }
38
+ description() {
39
+ return gtx._('Describe process for adding languages.');
40
+ }
41
+ aliases() {
42
+ return [];
43
+ }
44
+ args() {
45
+ var _a, _b;
46
+ return {
47
+ textdomain: {
48
+ alias: 't',
49
+ type: 'string',
50
+ describe: gtx._('The textdomain of your package'),
51
+ demandOption: true,
52
+ default: (_a = this.configuration.package) === null || _a === void 0 ? void 0 : _a.textdomain,
53
+ },
54
+ 'po-directory': {
55
+ type: 'string',
56
+ describe: gtx._('Directory where your po files are located'),
57
+ demandOption: true,
58
+ default: (_b = this.configuration.po) === null || _b === void 0 ? void 0 : _b.directory,
59
+ },
60
+ };
61
+ }
62
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
63
+ additional(_) { }
64
+ init(argv) {
65
+ const options = argv;
66
+ this.options = options;
67
+ }
68
+ run(argv) {
69
+ return new Promise(resolve => {
70
+ var _a;
71
+ this.init(argv);
72
+ const potFile = `${this.options.poDirectory}/${this.options.textdomain}.pot`.replace(/\//g, path.sep);
73
+ console.log(gtx._('Please execute this command:\n'));
74
+ // TRANSLATORS: Please replace 'll' with a two-letter abbreviation
75
+ // for the word 'language' and 'CC' with a two-letter abbreviation
76
+ // for the workd 'country'.
77
+ const llCC = gtx._('ll_CC');
78
+ console.log(`\tmsginit --input=${potFile} --locale=${llCC}\n`);
79
+ console.log(gtx._x("Replace '{placeholder}' with the two-letter" +
80
+ ' language code of the language, optionally' +
81
+ ' followed by an underscore and the two-letter' +
82
+ ' country code.', { placeholder: llCC }));
83
+ console.log(gtx._('If you prefer to separate language and country' +
84
+ ' by a hyphen, rename the file later.'));
85
+ console.log(gtx._x('When you are done, update the list of locales' +
86
+ " in the configuration file '{filename}'. The" +
87
+ " variable name is '{varname}'.", {
88
+ filename: (_a = this.configuration.files) === null || _a === void 0 ? void 0 : _a[0],
89
+ varname: 'po.locales',
90
+ }));
91
+ const redOn = '\x1b[31m';
92
+ const redOff = '\x1b[0m';
93
+ console.log(redOn, gtx._('Warning! The command will open an' +
94
+ ' internet connection to download the plural' +
95
+ ' function and some other data for that language!'), redOff);
96
+ resolve(0);
97
+ });
98
+ }
99
+ }
100
+ exports.AddLanguage = AddLanguage;
@@ -29,8 +29,9 @@ const runtime_1 = require("@esgettext/runtime");
29
29
  const package_1 = require("../package");
30
30
  const gtx = runtime_1.Textdomain.getInstance('com.cantanea.esgettext-tools');
31
31
  class Convert {
32
- constructor(configuration) {
33
- this.configuration = configuration;
32
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
33
+ constructor(_) {
34
+ this.options = undefined;
34
35
  }
35
36
  synopsis() {
36
37
  return `[${gtx._('INPUTFILE')}] [${gtx._('OUTPUTFILE')}]`;
@@ -58,7 +59,7 @@ class Convert {
58
59
  'input-format': {
59
60
  alias: 'I',
60
61
  type: 'string',
61
- describe: gtx._('Input file format (defaul: derived from filename)'),
62
+ describe: gtx._('Input file format (default: derived from filename)'),
62
63
  choices: ['mo.json', 'mo', 'gmo', 'json'],
63
64
  coerce: arg => arg.toLowerCase(),
64
65
  group: gtx._('File formats:'),
@@ -195,6 +196,7 @@ class Convert {
195
196
  if (typeof filename !== 'undefined') {
196
197
  return fs.readFileSync(filename);
197
198
  }
199
+ // Must read from standard input.
198
200
  const stdinFd = 0;
199
201
  const chunks = [];
200
202
  let bytesRead;
@@ -238,16 +240,16 @@ class Convert {
238
240
  }
239
241
  shortenAndEscapeString(input, maxLength) {
240
242
  const controlCharMap = {
241
- '\0': '\\0',
242
- '\b': '\\b',
243
- '\t': '\\t',
244
- '\n': '\\n',
245
- '\v': '\\v',
246
- '\f': '\\f',
247
- '\r': '\\r',
248
- '"': '\\"',
249
- "'": "\\'",
250
- '\\': '\\\\',
243
+ '\0': '\\0', // Null character
244
+ '\b': '\\b', // Backspace
245
+ '\t': '\\t', // Horizontal Tab
246
+ '\n': '\\n', // New Line
247
+ '\v': '\\v', // Vertical Tab
248
+ '\f': '\\f', // Form Feed
249
+ '\r': '\\r', // Carriage Return
250
+ '"': '\\"', // Double quote
251
+ "'": "\\'", // Single quote
252
+ '\\': '\\\\', // Backslash
251
253
  };
252
254
  const escapeControlChar = (char) => {
253
255
  if (controlCharMap[char]) {
@@ -257,8 +259,9 @@ class Convert {
257
259
  if (code < 32) {
258
260
  return `\\x${code.toString(16).padStart(2, '0')}`;
259
261
  }
260
- return char;
262
+ return char; // This line is technically redundant with the current regex.
261
263
  };
264
+ // Escape all control characters
262
265
  const escapedInput = input.replace(/[\x00-\x1F"'\\]/g, escapeControlChar);
263
266
  let truncatedString = escapedInput;
264
267
  if (escapedInput.length > maxLength) {
@@ -281,4 +284,3 @@ class Convert {
281
284
  }
282
285
  }
283
286
  exports.Convert = Convert;
284
- //# sourceMappingURL=convert.js.map