@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
package/dist/pot/catalog.js
CHANGED
|
@@ -1,21 +1,22 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Catalog = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
const entry_1 = require("./entry");
|
|
5
|
+
/**
|
|
6
|
+
* An entire message catalog that is subsequently filled.
|
|
7
|
+
*/
|
|
8
|
+
class Catalog {
|
|
9
|
+
constructor(properties = {}) {
|
|
8
10
|
this.properties = properties;
|
|
9
11
|
this.cache = {};
|
|
10
12
|
this.entries = new Array();
|
|
11
|
-
|
|
13
|
+
let barePkg;
|
|
12
14
|
if (typeof properties.package === 'undefined') {
|
|
13
15
|
barePkg = 'PACKAGE';
|
|
14
16
|
properties.package = 'PACKAGE VERSION';
|
|
15
17
|
}
|
|
16
18
|
else {
|
|
17
19
|
barePkg = properties.package.replace(/\n/g, '\\n');
|
|
18
|
-
;
|
|
19
20
|
if (typeof properties.version !== 'undefined') {
|
|
20
21
|
properties.package += ' ' + properties.version;
|
|
21
22
|
}
|
|
@@ -27,41 +28,60 @@ var Catalog = (function () {
|
|
|
27
28
|
properties.msgidBugsAddress = 'MSGID_BUGS_ADDRESS';
|
|
28
29
|
}
|
|
29
30
|
if (typeof properties.date === 'undefined') {
|
|
30
|
-
|
|
31
|
-
|
|
31
|
+
const now = new Date();
|
|
32
|
+
// Avoid if/else, so we do not spoil our test coverage. :)
|
|
33
|
+
let year = now.getFullYear().toString();
|
|
32
34
|
year = '0'.repeat(4 - year.length) + year;
|
|
33
|
-
|
|
35
|
+
let month = (1 + now.getMonth()).toString();
|
|
34
36
|
month = '0'.repeat(2 - month.length) + month;
|
|
35
|
-
|
|
37
|
+
let mday = now.getDate().toString();
|
|
36
38
|
mday = '0'.repeat(2 - mday.length) + mday;
|
|
37
|
-
|
|
39
|
+
let hour = now.getHours().toString();
|
|
38
40
|
hour = '0'.repeat(2 - hour.length) + hour;
|
|
39
|
-
|
|
41
|
+
let minutes = now.getMinutes().toString();
|
|
40
42
|
minutes = '0'.repeat(2 - minutes.length) + minutes;
|
|
41
|
-
|
|
42
|
-
|
|
43
|
+
// Do not depend on the timezone for test coverage.
|
|
44
|
+
let offset = now.getTimezoneOffset();
|
|
45
|
+
const sign = ['+', '-'][Math.sign(offset) + 1];
|
|
43
46
|
offset = Math.abs(offset);
|
|
44
|
-
|
|
47
|
+
let offsetHours = Math.floor(offset / 60).toString();
|
|
45
48
|
offsetHours = '0'.repeat(2 - offsetHours.length) + offsetHours;
|
|
46
|
-
|
|
49
|
+
let offsetMinutes = (offset % 60).toString();
|
|
47
50
|
offsetMinutes = '0'.repeat(2 - offsetMinutes.length) + offsetMinutes;
|
|
48
51
|
properties.date =
|
|
49
52
|
[year, month, mday].join('-') +
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
53
|
+
` ${hour}:${minutes}` +
|
|
54
|
+
`${sign}${offsetHours}${offsetMinutes}`;
|
|
55
|
+
}
|
|
56
|
+
const pkg = properties.package.replace(/\n/g, '\\n');
|
|
57
|
+
const msgidBugsAddress = properties.msgidBugsAddress.replace(/\n/g, '\\n');
|
|
58
|
+
const copyrightHolder = properties.copyrightHolder.replace(/\n/g, '\\n');
|
|
59
|
+
const header = `Project-Id-Version: ${pkg}
|
|
60
|
+
Report-Msgid-Bugs-To: ${msgidBugsAddress}
|
|
61
|
+
POT-Creation-Date: ${properties.date}
|
|
62
|
+
PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE
|
|
63
|
+
Last-Translator: FULL NAME <EMAIL@ADDRESS>
|
|
64
|
+
Language-Team: LANGUAGE <LL@li.org>
|
|
65
|
+
Language:\u0020
|
|
66
|
+
MIME-Version: 1.0
|
|
67
|
+
Content-Type: text/plain; charset=CHARSET
|
|
68
|
+
Content-Transfer-Encoding: 8bit
|
|
69
|
+
`;
|
|
70
|
+
let comment;
|
|
58
71
|
if (properties.foreignUser) {
|
|
59
|
-
comment =
|
|
72
|
+
comment = `SOME DESCRIPTIVE TITLE
|
|
73
|
+
This file is put in the public domain.
|
|
74
|
+
FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
|
|
75
|
+
`;
|
|
60
76
|
}
|
|
61
77
|
else {
|
|
62
|
-
comment =
|
|
78
|
+
comment = `SOME DESCRIPTIVE TITLE
|
|
79
|
+
Copyright (C) YEAR ${copyrightHolder}
|
|
80
|
+
This file is distributed under the same license as the ${barePkg} package.
|
|
81
|
+
FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
|
|
82
|
+
`;
|
|
63
83
|
}
|
|
64
|
-
|
|
84
|
+
const headerEntry = new entry_1.POTEntry({
|
|
65
85
|
msgid: '',
|
|
66
86
|
msgstr: header,
|
|
67
87
|
flags: ['fuzzy'],
|
|
@@ -70,33 +90,46 @@ var Catalog = (function () {
|
|
|
70
90
|
});
|
|
71
91
|
this.addEntry(headerEntry);
|
|
72
92
|
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
93
|
+
/**
|
|
94
|
+
* Render the entire catalog.
|
|
95
|
+
*
|
|
96
|
+
* @param renderOptions - options for rendering
|
|
97
|
+
*
|
|
98
|
+
* The following options are supported:
|
|
99
|
+
*
|
|
100
|
+
* width: wrap lines to that page width (default: 76)
|
|
101
|
+
*
|
|
102
|
+
* @returns the catalog rendered as a po(t) file
|
|
103
|
+
*/
|
|
104
|
+
toString(options = {}) {
|
|
105
|
+
const width = options && typeof options.width !== 'undefined' ? options.width : 76;
|
|
106
|
+
const isNotHeader = (entry) => {
|
|
77
107
|
return !(entry.properties.msgid === '' &&
|
|
78
108
|
typeof entry.properties.msgctxt === 'undefined');
|
|
79
109
|
};
|
|
80
|
-
|
|
110
|
+
const isHeader = (entry) => {
|
|
81
111
|
return !isNotHeader(entry);
|
|
82
112
|
};
|
|
83
|
-
|
|
113
|
+
const header = options.omitHeader
|
|
84
114
|
? undefined
|
|
85
115
|
: this.entries
|
|
86
116
|
.filter(isHeader)
|
|
87
|
-
.map(
|
|
117
|
+
.map(entry => entry.toString(width))
|
|
88
118
|
.join('\n');
|
|
89
|
-
|
|
119
|
+
let body = '';
|
|
90
120
|
if (options.sortOutput) {
|
|
91
121
|
body = this.entries
|
|
92
122
|
.filter(isNotHeader)
|
|
93
|
-
.sort(
|
|
94
|
-
|
|
123
|
+
.sort((a, b) => {
|
|
124
|
+
const cmp = a.properties.msgid.localeCompare(b.properties.msgid);
|
|
95
125
|
if (cmp) {
|
|
96
126
|
return cmp;
|
|
97
127
|
}
|
|
98
|
-
|
|
99
|
-
|
|
128
|
+
const actx = a.properties.msgctxt;
|
|
129
|
+
const bctx = b.properties.msgctxt;
|
|
130
|
+
// It is impossible that both msgctxts are undefined
|
|
131
|
+
// because that would mean that the msgids are identical
|
|
132
|
+
// which is prevented.
|
|
100
133
|
if (typeof bctx === 'undefined') {
|
|
101
134
|
return +1;
|
|
102
135
|
}
|
|
@@ -105,34 +138,35 @@ var Catalog = (function () {
|
|
|
105
138
|
}
|
|
106
139
|
return actx.localeCompare(bctx);
|
|
107
140
|
})
|
|
108
|
-
.map(
|
|
141
|
+
.map(entry => entry.toString(width))
|
|
109
142
|
.join('\n');
|
|
110
143
|
}
|
|
111
144
|
else if (options.sortByFile) {
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
return { filename
|
|
145
|
+
const copy = this.copy(this.properties);
|
|
146
|
+
const splitRef = (ref) => {
|
|
147
|
+
const parts = ref.split(':');
|
|
148
|
+
const lineno = Number.parseInt(parts.pop(), 10);
|
|
149
|
+
const filename = parts.join(':');
|
|
150
|
+
return { filename, lineno };
|
|
118
151
|
};
|
|
119
|
-
|
|
152
|
+
// First order all references
|
|
153
|
+
copy.entries.forEach(entry => {
|
|
120
154
|
if (entry.properties.references) {
|
|
121
155
|
entry.properties.references = entry.properties.references
|
|
122
|
-
.map(
|
|
123
|
-
.sort(
|
|
156
|
+
.map(splitRef)
|
|
157
|
+
.sort((a, b) => {
|
|
124
158
|
return (a.filename.localeCompare(b.filename) ||
|
|
125
159
|
Math.sign(a.lineno - b.lineno));
|
|
126
160
|
})
|
|
127
|
-
.map(
|
|
161
|
+
.map(ref => `${ref.filename}:${ref.lineno}`);
|
|
128
162
|
}
|
|
129
163
|
});
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
for (
|
|
135
|
-
|
|
164
|
+
const compareSplitRefs = (a, b) => {
|
|
165
|
+
const arefs = a.refs;
|
|
166
|
+
const brefs = b.refs;
|
|
167
|
+
const min = Math.min(arefs.length, brefs.length);
|
|
168
|
+
for (let i = 0; i < min; ++i) {
|
|
169
|
+
const cmp = arefs[i].filename.localeCompare(brefs[i].filename) ||
|
|
136
170
|
Math.sign(arefs[i].lineno - brefs[i].lineno);
|
|
137
171
|
if (cmp) {
|
|
138
172
|
return cmp;
|
|
@@ -140,35 +174,45 @@ var Catalog = (function () {
|
|
|
140
174
|
}
|
|
141
175
|
return Math.sign(arefs.length - brefs.length);
|
|
142
176
|
};
|
|
143
|
-
|
|
144
|
-
return refs ? refs.map(
|
|
177
|
+
const splitRefs = (refs) => {
|
|
178
|
+
return refs ? refs.map(splitRef) : [];
|
|
145
179
|
};
|
|
146
180
|
body = copy.entries
|
|
147
181
|
.filter(isNotHeader)
|
|
148
|
-
.map(
|
|
149
|
-
return {
|
|
182
|
+
.map(entry => {
|
|
183
|
+
return {
|
|
184
|
+
refs: splitRefs(entry.properties.references),
|
|
185
|
+
entry,
|
|
186
|
+
};
|
|
150
187
|
})
|
|
151
188
|
.sort(compareSplitRefs)
|
|
152
|
-
.map(
|
|
153
|
-
.map(
|
|
189
|
+
.map(split => split.entry)
|
|
190
|
+
.map(entry => entry.toString(width))
|
|
154
191
|
.join('\n');
|
|
155
192
|
}
|
|
156
193
|
else {
|
|
157
194
|
body = this.entries
|
|
158
195
|
.filter(isNotHeader)
|
|
159
|
-
.map(
|
|
196
|
+
.map(entry => entry.toString(width))
|
|
160
197
|
.join('\n');
|
|
161
198
|
}
|
|
162
199
|
if (body && header) {
|
|
163
|
-
return
|
|
200
|
+
return `${header}\n${body}`;
|
|
164
201
|
}
|
|
165
202
|
else {
|
|
166
203
|
return header || body || '';
|
|
167
204
|
}
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Add an entry to the catalog. If an entry with the same msgid
|
|
208
|
+
* and msgctxt already exists, the entry is merged into
|
|
209
|
+
* the existing one instead.
|
|
210
|
+
*
|
|
211
|
+
* @param entry - the `POTEntry` to add
|
|
212
|
+
*/
|
|
213
|
+
addEntry(entry) {
|
|
214
|
+
const msgid = entry.properties.msgid;
|
|
215
|
+
const msgctxt = entry.properties.msgctxt;
|
|
172
216
|
if (!Object.prototype.hasOwnProperty.call(this.cache, msgid)) {
|
|
173
217
|
this.cache[msgid] = {};
|
|
174
218
|
}
|
|
@@ -179,32 +223,39 @@ var Catalog = (function () {
|
|
|
179
223
|
else {
|
|
180
224
|
this.cache[msgid][msgctxt].merge(entry);
|
|
181
225
|
}
|
|
182
|
-
}
|
|
183
|
-
|
|
226
|
+
}
|
|
227
|
+
deleteEntry(msgid, msgctxt) {
|
|
184
228
|
if (!this.cache[msgid]) {
|
|
185
229
|
return;
|
|
186
230
|
}
|
|
187
|
-
|
|
231
|
+
const entry = this.cache[msgid][msgctxt];
|
|
188
232
|
if (!entry) {
|
|
189
233
|
return;
|
|
190
234
|
}
|
|
191
235
|
delete this.cache[msgid][msgctxt];
|
|
192
|
-
this.entries = this.entries.filter(
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
236
|
+
this.entries = this.entries.filter(other => other !== entry);
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
239
|
+
* Copy a catalog with other options. This is for testing only.
|
|
240
|
+
*
|
|
241
|
+
* @returns a deep copy of the catalog.
|
|
242
|
+
*/
|
|
243
|
+
copy(properties) {
|
|
244
|
+
const other = new Catalog(properties);
|
|
245
|
+
this.entries.forEach(entry => other.addEntry(entry));
|
|
197
246
|
return other;
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
|
|
247
|
+
}
|
|
248
|
+
/**
|
|
249
|
+
* Removes all translations from a catalog, so that it can be used as
|
|
250
|
+
* a .pot file.
|
|
251
|
+
*/
|
|
252
|
+
makePOT() {
|
|
253
|
+
this.entries.forEach(entry => {
|
|
201
254
|
if (!(entry.properties.msgid === '' &&
|
|
202
255
|
typeof entry.properties.msgctxt === 'undefined')) {
|
|
203
256
|
delete entry.properties.msgstr;
|
|
204
257
|
}
|
|
205
258
|
});
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
}());
|
|
259
|
+
}
|
|
260
|
+
}
|
|
209
261
|
exports.Catalog = Catalog;
|
|
210
|
-
//# sourceMappingURL=catalog.js.map
|