@esgettext/runtime 1.0.0 → 1.1.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/README.md +6 -6
- package/{lib-esm → dist}/core/browser-environment.d.ts +1 -0
- package/dist/core/browser-environment.d.ts.map +1 -0
- package/{lib-esm → dist}/core/catalog-cache.d.ts +1 -0
- package/dist/core/catalog-cache.d.ts.map +1 -0
- package/dist/core/catalog-cache.spec.d.ts +2 -0
- package/dist/core/catalog-cache.spec.d.ts.map +1 -0
- package/dist/core/catalog-format.spec.d.ts +2 -0
- package/dist/core/catalog-format.spec.d.ts.map +1 -0
- package/{lib → dist}/core/catalog.d.ts +1 -0
- package/dist/core/catalog.d.ts.map +1 -0
- package/{lib → dist}/core/data-viewlet.d.ts +1 -0
- package/dist/core/data-viewlet.d.ts.map +1 -0
- package/dist/core/data-viewlet.spec.d.ts +2 -0
- package/dist/core/data-viewlet.spec.d.ts.map +1 -0
- package/{lib-esm → dist}/core/explode-locale.d.ts +1 -0
- package/dist/core/explode-locale.d.ts.map +1 -0
- package/dist/core/explode-locale.spec.d.ts +2 -0
- package/dist/core/explode-locale.spec.d.ts.map +1 -0
- package/{lib-esm → dist}/core/germanic-plural.d.ts +1 -0
- package/dist/core/germanic-plural.d.ts.map +1 -0
- package/{lib → dist}/core/gettext-impl.d.ts +1 -0
- package/dist/core/gettext-impl.d.ts.map +1 -0
- package/dist/core/gettext.spec.d.ts +2 -0
- package/dist/core/gettext.spec.d.ts.map +1 -0
- package/{lib-esm → dist}/core/index.d.ts +1 -0
- package/dist/core/index.d.ts.map +1 -0
- package/{lib → dist}/core/locale-container.d.ts +1 -0
- package/dist/core/locale-container.d.ts.map +1 -0
- package/dist/core/platform.d.ts +3 -0
- package/dist/core/platform.d.ts.map +1 -0
- package/{lib → dist}/core/resolve-impl.d.ts +1 -0
- package/dist/core/resolve-impl.d.ts.map +1 -0
- package/dist/core/resolve.spec.d.ts +2 -0
- package/dist/core/resolve.spec.d.ts.map +1 -0
- package/{lib-esm → dist}/core/select-locale.d.ts +1 -0
- package/dist/core/select-locale.d.ts.map +1 -0
- package/dist/core/select-locale.spec.d.ts +2 -0
- package/dist/core/select-locale.spec.d.ts.map +1 -0
- package/dist/core/set-locale-browser.spec.d.ts +2 -0
- package/dist/core/set-locale-browser.spec.d.ts.map +1 -0
- package/dist/core/set-locale-node.spec.d.ts +2 -0
- package/dist/core/set-locale-node.spec.d.ts.map +1 -0
- package/{lib-esm → dist}/core/split-locale.d.ts +1 -0
- package/dist/core/split-locale.d.ts.map +1 -0
- package/dist/core/split-locale.spec.d.ts +2 -0
- package/dist/core/split-locale.spec.d.ts.map +1 -0
- package/{lib → dist}/core/textdomain.d.ts +18 -17
- package/dist/core/textdomain.d.ts.map +1 -0
- package/dist/core/textdomain.spec.d.ts +2 -0
- package/dist/core/textdomain.spec.d.ts.map +1 -0
- package/{lib-esm → dist}/core/user-locales.d.ts +1 -0
- package/dist/core/user-locales.d.ts.map +1 -0
- package/dist/esgettext.cjs.js +868 -0
- package/dist/esgettext.cjs.js.map +1 -0
- package/dist/esgettext.esm.js +863 -0
- package/dist/esgettext.esm.js.map +1 -0
- package/dist/esgettext.min.js +2 -0
- package/dist/esgettext.min.js.map +1 -0
- package/dist/index-browser.d.ts +3 -0
- package/dist/index-browser.d.ts.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/parser/index.d.ts +4 -0
- package/dist/parser/index.d.ts.map +1 -0
- package/{lib-esm → dist}/parser/parse-json-catalog.d.ts +1 -0
- package/dist/parser/parse-json-catalog.d.ts.map +1 -0
- package/{lib-esm → dist}/parser/parse-mo-catalog.d.ts +1 -0
- package/dist/parser/parse-mo-catalog.d.ts.map +1 -0
- package/dist/parser/parse-mo-catalog.spec.d.ts +2 -0
- package/dist/parser/parse-mo-catalog.spec.d.ts.map +1 -0
- package/dist/parser/parse-mo-json-catalog.d.ts +4 -0
- package/dist/parser/parse-mo-json-catalog.d.ts.map +1 -0
- package/dist/parser/parse-mo-json-catalog.spec.d.ts +2 -0
- package/dist/parser/parse-mo-json-catalog.spec.d.ts.map +1 -0
- package/{lib/transport/fs.d.ts → dist/transport/fs-browser.d.ts} +2 -1
- package/dist/transport/fs-browser.d.ts.map +1 -0
- package/{lib-esm → dist}/transport/fs.d.ts +1 -0
- package/dist/transport/fs.d.ts.map +1 -0
- package/{lib-esm → dist}/transport/http.d.ts +1 -0
- package/dist/transport/http.d.ts.map +1 -0
- package/dist/transport/http.spec.d.ts +2 -0
- package/dist/transport/http.spec.d.ts.map +1 -0
- package/{lib → dist}/transport/index.d.ts +2 -1
- package/dist/transport/index.d.ts.map +1 -0
- package/{lib → dist}/transport/transport.interface.d.ts +1 -0
- package/dist/transport/transport.interface.d.ts.map +1 -0
- package/package.json +30 -14
- package/_bundles/runtime.js +0 -1356
- package/_bundles/runtime.js.map +0 -1
- package/_bundles/runtime.min.js +0 -2
- package/_bundles/runtime.min.js.map +0 -1
- package/api-docs/assets/highlight.css +0 -127
- package/api-docs/assets/main.js +0 -59
- package/api-docs/assets/navigation.js +0 -1
- package/api-docs/assets/search.js +0 -1
- package/api-docs/assets/style.css +0 -1414
- package/api-docs/classes/Textdomain.html +0 -364
- package/api-docs/index.html +0 -222
- package/api-docs/interfaces/Catalog.html +0 -20
- package/api-docs/interfaces/CatalogEntries.html +0 -11
- package/api-docs/interfaces/LocaleContainer.html +0 -19
- package/api-docs/interfaces/Placeholders.html +0 -9
- package/api-docs/modules.html +0 -6
- package/lib/core/browser-environment.d.ts +0 -1
- package/lib/core/browser-environment.js +0 -12
- package/lib/core/browser-environment.js.map +0 -1
- package/lib/core/catalog-cache.d.ts +0 -10
- package/lib/core/catalog-cache.js +0 -39
- package/lib/core/catalog-cache.js.map +0 -1
- package/lib/core/catalog-cache.spec.d.ts +0 -1
- package/lib/core/catalog-cache.spec.js +0 -24
- package/lib/core/catalog-cache.spec.js.map +0 -1
- package/lib/core/catalog-format.spec.d.ts +0 -1
- package/lib/core/catalog-format.spec.js +0 -35
- package/lib/core/catalog-format.spec.js.map +0 -1
- package/lib/core/catalog.js +0 -3
- package/lib/core/catalog.js.map +0 -1
- package/lib/core/data-viewlet.js +0 -57
- package/lib/core/data-viewlet.js.map +0 -1
- package/lib/core/data-viewlet.spec.d.ts +0 -1
- package/lib/core/data-viewlet.spec.js +0 -62
- package/lib/core/data-viewlet.spec.js.map +0 -1
- package/lib/core/explode-locale.d.ts +0 -3
- package/lib/core/explode-locale.js +0 -37
- package/lib/core/explode-locale.js.map +0 -1
- package/lib/core/explode-locale.spec.d.ts +0 -1
- package/lib/core/explode-locale.spec.js +0 -41
- package/lib/core/explode-locale.spec.js.map +0 -1
- package/lib/core/germanic-plural.d.ts +0 -1
- package/lib/core/germanic-plural.js +0 -8
- package/lib/core/germanic-plural.js.map +0 -1
- package/lib/core/gettext-impl.js +0 -38
- package/lib/core/gettext-impl.js.map +0 -1
- package/lib/core/gettext.spec.d.ts +0 -1
- package/lib/core/gettext.spec.js +0 -391
- package/lib/core/gettext.spec.js.map +0 -1
- package/lib/core/index.d.ts +0 -4
- package/lib/core/index.js +0 -21
- package/lib/core/index.js.map +0 -1
- package/lib/core/locale-container.js +0 -3
- package/lib/core/locale-container.js.map +0 -1
- package/lib/core/path-separator.d.ts +0 -1
- package/lib/core/path-separator.js +0 -12
- package/lib/core/path-separator.js.map +0 -1
- package/lib/core/resolve-impl.js +0 -253
- package/lib/core/resolve-impl.js.map +0 -1
- package/lib/core/resolve.spec.d.ts +0 -1
- package/lib/core/resolve.spec.js +0 -345
- package/lib/core/resolve.spec.js.map +0 -1
- package/lib/core/select-locale.d.ts +0 -1
- package/lib/core/select-locale.js +0 -43
- package/lib/core/select-locale.js.map +0 -1
- package/lib/core/select-locale.spec.d.ts +0 -1
- package/lib/core/select-locale.spec.js +0 -27
- package/lib/core/select-locale.spec.js.map +0 -1
- package/lib/core/set-locale-browser.spec.d.ts +0 -1
- package/lib/core/set-locale-browser.spec.js +0 -17
- package/lib/core/set-locale-browser.spec.js.map +0 -1
- package/lib/core/set-locale-node.spec.d.ts +0 -1
- package/lib/core/set-locale-node.spec.js +0 -26
- package/lib/core/set-locale-node.spec.js.map +0 -1
- package/lib/core/split-locale.d.ts +0 -7
- package/lib/core/split-locale.js +0 -39
- package/lib/core/split-locale.js.map +0 -1
- package/lib/core/split-locale.spec.d.ts +0 -1
- package/lib/core/split-locale.spec.js +0 -59
- package/lib/core/split-locale.spec.js.map +0 -1
- package/lib/core/textdomain.js +0 -277
- package/lib/core/textdomain.js.map +0 -1
- package/lib/core/textdomain.spec.d.ts +0 -1
- package/lib/core/textdomain.spec.js +0 -33
- package/lib/core/textdomain.spec.js.map +0 -1
- package/lib/core/user-locales.d.ts +0 -1
- package/lib/core/user-locales.js +0 -12
- package/lib/core/user-locales.js.map +0 -1
- package/lib/index-browser.d.ts +0 -2
- package/lib/index-browser.js +0 -44
- package/lib/index-browser.js.map +0 -1
- package/lib/index.d.ts +0 -2
- package/lib/index.js +0 -37
- package/lib/index.js.map +0 -1
- package/lib/parser/index.d.ts +0 -2
- package/lib/parser/index.js +0 -19
- package/lib/parser/index.js.map +0 -1
- package/lib/parser/parse-json-catalog.d.ts +0 -3
- package/lib/parser/parse-json-catalog.js +0 -37
- package/lib/parser/parse-json-catalog.js.map +0 -1
- package/lib/parser/parse-json-catalog.spec.d.ts +0 -1
- package/lib/parser/parse-json-catalog.spec.js +0 -41
- package/lib/parser/parse-json-catalog.spec.js.map +0 -1
- package/lib/parser/parse-mo-catalog.d.ts +0 -2
- package/lib/parser/parse-mo-catalog.js +0 -86
- package/lib/parser/parse-mo-catalog.js.map +0 -1
- package/lib/parser/parse-mo-catalog.spec.d.ts +0 -1
- package/lib/parser/parse-mo-catalog.spec.js +0 -115
- package/lib/parser/parse-mo-catalog.spec.js.map +0 -1
- package/lib/transport/fs.js +0 -18
- package/lib/transport/fs.js.map +0 -1
- package/lib/transport/http.d.ts +0 -4
- package/lib/transport/http.js +0 -27
- package/lib/transport/http.js.map +0 -1
- package/lib/transport/http.spec.d.ts +0 -1
- package/lib/transport/http.spec.js +0 -119
- package/lib/transport/http.spec.js.map +0 -1
- package/lib/transport/index.js +0 -20
- package/lib/transport/index.js.map +0 -1
- package/lib/transport/transport.interface.js +0 -3
- package/lib/transport/transport.interface.js.map +0 -1
- package/lib-esm/core/browser-environment.js +0 -8
- package/lib-esm/core/browser-environment.js.map +0 -1
- package/lib-esm/core/catalog-cache.js +0 -36
- package/lib-esm/core/catalog-cache.js.map +0 -1
- package/lib-esm/core/catalog-cache.spec.d.ts +0 -1
- package/lib-esm/core/catalog-cache.spec.js +0 -22
- package/lib-esm/core/catalog-cache.spec.js.map +0 -1
- package/lib-esm/core/catalog-format.spec.d.ts +0 -1
- package/lib-esm/core/catalog-format.spec.js +0 -33
- package/lib-esm/core/catalog-format.spec.js.map +0 -1
- package/lib-esm/core/catalog.d.ts +0 -9
- package/lib-esm/core/catalog.js +0 -2
- package/lib-esm/core/catalog.js.map +0 -1
- package/lib-esm/core/data-viewlet.d.ts +0 -11
- package/lib-esm/core/data-viewlet.js +0 -54
- package/lib-esm/core/data-viewlet.js.map +0 -1
- package/lib-esm/core/data-viewlet.spec.d.ts +0 -1
- package/lib-esm/core/data-viewlet.spec.js +0 -60
- package/lib-esm/core/data-viewlet.spec.js.map +0 -1
- package/lib-esm/core/explode-locale.js +0 -33
- package/lib-esm/core/explode-locale.js.map +0 -1
- package/lib-esm/core/explode-locale.spec.d.ts +0 -1
- package/lib-esm/core/explode-locale.spec.js +0 -39
- package/lib-esm/core/explode-locale.spec.js.map +0 -1
- package/lib-esm/core/germanic-plural.js +0 -4
- package/lib-esm/core/germanic-plural.js.map +0 -1
- package/lib-esm/core/gettext-impl.d.ts +0 -10
- package/lib-esm/core/gettext-impl.js +0 -34
- package/lib-esm/core/gettext-impl.js.map +0 -1
- package/lib-esm/core/gettext.spec.d.ts +0 -1
- package/lib-esm/core/gettext.spec.js +0 -389
- package/lib-esm/core/gettext.spec.js.map +0 -1
- package/lib-esm/core/index.js +0 -5
- package/lib-esm/core/index.js.map +0 -1
- package/lib-esm/core/locale-container.d.ts +0 -8
- package/lib-esm/core/locale-container.js +0 -2
- package/lib-esm/core/locale-container.js.map +0 -1
- package/lib-esm/core/path-separator.d.ts +0 -1
- package/lib-esm/core/path-separator.js +0 -8
- package/lib-esm/core/path-separator.js.map +0 -1
- package/lib-esm/core/resolve-impl.d.ts +0 -3
- package/lib-esm/core/resolve-impl.js +0 -249
- package/lib-esm/core/resolve-impl.js.map +0 -1
- package/lib-esm/core/resolve.spec.d.ts +0 -1
- package/lib-esm/core/resolve.spec.js +0 -340
- package/lib-esm/core/resolve.spec.js.map +0 -1
- package/lib-esm/core/select-locale.js +0 -39
- package/lib-esm/core/select-locale.js.map +0 -1
- package/lib-esm/core/select-locale.spec.d.ts +0 -1
- package/lib-esm/core/select-locale.spec.js +0 -25
- package/lib-esm/core/select-locale.spec.js.map +0 -1
- package/lib-esm/core/set-locale-browser.spec.d.ts +0 -1
- package/lib-esm/core/set-locale-browser.spec.js +0 -15
- package/lib-esm/core/set-locale-browser.spec.js.map +0 -1
- package/lib-esm/core/set-locale-node.spec.d.ts +0 -1
- package/lib-esm/core/set-locale-node.spec.js +0 -24
- package/lib-esm/core/set-locale-node.spec.js.map +0 -1
- package/lib-esm/core/split-locale.js +0 -35
- package/lib-esm/core/split-locale.js.map +0 -1
- package/lib-esm/core/split-locale.spec.d.ts +0 -1
- package/lib-esm/core/split-locale.spec.js +0 -57
- package/lib-esm/core/split-locale.spec.js.map +0 -1
- package/lib-esm/core/textdomain.d.ts +0 -55
- package/lib-esm/core/textdomain.js +0 -274
- package/lib-esm/core/textdomain.js.map +0 -1
- package/lib-esm/core/textdomain.spec.d.ts +0 -1
- package/lib-esm/core/textdomain.spec.js +0 -31
- package/lib-esm/core/textdomain.spec.js.map +0 -1
- package/lib-esm/core/user-locales.js +0 -8
- package/lib-esm/core/user-locales.js.map +0 -1
- package/lib-esm/index-browser.d.ts +0 -2
- package/lib-esm/index-browser.js +0 -26
- package/lib-esm/index-browser.js.map +0 -1
- package/lib-esm/index.d.ts +0 -2
- package/lib-esm/index.js +0 -19
- package/lib-esm/index.js.map +0 -1
- package/lib-esm/parser/index.d.ts +0 -2
- package/lib-esm/parser/index.js +0 -3
- package/lib-esm/parser/index.js.map +0 -1
- package/lib-esm/parser/parse-json-catalog.js +0 -32
- package/lib-esm/parser/parse-json-catalog.js.map +0 -1
- package/lib-esm/parser/parse-json-catalog.spec.d.ts +0 -1
- package/lib-esm/parser/parse-json-catalog.spec.js +0 -39
- package/lib-esm/parser/parse-json-catalog.spec.js.map +0 -1
- package/lib-esm/parser/parse-mo-catalog.js +0 -82
- package/lib-esm/parser/parse-mo-catalog.js.map +0 -1
- package/lib-esm/parser/parse-mo-catalog.spec.d.ts +0 -1
- package/lib-esm/parser/parse-mo-catalog.spec.js +0 -113
- package/lib-esm/parser/parse-mo-catalog.spec.js.map +0 -1
- package/lib-esm/transport/fs.js +0 -15
- package/lib-esm/transport/fs.js.map +0 -1
- package/lib-esm/transport/http.js +0 -24
- package/lib-esm/transport/http.js.map +0 -1
- package/lib-esm/transport/http.spec.d.ts +0 -1
- package/lib-esm/transport/http.spec.js +0 -114
- package/lib-esm/transport/http.spec.js.map +0 -1
- package/lib-esm/transport/index.d.ts +0 -3
- package/lib-esm/transport/index.js +0 -4
- package/lib-esm/transport/index.js.map +0 -1
- package/lib-esm/transport/transport.interface.d.ts +0 -3
- package/lib-esm/transport/transport.interface.js +0 -2
- package/lib-esm/transport/transport.interface.js.map +0 -1
- package/webpack.common.js +0 -38
- package/webpack.dev.js +0 -9
- package/webpack.prod.js +0 -8
|
@@ -0,0 +1,863 @@
|
|
|
1
|
+
import { readFile } from 'fs';
|
|
2
|
+
|
|
3
|
+
let userLocalesSelected = ['C'];
|
|
4
|
+
function userLocales(locales) {
|
|
5
|
+
if (typeof locales !== 'undefined') {
|
|
6
|
+
userLocalesSelected = locales;
|
|
7
|
+
}
|
|
8
|
+
return userLocalesSelected;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
class TransportHttp {
|
|
12
|
+
loadFile(url) {
|
|
13
|
+
return new Promise((resolve, reject) => {
|
|
14
|
+
const xhr = new XMLHttpRequest();
|
|
15
|
+
xhr.responseType = 'arraybuffer';
|
|
16
|
+
xhr.open('GET', url, true);
|
|
17
|
+
xhr.onload = () => {
|
|
18
|
+
if (xhr.readyState === 4 && xhr.status === 200) {
|
|
19
|
+
resolve(xhr.response);
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
reject(new Error('get failed with status ' + xhr.status));
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
xhr.onerror = err => reject(err);
|
|
26
|
+
xhr.send();
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
class TransportFs {
|
|
32
|
+
loadFile(url) {
|
|
33
|
+
return new Promise((resolve, reject) => {
|
|
34
|
+
readFile(url, (err, data) => {
|
|
35
|
+
return err ? reject(err) : resolve(data);
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function germanicPlural(numItems) {
|
|
42
|
+
return numItems === 1 ? 0 : 1;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
class DataViewlet {
|
|
46
|
+
constructor(array, encoding = 'utf-8') {
|
|
47
|
+
this.array = array;
|
|
48
|
+
this.decoder = new TextDecoder(encoding);
|
|
49
|
+
this._encoding = encoding;
|
|
50
|
+
}
|
|
51
|
+
get encoding() {
|
|
52
|
+
return this._encoding;
|
|
53
|
+
}
|
|
54
|
+
set encoding(encoding) {
|
|
55
|
+
this.decoder = new TextDecoder(encoding);
|
|
56
|
+
this._encoding = encoding;
|
|
57
|
+
}
|
|
58
|
+
readUInt32BE(offset = 0) {
|
|
59
|
+
if (offset + 4 > this.array.byteLength + this.array.byteOffset) {
|
|
60
|
+
throw new Error('read past array end');
|
|
61
|
+
}
|
|
62
|
+
return ((((this.array[offset] << 24) >>> 0) |
|
|
63
|
+
(this.array[offset + 1] << 16) |
|
|
64
|
+
(this.array[offset + 2] << 8) |
|
|
65
|
+
this.array[offset + 3]) >>>
|
|
66
|
+
0);
|
|
67
|
+
}
|
|
68
|
+
readUInt32LE(offset = 0) {
|
|
69
|
+
if (offset + 4 > this.array.byteLength + this.array.byteOffset) {
|
|
70
|
+
throw new Error('read past array end');
|
|
71
|
+
}
|
|
72
|
+
return ((((this.array[offset + 3] << 24) >>> 0) |
|
|
73
|
+
(this.array[offset + 2] << 16) |
|
|
74
|
+
(this.array[offset + 1] << 8) |
|
|
75
|
+
this.array[offset]) >>>
|
|
76
|
+
0);
|
|
77
|
+
}
|
|
78
|
+
readString(offset = 0, length) {
|
|
79
|
+
if (offset + length >
|
|
80
|
+
this.array.byteLength + this.array.byteOffset) {
|
|
81
|
+
throw new Error('read past array end');
|
|
82
|
+
}
|
|
83
|
+
if (typeof length === 'undefined') {
|
|
84
|
+
length = this.array.byteLength - offset;
|
|
85
|
+
}
|
|
86
|
+
return this.decoder.decode(this.array.slice(offset, offset + length));
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function parseMoCatalog(raw) {
|
|
91
|
+
const catalog = {
|
|
92
|
+
major: 0,
|
|
93
|
+
minor: 0,
|
|
94
|
+
entries: {},
|
|
95
|
+
pluralFunction: germanicPlural,
|
|
96
|
+
};
|
|
97
|
+
let offset = 0;
|
|
98
|
+
const blob = new DataViewlet(new Uint8Array(raw), 'ascii');
|
|
99
|
+
const magic = blob.readUInt32LE(offset);
|
|
100
|
+
let reader;
|
|
101
|
+
if (magic === 0x950412de) {
|
|
102
|
+
reader = (buf, off) => buf.readUInt32LE(off);
|
|
103
|
+
}
|
|
104
|
+
else if (magic === 0xde120495) {
|
|
105
|
+
reader = (buf, off) => buf.readUInt32BE(off);
|
|
106
|
+
}
|
|
107
|
+
else {
|
|
108
|
+
throw new Error(`invalid MO magic 0x${magic.toString(16)}`);
|
|
109
|
+
}
|
|
110
|
+
offset += 4;
|
|
111
|
+
const major = reader(blob, offset) >> 16;
|
|
112
|
+
offset += 4;
|
|
113
|
+
if (major > 0) {
|
|
114
|
+
throw new Error(`unsupported major revision ${major}`);
|
|
115
|
+
}
|
|
116
|
+
const numStrings = reader(blob, offset);
|
|
117
|
+
offset += 4;
|
|
118
|
+
const msgidOffset = reader(blob, offset);
|
|
119
|
+
offset += 4;
|
|
120
|
+
const msgstrOffset = reader(blob, offset);
|
|
121
|
+
offset = msgidOffset;
|
|
122
|
+
const origTab = [];
|
|
123
|
+
for (let i = 0; i < numStrings; ++i) {
|
|
124
|
+
const l = reader(blob, offset);
|
|
125
|
+
offset += 4;
|
|
126
|
+
const stringOffset = reader(blob, offset);
|
|
127
|
+
offset += 4;
|
|
128
|
+
origTab.push([l, stringOffset]);
|
|
129
|
+
}
|
|
130
|
+
offset = msgstrOffset;
|
|
131
|
+
const transTab = [];
|
|
132
|
+
for (let i = 0; i < numStrings; ++i) {
|
|
133
|
+
const l = reader(blob, offset);
|
|
134
|
+
offset += 4;
|
|
135
|
+
const stringOffset = reader(blob, offset);
|
|
136
|
+
offset += 4;
|
|
137
|
+
transTab.push([l, stringOffset]);
|
|
138
|
+
}
|
|
139
|
+
const poHeader = {};
|
|
140
|
+
for (let i = 0; i < numStrings; ++i) {
|
|
141
|
+
const orig = origTab[i];
|
|
142
|
+
let l = orig[0];
|
|
143
|
+
offset = orig[1];
|
|
144
|
+
const msgid = blob.readString(offset, l).split('\u0000')[0];
|
|
145
|
+
const trans = transTab[i];
|
|
146
|
+
l = trans[0];
|
|
147
|
+
offset = trans[1];
|
|
148
|
+
const msgstr = blob.readString(offset, l).split('\u0000');
|
|
149
|
+
let pairs, kv;
|
|
150
|
+
if (i === 0 && msgid === '') {
|
|
151
|
+
pairs = msgstr[0].split('\n');
|
|
152
|
+
for (let j = 0; j < pairs.length; ++j) {
|
|
153
|
+
if (pairs[j] !== '') {
|
|
154
|
+
kv = pairs[j].split(/[ \t]*:[ \t]*/);
|
|
155
|
+
poHeader[kv[0].toLowerCase()] = kv[1];
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
if (poHeader['content-type'] !== undefined) {
|
|
159
|
+
const enc = poHeader['content-type'].replace(/.*=/, '');
|
|
160
|
+
if (enc !== poHeader['content-type']) {
|
|
161
|
+
blob.encoding = enc;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
catalog.entries[msgid] = msgstr;
|
|
166
|
+
}
|
|
167
|
+
return catalog;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
function validateMoJsonCatalog(udata) {
|
|
171
|
+
if (udata === null || typeof udata === 'undefined') {
|
|
172
|
+
throw new Error('catalog is either null or undefined');
|
|
173
|
+
}
|
|
174
|
+
const data = udata;
|
|
175
|
+
if (data.constructor !== Object) {
|
|
176
|
+
throw new Error('catalog must be a dictionary');
|
|
177
|
+
}
|
|
178
|
+
if (!Object.prototype.hasOwnProperty.call(data, 'entries')) {
|
|
179
|
+
throw new Error('catalog.entries does not exist');
|
|
180
|
+
}
|
|
181
|
+
const entries = data.entries;
|
|
182
|
+
if (entries === null || typeof entries === 'undefined') {
|
|
183
|
+
throw new Error('catalog.entries are not defined or null');
|
|
184
|
+
}
|
|
185
|
+
if (entries.constructor !== Object) {
|
|
186
|
+
throw new Error('catalog.entries must be a dictionary');
|
|
187
|
+
}
|
|
188
|
+
for (const [key, value] of Object.entries(entries)) {
|
|
189
|
+
if (!Array.isArray(value)) {
|
|
190
|
+
throw new Error(`catalog entry for key '${key}' is not an array`);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
return data;
|
|
194
|
+
}
|
|
195
|
+
function parseMoJsonCatalog(json) {
|
|
196
|
+
const text = new TextDecoder().decode(json);
|
|
197
|
+
const data = JSON.parse(text);
|
|
198
|
+
return validateMoJsonCatalog(data);
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
function validateJsonCatalog(udata) {
|
|
202
|
+
if (udata === null || typeof udata === 'undefined') {
|
|
203
|
+
throw new Error('catalog is either null or undefined');
|
|
204
|
+
}
|
|
205
|
+
const entries = udata;
|
|
206
|
+
if (entries.constructor !== Object) ;
|
|
207
|
+
const catalog = {
|
|
208
|
+
major: 0,
|
|
209
|
+
minor: 1,
|
|
210
|
+
pluralFunction: () => 0,
|
|
211
|
+
entries: {},
|
|
212
|
+
};
|
|
213
|
+
for (const [msgid, msgstr] of Object.entries(entries)) {
|
|
214
|
+
catalog.entries[msgid] = [msgstr.toString()];
|
|
215
|
+
}
|
|
216
|
+
return catalog;
|
|
217
|
+
}
|
|
218
|
+
function parseJsonCatalog(json) {
|
|
219
|
+
const text = new TextDecoder().decode(json);
|
|
220
|
+
const data = JSON.parse(text);
|
|
221
|
+
return validateJsonCatalog(data);
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
const tagHyphenRegex = new RegExp('^[a-z0-9]+(?:-[a-z0-9]+)*$', 'i');
|
|
225
|
+
const tagUnderscoreRegex = new RegExp('^[a-z0-9]+(?:_[a-z0-9]+)*$', 'i');
|
|
226
|
+
function splitLocale(locale) {
|
|
227
|
+
let charset = '', modifier = '';
|
|
228
|
+
const underscoreSeparator = locale.includes('_');
|
|
229
|
+
locale = locale.replace(/@([a-z]+)$/i, (_, match) => {
|
|
230
|
+
modifier = match;
|
|
231
|
+
return '';
|
|
232
|
+
});
|
|
233
|
+
locale = locale.replace(/\.([-0-9a-z]+)$/i, (_, match) => {
|
|
234
|
+
charset = match;
|
|
235
|
+
return '';
|
|
236
|
+
});
|
|
237
|
+
if (underscoreSeparator) {
|
|
238
|
+
if (!tagUnderscoreRegex.exec(locale)) {
|
|
239
|
+
return null;
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
else {
|
|
243
|
+
if (!tagHyphenRegex.exec(locale)) {
|
|
244
|
+
return null;
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
const separator = underscoreSeparator ? '_' : '-';
|
|
248
|
+
const tags = locale.split(separator);
|
|
249
|
+
const split = { tags: tags, underscoreSeparator };
|
|
250
|
+
if (charset.length) {
|
|
251
|
+
split.charset = charset;
|
|
252
|
+
}
|
|
253
|
+
if (modifier.length) {
|
|
254
|
+
split.modifier = modifier;
|
|
255
|
+
}
|
|
256
|
+
return split;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
class CatalogCache {
|
|
260
|
+
constructor() {
|
|
261
|
+
}
|
|
262
|
+
static getInstance() {
|
|
263
|
+
if (!CatalogCache.instance) {
|
|
264
|
+
CatalogCache.instance = new CatalogCache();
|
|
265
|
+
}
|
|
266
|
+
return CatalogCache.instance;
|
|
267
|
+
}
|
|
268
|
+
static clear() {
|
|
269
|
+
CatalogCache.cache = {};
|
|
270
|
+
}
|
|
271
|
+
static lookup(localeKey, textdomain) {
|
|
272
|
+
if (CatalogCache.cache[localeKey]) {
|
|
273
|
+
const ptr = CatalogCache.cache[localeKey];
|
|
274
|
+
if (Object.prototype.hasOwnProperty.call(ptr, textdomain)) {
|
|
275
|
+
return ptr[textdomain];
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
return null;
|
|
279
|
+
}
|
|
280
|
+
static store(localeKey, textdomain, entry) {
|
|
281
|
+
if (Promise.resolve(entry) !== entry) {
|
|
282
|
+
entry = validateMoJsonCatalog(entry);
|
|
283
|
+
}
|
|
284
|
+
if (!CatalogCache.cache[localeKey]) {
|
|
285
|
+
CatalogCache.cache[localeKey] = {};
|
|
286
|
+
}
|
|
287
|
+
CatalogCache.cache[localeKey][textdomain] = entry;
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
CatalogCache.cache = {};
|
|
291
|
+
|
|
292
|
+
function explodeLocale(locale, vary) {
|
|
293
|
+
const retval = [];
|
|
294
|
+
const lsep = locale.underscoreSeparator ? '_' : '-';
|
|
295
|
+
let i = 0 ;
|
|
296
|
+
const hasCharset = typeof locale.charset !== 'undefined';
|
|
297
|
+
const hasModifier = typeof locale.modifier !== 'undefined';
|
|
298
|
+
const charsets = hasCharset ? [locale.charset] : [''];
|
|
299
|
+
if (hasCharset) {
|
|
300
|
+
const charset = locale.charset;
|
|
301
|
+
const ucCharset = charset.toUpperCase();
|
|
302
|
+
if (ucCharset !== charset) {
|
|
303
|
+
charsets.push(ucCharset);
|
|
304
|
+
}
|
|
305
|
+
charsets.push('');
|
|
306
|
+
}
|
|
307
|
+
for (; i < locale.tags.length; ++i) {
|
|
308
|
+
const lingua = locale.tags.slice(0, i + 1).join(lsep);
|
|
309
|
+
const ids = new Array();
|
|
310
|
+
charsets.forEach(charset => {
|
|
311
|
+
let id = charset.length ? lingua + '.' + charset : lingua;
|
|
312
|
+
if (hasModifier) {
|
|
313
|
+
id += '@' + locale.modifier;
|
|
314
|
+
}
|
|
315
|
+
ids.push(id);
|
|
316
|
+
});
|
|
317
|
+
retval.push(ids);
|
|
318
|
+
}
|
|
319
|
+
return retval;
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
function loadCatalog(url, format) {
|
|
323
|
+
let transportInstance;
|
|
324
|
+
{
|
|
325
|
+
let transport;
|
|
326
|
+
try {
|
|
327
|
+
const parsedURL = new URL(url);
|
|
328
|
+
if (parsedURL.protocol === 'https:' ||
|
|
329
|
+
parsedURL.protocol === 'http:' ||
|
|
330
|
+
parsedURL.protocol === 'file:') {
|
|
331
|
+
transport = 'http';
|
|
332
|
+
}
|
|
333
|
+
else {
|
|
334
|
+
throw new Error(`unsupported scheme ${parsedURL.protocol}`);
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
catch (e) {
|
|
338
|
+
{
|
|
339
|
+
transport = 'fs';
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
if (transport === 'http') {
|
|
343
|
+
transportInstance = new TransportHttp();
|
|
344
|
+
}
|
|
345
|
+
else {
|
|
346
|
+
transportInstance = new TransportFs();
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
let validator;
|
|
350
|
+
if ('mo.json' === format) {
|
|
351
|
+
validator = parseMoJsonCatalog;
|
|
352
|
+
}
|
|
353
|
+
else if ('.json' === format) {
|
|
354
|
+
validator = parseJsonCatalog;
|
|
355
|
+
}
|
|
356
|
+
else {
|
|
357
|
+
validator = parseMoCatalog;
|
|
358
|
+
}
|
|
359
|
+
return new Promise((resolve, reject) => {
|
|
360
|
+
transportInstance
|
|
361
|
+
.loadFile(url)
|
|
362
|
+
.then(data => {
|
|
363
|
+
resolve(validator(data));
|
|
364
|
+
})
|
|
365
|
+
.catch(e => reject(e));
|
|
366
|
+
});
|
|
367
|
+
}
|
|
368
|
+
function assemblePath(base, id, domainname, extender) {
|
|
369
|
+
return `${base}/${id}/LC_MESSAGES/${domainname}.${extender}`;
|
|
370
|
+
}
|
|
371
|
+
function loadLanguageFromObject(ids, base, domainname) {
|
|
372
|
+
let catalog;
|
|
373
|
+
for (let i = 0; i < ids.length; ++i) {
|
|
374
|
+
const id = ids[0];
|
|
375
|
+
if (!Object.prototype.hasOwnProperty.call(base, id)) {
|
|
376
|
+
continue;
|
|
377
|
+
}
|
|
378
|
+
if (!Object.prototype.hasOwnProperty.call(base[id], 'LC_MESSAGES')) {
|
|
379
|
+
continue;
|
|
380
|
+
}
|
|
381
|
+
if (!Object.prototype.hasOwnProperty.call(base[id].LC_MESSAGES, domainname)) {
|
|
382
|
+
continue;
|
|
383
|
+
}
|
|
384
|
+
catalog = base[id].LC_MESSAGES[domainname];
|
|
385
|
+
}
|
|
386
|
+
return new Promise((resolve, reject) => {
|
|
387
|
+
if (catalog) {
|
|
388
|
+
resolve(catalog);
|
|
389
|
+
}
|
|
390
|
+
else {
|
|
391
|
+
reject();
|
|
392
|
+
}
|
|
393
|
+
});
|
|
394
|
+
}
|
|
395
|
+
async function loadLanguage(ids, base, domainname, format) {
|
|
396
|
+
if (typeof base === 'object' && base !== null) {
|
|
397
|
+
return loadLanguageFromObject(ids, base, domainname);
|
|
398
|
+
}
|
|
399
|
+
return new Promise((resolve, reject) => {
|
|
400
|
+
const tries = new Array();
|
|
401
|
+
ids.forEach(id => {
|
|
402
|
+
tries.push(() => loadCatalog(assemblePath(base, id, domainname, format), format));
|
|
403
|
+
});
|
|
404
|
+
tries
|
|
405
|
+
.reduce((promise, fn) => promise.catch(fn), Promise.reject())
|
|
406
|
+
.then(value => resolve(value))
|
|
407
|
+
.catch(e => reject(e));
|
|
408
|
+
});
|
|
409
|
+
}
|
|
410
|
+
async function loadDomain(exploded, localeKey, base, domainname, format) {
|
|
411
|
+
const entries = {};
|
|
412
|
+
const catalog = {
|
|
413
|
+
major: 0,
|
|
414
|
+
minor: 0,
|
|
415
|
+
pluralFunction: germanicPlural,
|
|
416
|
+
entries,
|
|
417
|
+
};
|
|
418
|
+
const cacheHit = CatalogCache.lookup(localeKey, domainname);
|
|
419
|
+
if (cacheHit !== null) {
|
|
420
|
+
if (Promise.resolve(cacheHit) === cacheHit) {
|
|
421
|
+
return cacheHit;
|
|
422
|
+
}
|
|
423
|
+
else {
|
|
424
|
+
return new Promise(resolve => resolve(cacheHit));
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
const promises = new Array();
|
|
428
|
+
const results = new Array();
|
|
429
|
+
exploded.forEach((tries, i) => {
|
|
430
|
+
const p = loadLanguage(tries, base, domainname, format)
|
|
431
|
+
.then(catalog => (results[i] = catalog))
|
|
432
|
+
.catch(() => {
|
|
433
|
+
});
|
|
434
|
+
promises.push(p);
|
|
435
|
+
});
|
|
436
|
+
await Promise.all(promises);
|
|
437
|
+
results.forEach(result => {
|
|
438
|
+
catalog.major = result.major;
|
|
439
|
+
catalog.minor = result.minor;
|
|
440
|
+
catalog.entries = Object.assign(Object.assign({}, catalog.entries), result.entries);
|
|
441
|
+
});
|
|
442
|
+
return new Promise(resolve => {
|
|
443
|
+
resolve(catalog);
|
|
444
|
+
});
|
|
445
|
+
}
|
|
446
|
+
function pluralExpression(str) {
|
|
447
|
+
const tokens = str
|
|
448
|
+
.replace(/[ \t\r\013\014]/g, '')
|
|
449
|
+
.replace(/;$/, '')
|
|
450
|
+
.split(/[<>!=]=|&&|\|\||[-!*/%+<>=?:;]/);
|
|
451
|
+
for (let i = 0; i < tokens.length; ++i) {
|
|
452
|
+
const token = tokens[i].replace(/^\(+/, '').replace(/\)+$/, '');
|
|
453
|
+
if (token !== 'nplurals' &&
|
|
454
|
+
token !== 'plural' &&
|
|
455
|
+
token !== 'n' &&
|
|
456
|
+
null === /^[0-9]+$/.exec(token)) {
|
|
457
|
+
throw new Error('invalid plural function');
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
const code = 'var nplurals = 1, plural = 0;' + str + '; return 0 + plural';
|
|
461
|
+
return new Function('n', code);
|
|
462
|
+
}
|
|
463
|
+
function setPluralFunction(catalog) {
|
|
464
|
+
if (!Object.prototype.hasOwnProperty.call(catalog.entries, '')) {
|
|
465
|
+
return catalog;
|
|
466
|
+
}
|
|
467
|
+
const headers = catalog.entries[''][0].split('\n');
|
|
468
|
+
headers.forEach(header => {
|
|
469
|
+
const tokens = header.split(':');
|
|
470
|
+
if ('plural-forms' === tokens.shift().toLowerCase()) {
|
|
471
|
+
const code = tokens.join(':');
|
|
472
|
+
catalog.pluralFunction = pluralExpression(code);
|
|
473
|
+
}
|
|
474
|
+
});
|
|
475
|
+
return catalog;
|
|
476
|
+
}
|
|
477
|
+
function resolveImpl(domainname, path, format, localeKey) {
|
|
478
|
+
const defaultCatalog = {
|
|
479
|
+
major: 0,
|
|
480
|
+
minor: 0,
|
|
481
|
+
pluralFunction: germanicPlural,
|
|
482
|
+
entries: {},
|
|
483
|
+
};
|
|
484
|
+
if (localeKey === 'C' || localeKey === 'POSIX') {
|
|
485
|
+
return new Promise(resolve => resolve(defaultCatalog));
|
|
486
|
+
}
|
|
487
|
+
return new Promise(resolve => {
|
|
488
|
+
const exploded = explodeLocale(splitLocale(localeKey));
|
|
489
|
+
loadDomain(exploded, localeKey, path, domainname, format)
|
|
490
|
+
.then(catalog => {
|
|
491
|
+
setPluralFunction(catalog);
|
|
492
|
+
CatalogCache.store(localeKey, domainname, catalog);
|
|
493
|
+
resolve(catalog);
|
|
494
|
+
})
|
|
495
|
+
.catch(() => {
|
|
496
|
+
CatalogCache.store(localeKey, domainname, defaultCatalog);
|
|
497
|
+
resolve(defaultCatalog);
|
|
498
|
+
});
|
|
499
|
+
});
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
function gettextImpl(args) {
|
|
503
|
+
var _a;
|
|
504
|
+
const key = typeof args.msgctxt === 'undefined'
|
|
505
|
+
? args.msgid
|
|
506
|
+
: args.msgctxt + '\u0004' + args.msgid;
|
|
507
|
+
const translations = args.catalog.entries[key];
|
|
508
|
+
const numItems = (_a = args.numItems) !== null && _a !== void 0 ? _a : 1;
|
|
509
|
+
if (translations && translations.length) {
|
|
510
|
+
if (typeof args.msgidPlural === 'undefined') {
|
|
511
|
+
return translations[0];
|
|
512
|
+
}
|
|
513
|
+
else {
|
|
514
|
+
let pluralForm = args.catalog.pluralFunction(numItems);
|
|
515
|
+
if (pluralForm >= translations.length) {
|
|
516
|
+
if (translations.length === 1) {
|
|
517
|
+
return translations[0];
|
|
518
|
+
}
|
|
519
|
+
else {
|
|
520
|
+
pluralForm = germanicPlural(numItems);
|
|
521
|
+
}
|
|
522
|
+
}
|
|
523
|
+
return translations[pluralForm];
|
|
524
|
+
}
|
|
525
|
+
}
|
|
526
|
+
else if (typeof args.msgidPlural !== 'undefined') {
|
|
527
|
+
const pluralform = args.catalog.pluralFunction(numItems);
|
|
528
|
+
if (pluralform === 1) {
|
|
529
|
+
return args.msgidPlural;
|
|
530
|
+
}
|
|
531
|
+
}
|
|
532
|
+
return args.msgid;
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
const isNode = typeof process !== 'undefined' &&
|
|
536
|
+
process.versions !== null &&
|
|
537
|
+
process.versions.node !== null;
|
|
538
|
+
const pathSeparator = isNode && process.platform === 'win32' ? '\\' : '/';
|
|
539
|
+
|
|
540
|
+
function tagsEqual(left, right) {
|
|
541
|
+
if (left.length !== right.length) {
|
|
542
|
+
return false;
|
|
543
|
+
}
|
|
544
|
+
for (let i = 0; i < left.length; ++i) {
|
|
545
|
+
if (left[i].toLowerCase() !== right[i].toLowerCase()) {
|
|
546
|
+
return false;
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
return true;
|
|
550
|
+
}
|
|
551
|
+
function selectLocale(supported, requested) {
|
|
552
|
+
let languageMatch = '';
|
|
553
|
+
for (let i = 0; i < requested.length; ++i) {
|
|
554
|
+
const wanted = splitLocale(requested[i]);
|
|
555
|
+
if (!wanted) {
|
|
556
|
+
continue;
|
|
557
|
+
}
|
|
558
|
+
for (let j = 0; j < supported.length; ++j) {
|
|
559
|
+
const got = splitLocale(supported[j]);
|
|
560
|
+
if (!got) {
|
|
561
|
+
continue;
|
|
562
|
+
}
|
|
563
|
+
if (tagsEqual(wanted.tags, got.tags)) {
|
|
564
|
+
return supported[j];
|
|
565
|
+
}
|
|
566
|
+
if (!languageMatch.length &&
|
|
567
|
+
wanted.tags[0].toLowerCase() === got.tags[0].toLowerCase()) {
|
|
568
|
+
languageMatch = supported[j];
|
|
569
|
+
}
|
|
570
|
+
}
|
|
571
|
+
}
|
|
572
|
+
if (languageMatch.length) {
|
|
573
|
+
return languageMatch;
|
|
574
|
+
}
|
|
575
|
+
return 'C';
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
class Textdomain {
|
|
579
|
+
_(msgid) {
|
|
580
|
+
return gettextImpl({ msgid: msgid, catalog: this.catalog });
|
|
581
|
+
}
|
|
582
|
+
_n(msgid, msgidPlural, numItems) {
|
|
583
|
+
return gettextImpl({
|
|
584
|
+
msgid: msgid,
|
|
585
|
+
msgidPlural: msgidPlural,
|
|
586
|
+
numItems: numItems,
|
|
587
|
+
catalog: this.catalog,
|
|
588
|
+
});
|
|
589
|
+
}
|
|
590
|
+
_p(msgctxt, msgid) {
|
|
591
|
+
return gettextImpl({
|
|
592
|
+
msgctxt: msgctxt,
|
|
593
|
+
msgid: msgid,
|
|
594
|
+
catalog: this.catalog,
|
|
595
|
+
});
|
|
596
|
+
}
|
|
597
|
+
_np(msgctxt, msgid, msgidPlural, numItems) {
|
|
598
|
+
return gettextImpl({
|
|
599
|
+
msgctxt: msgctxt,
|
|
600
|
+
msgid: msgid,
|
|
601
|
+
msgidPlural: msgidPlural,
|
|
602
|
+
numItems: numItems,
|
|
603
|
+
catalog: this.catalog,
|
|
604
|
+
});
|
|
605
|
+
}
|
|
606
|
+
_x(msgid, placeholders) {
|
|
607
|
+
return Textdomain.expand(gettextImpl({ msgid: msgid, catalog: this.catalog }), placeholders || {});
|
|
608
|
+
}
|
|
609
|
+
_nx(msgid, msgidPlural, numItems, placeholders) {
|
|
610
|
+
return Textdomain.expand(gettextImpl({
|
|
611
|
+
msgid: msgid,
|
|
612
|
+
msgidPlural: msgidPlural,
|
|
613
|
+
numItems: numItems,
|
|
614
|
+
catalog: this.catalog,
|
|
615
|
+
}), placeholders || {});
|
|
616
|
+
}
|
|
617
|
+
_px(msgctxt, msgid, placeholders) {
|
|
618
|
+
return Textdomain.expand(gettextImpl({ msgctxt: msgctxt, msgid: msgid, catalog: this.catalog }), placeholders || {});
|
|
619
|
+
}
|
|
620
|
+
_npx(msgctxt, msgid, msgidPlural, numItems, placeholders) {
|
|
621
|
+
return Textdomain.expand(gettextImpl({
|
|
622
|
+
msgctxt: msgctxt,
|
|
623
|
+
msgid: msgid,
|
|
624
|
+
msgidPlural: msgidPlural,
|
|
625
|
+
numItems: numItems,
|
|
626
|
+
catalog: this.catalog,
|
|
627
|
+
}), placeholders || {});
|
|
628
|
+
}
|
|
629
|
+
static getCatalog(locale, textdomain) {
|
|
630
|
+
const catalog = CatalogCache.lookup(locale, textdomain);
|
|
631
|
+
if (!catalog || Promise.resolve(catalog) === catalog) {
|
|
632
|
+
return {
|
|
633
|
+
major: 0,
|
|
634
|
+
minor: 0,
|
|
635
|
+
pluralFunction: germanicPlural,
|
|
636
|
+
entries: {},
|
|
637
|
+
};
|
|
638
|
+
}
|
|
639
|
+
return catalog;
|
|
640
|
+
}
|
|
641
|
+
_l(locale, msgid) {
|
|
642
|
+
const catalog = Textdomain.getCatalog(locale, this.textdomain());
|
|
643
|
+
return gettextImpl({ msgid: msgid, catalog: catalog });
|
|
644
|
+
}
|
|
645
|
+
_ln(locale, msgid, msgidPlural, numItems) {
|
|
646
|
+
const catalog = Textdomain.getCatalog(locale, this.textdomain());
|
|
647
|
+
return gettextImpl({
|
|
648
|
+
msgid: msgid,
|
|
649
|
+
msgidPlural: msgidPlural,
|
|
650
|
+
numItems: numItems,
|
|
651
|
+
catalog: catalog,
|
|
652
|
+
});
|
|
653
|
+
}
|
|
654
|
+
_lp(locale, msgctxt, msgid) {
|
|
655
|
+
const catalog = Textdomain.getCatalog(locale, this.textdomain());
|
|
656
|
+
return gettextImpl({ msgctxt: msgctxt, msgid: msgid, catalog: catalog });
|
|
657
|
+
}
|
|
658
|
+
_lnp(locale, msgctxt, msgid, msgidPlural, numItems) {
|
|
659
|
+
const catalog = Textdomain.getCatalog(locale, this.textdomain());
|
|
660
|
+
return gettextImpl({
|
|
661
|
+
msgctxt: msgctxt,
|
|
662
|
+
msgid: msgid,
|
|
663
|
+
msgidPlural: msgidPlural,
|
|
664
|
+
numItems: numItems,
|
|
665
|
+
catalog: catalog,
|
|
666
|
+
});
|
|
667
|
+
}
|
|
668
|
+
_lx(locale, msgid, placeholders) {
|
|
669
|
+
const catalog = Textdomain.getCatalog(locale, this.textdomain());
|
|
670
|
+
return Textdomain.expand(gettextImpl({ msgid: msgid, catalog: catalog }), placeholders || {});
|
|
671
|
+
}
|
|
672
|
+
_lnx(locale, msgid, msgidPlural, numItems, placeholders) {
|
|
673
|
+
const catalog = Textdomain.getCatalog(locale, this.textdomain());
|
|
674
|
+
return Textdomain.expand(gettextImpl({
|
|
675
|
+
msgid: msgid,
|
|
676
|
+
msgidPlural: msgidPlural,
|
|
677
|
+
numItems: numItems,
|
|
678
|
+
catalog: catalog,
|
|
679
|
+
}), placeholders || {});
|
|
680
|
+
}
|
|
681
|
+
_lpx(locale, msgctxt, msgid, placeholders) {
|
|
682
|
+
const catalog = Textdomain.getCatalog(locale, this.textdomain());
|
|
683
|
+
return Textdomain.expand(gettextImpl({ msgctxt: msgctxt, msgid: msgid, catalog: catalog }), placeholders || {});
|
|
684
|
+
}
|
|
685
|
+
_lnpx(locale, msgctxt, msgid, msgidPlural, numItems, placeholders) {
|
|
686
|
+
const catalog = Textdomain.getCatalog(locale, this.textdomain());
|
|
687
|
+
return Textdomain.expand(gettextImpl({
|
|
688
|
+
msgctxt: msgctxt,
|
|
689
|
+
msgid: msgid,
|
|
690
|
+
msgidPlural: msgidPlural,
|
|
691
|
+
numItems: numItems,
|
|
692
|
+
catalog: catalog,
|
|
693
|
+
}), placeholders || {});
|
|
694
|
+
}
|
|
695
|
+
static expand(msg, placeholders) {
|
|
696
|
+
return msg.replace(/\{([a-zA-Z][0-9a-zA-Z]*)\}/g, (_, match) => {
|
|
697
|
+
if (Object.prototype.hasOwnProperty.call(placeholders, match)) {
|
|
698
|
+
return placeholders[match];
|
|
699
|
+
}
|
|
700
|
+
else {
|
|
701
|
+
return `{${match}}`;
|
|
702
|
+
}
|
|
703
|
+
});
|
|
704
|
+
}
|
|
705
|
+
static getInstance(textdomain) {
|
|
706
|
+
if (typeof textdomain === 'undefined' ||
|
|
707
|
+
textdomain === null ||
|
|
708
|
+
textdomain === '') {
|
|
709
|
+
throw new Error('Cannot instantiate TextDomain without a textdomain');
|
|
710
|
+
}
|
|
711
|
+
if (Object.prototype.hasOwnProperty.call(Textdomain.domains, textdomain)) {
|
|
712
|
+
return Textdomain.domains[textdomain];
|
|
713
|
+
}
|
|
714
|
+
else {
|
|
715
|
+
const domain = new Textdomain(textdomain);
|
|
716
|
+
Textdomain.domains[textdomain] = domain;
|
|
717
|
+
domain.catalog = {
|
|
718
|
+
major: 0,
|
|
719
|
+
minor: 0,
|
|
720
|
+
pluralFunction: germanicPlural,
|
|
721
|
+
entries: {},
|
|
722
|
+
};
|
|
723
|
+
return domain;
|
|
724
|
+
}
|
|
725
|
+
}
|
|
726
|
+
static clearInstances() {
|
|
727
|
+
Textdomain.boundDomains = {};
|
|
728
|
+
}
|
|
729
|
+
static forgetInstances() {
|
|
730
|
+
Textdomain.clearInstances();
|
|
731
|
+
Textdomain.domains = {};
|
|
732
|
+
}
|
|
733
|
+
static get locale() {
|
|
734
|
+
return Textdomain._locale;
|
|
735
|
+
}
|
|
736
|
+
static set locale(locale) {
|
|
737
|
+
const ucLocale = locale.toUpperCase();
|
|
738
|
+
if (ucLocale === 'POSIX' || ucLocale === 'C') {
|
|
739
|
+
this._locale = 'POSIX';
|
|
740
|
+
return;
|
|
741
|
+
}
|
|
742
|
+
const split = splitLocale(locale);
|
|
743
|
+
if (!split) {
|
|
744
|
+
throw new Error('invalid locale identifier');
|
|
745
|
+
}
|
|
746
|
+
split.tags[0] = split.tags[0].toLowerCase();
|
|
747
|
+
if (split.tags.length > 1) {
|
|
748
|
+
split.tags[1] = split.tags[1].toUpperCase();
|
|
749
|
+
}
|
|
750
|
+
const separator = split.underscoreSeparator ? '_' : '-';
|
|
751
|
+
this._locale = split.tags.join(separator);
|
|
752
|
+
if (typeof split.charset !== 'undefined') {
|
|
753
|
+
this._locale += '.' + split.charset;
|
|
754
|
+
}
|
|
755
|
+
if (typeof split.modifier !== 'undefined') {
|
|
756
|
+
this._locale += '@' + split.modifier;
|
|
757
|
+
}
|
|
758
|
+
}
|
|
759
|
+
constructor(domain) {
|
|
760
|
+
this._catalogFormat = 'mo.json';
|
|
761
|
+
this.domain = domain;
|
|
762
|
+
}
|
|
763
|
+
textdomain() {
|
|
764
|
+
return this.domain;
|
|
765
|
+
}
|
|
766
|
+
bindtextdomain(path) {
|
|
767
|
+
if (typeof path !== 'undefined') {
|
|
768
|
+
Textdomain.boundDomains[this.domain] = path;
|
|
769
|
+
}
|
|
770
|
+
return Textdomain.boundDomains[this.domain];
|
|
771
|
+
}
|
|
772
|
+
async resolve(locale) {
|
|
773
|
+
const promises = [this.resolve1(locale)];
|
|
774
|
+
for (const td in Textdomain.domains) {
|
|
775
|
+
if (Object.prototype.hasOwnProperty.call(Textdomain.domains, td) &&
|
|
776
|
+
Textdomain.domains[td] !== this) {
|
|
777
|
+
promises.push(Textdomain.domains[td].resolve1(locale));
|
|
778
|
+
}
|
|
779
|
+
}
|
|
780
|
+
return Promise.all(promises).then(values => {
|
|
781
|
+
return new Promise(resolve => resolve(values[0]));
|
|
782
|
+
});
|
|
783
|
+
}
|
|
784
|
+
async resolve1(locale) {
|
|
785
|
+
let path = this.bindtextdomain();
|
|
786
|
+
if (typeof path === 'undefined' || path === null) {
|
|
787
|
+
const parts = ['.', 'locale'];
|
|
788
|
+
path = parts.join(pathSeparator);
|
|
789
|
+
}
|
|
790
|
+
const resolvedLocale = locale ? locale : Textdomain.locale;
|
|
791
|
+
return resolveImpl(this.domain, path, this.catalogFormat, resolvedLocale).then(catalog => {
|
|
792
|
+
if (!locale) {
|
|
793
|
+
this.catalog = catalog;
|
|
794
|
+
}
|
|
795
|
+
return new Promise(resolve => resolve(catalog));
|
|
796
|
+
});
|
|
797
|
+
}
|
|
798
|
+
get catalogFormat() {
|
|
799
|
+
return this._catalogFormat;
|
|
800
|
+
}
|
|
801
|
+
set catalogFormat(format) {
|
|
802
|
+
format = format.toLowerCase();
|
|
803
|
+
if (format === 'mo.json') {
|
|
804
|
+
this._catalogFormat = 'mo.json';
|
|
805
|
+
}
|
|
806
|
+
else if (format === 'mo') {
|
|
807
|
+
this._catalogFormat = 'mo';
|
|
808
|
+
}
|
|
809
|
+
else {
|
|
810
|
+
throw new Error(`unsupported format ${format}`);
|
|
811
|
+
}
|
|
812
|
+
}
|
|
813
|
+
static userLocales() {
|
|
814
|
+
return userLocales();
|
|
815
|
+
}
|
|
816
|
+
static selectLocale(supported, requested) {
|
|
817
|
+
return selectLocale(supported, requested !== null && requested !== void 0 ? requested : Textdomain.userLocales());
|
|
818
|
+
}
|
|
819
|
+
static N_(msgid) {
|
|
820
|
+
return msgid;
|
|
821
|
+
}
|
|
822
|
+
N_(msgid) {
|
|
823
|
+
return msgid;
|
|
824
|
+
}
|
|
825
|
+
N_x(msgid, placeholders) {
|
|
826
|
+
return Textdomain.expand(msgid, placeholders !== null && placeholders !== void 0 ? placeholders : {});
|
|
827
|
+
}
|
|
828
|
+
static N_x(msgid, placeholders) {
|
|
829
|
+
return Textdomain.expand(msgid, placeholders !== null && placeholders !== void 0 ? placeholders : {});
|
|
830
|
+
}
|
|
831
|
+
N_p(_msgctxt, msgid) {
|
|
832
|
+
return msgid;
|
|
833
|
+
}
|
|
834
|
+
static N_p(_msgctxt, msgid) {
|
|
835
|
+
return msgid;
|
|
836
|
+
}
|
|
837
|
+
N_px(_msgctxt, msgid, placeholders) {
|
|
838
|
+
return Textdomain.expand(msgid, placeholders !== null && placeholders !== void 0 ? placeholders : {});
|
|
839
|
+
}
|
|
840
|
+
static N_px(_msgctxt, msgid, placeholders) {
|
|
841
|
+
return Textdomain.expand(msgid, placeholders !== null && placeholders !== void 0 ? placeholders : {});
|
|
842
|
+
}
|
|
843
|
+
}
|
|
844
|
+
Textdomain.domains = {};
|
|
845
|
+
Textdomain.cache = CatalogCache.getInstance();
|
|
846
|
+
Textdomain.boundDomains = {};
|
|
847
|
+
Textdomain._locale = 'C';
|
|
848
|
+
|
|
849
|
+
if (typeof process.env.LANGUAGE !== 'undefined') {
|
|
850
|
+
userLocales(process.env.LANGUAGE.split(':'));
|
|
851
|
+
}
|
|
852
|
+
else if (typeof process.env.LC_ALL !== 'undefined') {
|
|
853
|
+
userLocales([process.env.LC_ALL]);
|
|
854
|
+
}
|
|
855
|
+
else if (typeof process.env.LANG !== 'undefined') {
|
|
856
|
+
userLocales([process.env.LANG]);
|
|
857
|
+
}
|
|
858
|
+
else if (typeof process.env.LC_MESSAGES !== 'undefined') {
|
|
859
|
+
userLocales([process.env.LC_MESSAGES]);
|
|
860
|
+
}
|
|
861
|
+
|
|
862
|
+
export { CatalogCache, Textdomain, parseMoCatalog, parseMoJsonCatalog };
|
|
863
|
+
//# sourceMappingURL=esgettext.esm.js.map
|