@esgettext/runtime 1.1.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.
@@ -0,0 +1,1415 @@
1
+ (function (global, factory) {
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
3
+ typeof define === 'function' && define.amd ? define(['exports'], factory) :
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.esgettext = {}));
5
+ })(this, (function (exports) { 'use strict';
6
+
7
+ let isBrowser = false;
8
+ /*
9
+ * Force an execution environment. By default, the environment (NodeJS or
10
+ * browser) is auto-detected. You can force the library to assume a certain
11
+ * environment with this function.
12
+ *
13
+ * @param browser - whether to assume a browser or not
14
+ * @returns the new setting.
15
+ */
16
+ function browserEnvironment(browser) {
17
+ if (typeof browser !== 'undefined') {
18
+ isBrowser = browser;
19
+ }
20
+ return isBrowser;
21
+ }
22
+
23
+ let userLocalesSelected = ['C'];
24
+ /*
25
+ * Force an execution environment. By default, the environment (NodeJS or
26
+ * browser) is auto-detected. You can force the library to assume a certain
27
+ * environment with this function.
28
+ *
29
+ * @param browser - whether to assume a browser or not
30
+ * @returns the new setting.
31
+ */
32
+ function userLocales(locales) {
33
+ if (typeof locales !== 'undefined') {
34
+ userLocalesSelected = locales;
35
+ }
36
+ return userLocalesSelected;
37
+ }
38
+
39
+ /******************************************************************************
40
+ Copyright (c) Microsoft Corporation.
41
+
42
+ Permission to use, copy, modify, and/or distribute this software for any
43
+ purpose with or without fee is hereby granted.
44
+
45
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
46
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
47
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
48
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
49
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
50
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
51
+ PERFORMANCE OF THIS SOFTWARE.
52
+ ***************************************************************************** */
53
+ /* global Reflect, Promise, SuppressedError, Symbol */
54
+
55
+
56
+ function __awaiter(thisArg, _arguments, P, generator) {
57
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
58
+ return new (P || (P = Promise))(function (resolve, reject) {
59
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
60
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
61
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
62
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
63
+ });
64
+ }
65
+
66
+ typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
67
+ var e = new Error(message);
68
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
69
+ };
70
+
71
+ /* eslint-disable @typescript-eslint/explicit-function-return-type */
72
+ class TransportHttp {
73
+ loadFile(url) {
74
+ return new Promise((resolve, reject) => {
75
+ const xhr = new XMLHttpRequest();
76
+ xhr.responseType = 'arraybuffer';
77
+ xhr.open('GET', url, true);
78
+ xhr.onload = () => {
79
+ if (xhr.readyState === 4 && xhr.status === 200) {
80
+ resolve(xhr.response);
81
+ }
82
+ else {
83
+ reject(new Error('get failed with status ' + xhr.status));
84
+ }
85
+ };
86
+ xhr.onerror = err => reject(err);
87
+ xhr.send();
88
+ });
89
+ }
90
+ }
91
+
92
+ /*
93
+ * Function for germanic plural. Returns singular (0) for 1 item, and
94
+ * 1 for everything else.
95
+ *
96
+ * @param numItems - number of items
97
+ * @returns the index into the plural translations
98
+ */
99
+ function germanicPlural(numItems) {
100
+ return numItems === 1 ? 0 : 1;
101
+ }
102
+
103
+ /*
104
+ * A minimalistic buffer implementation that can only read 32 bit unsigned
105
+ * integers and strings.
106
+ */
107
+ class DataViewlet {
108
+ /*
109
+ * Create a DataViewlet instance. All encodings that are supported by
110
+ * the runtime environments `TextDecoder` interface.
111
+ *
112
+ * @param array - a `Unit8Array` view on the binary buffer
113
+ * @param encoding - encoding of strings, defaults to utf-8
114
+ */
115
+ constructor(array, encoding = 'utf-8') {
116
+ this.array = array;
117
+ this.decoder = new TextDecoder(encoding);
118
+ this._encoding = encoding;
119
+ }
120
+ /**
121
+ * Get the encoding for strings.
122
+ *
123
+ * @returns the encoding in use
124
+ */
125
+ get encoding() {
126
+ return this._encoding;
127
+ }
128
+ /**
129
+ * Switch to a new encoding.
130
+ *
131
+ * @param encoding - new encoding to use
132
+ */
133
+ set encoding(encoding) {
134
+ this.decoder = new TextDecoder(encoding);
135
+ this._encoding = encoding;
136
+ }
137
+ /*
138
+ * Reads an unsigned 32-bit integer from the buffer at
139
+ * the specified offset as big-endian.
140
+ *
141
+ * @param offset - Number of bytes to skip before starting to read.
142
+ * Must satisfy `0 <= offset <= buf.length - 4`.
143
+ * Default: 0.
144
+ * @returns the 32-bit unsigned integer at position `offset`.s
145
+ */
146
+ readUInt32BE(offset = 0) {
147
+ if (offset + 4 > this.array.byteLength + this.array.byteOffset) {
148
+ throw new Error('read past array end');
149
+ }
150
+ return ((((this.array[offset] << 24) >>> 0) |
151
+ (this.array[offset + 1] << 16) |
152
+ (this.array[offset + 2] << 8) |
153
+ this.array[offset + 3]) >>>
154
+ 0);
155
+ }
156
+ /*
157
+ * Reads an unsigned 32-bit integer from the buffer at
158
+ * the specified offset as little-endian.
159
+ *
160
+ * @param offset - Number of bytes to skip before starting to read.
161
+ * Must satisfy `0 <= offset <= buf.length - 4`.
162
+ * Default: 0.
163
+ * @returns the 32-bit unsigned integer at position `offset`.s
164
+ */
165
+ readUInt32LE(offset = 0) {
166
+ if (offset + 4 > this.array.byteLength + this.array.byteOffset) {
167
+ throw new Error('read past array end');
168
+ }
169
+ return ((((this.array[offset + 3] << 24) >>> 0) |
170
+ (this.array[offset + 2] << 16) |
171
+ (this.array[offset + 1] << 8) |
172
+ this.array[offset]) >>>
173
+ 0);
174
+ }
175
+ /*
176
+ * Read a string at a specified offset.
177
+ *
178
+ * @param offset - to beginning of buffer in bytes
179
+ * @param length - of the string to read in bytes or to the end of the
180
+ * buffer if not specified.
181
+ */
182
+ readString(offset = 0, length) {
183
+ if (offset + length >
184
+ this.array.byteLength + this.array.byteOffset) {
185
+ throw new Error('read past array end');
186
+ }
187
+ if (typeof length === 'undefined') {
188
+ length = this.array.byteLength - offset;
189
+ }
190
+ return this.decoder.decode(this.array.slice(offset, offset + length));
191
+ }
192
+ }
193
+
194
+ /*
195
+ * Parse an MO file.
196
+ *
197
+ * An exception is thrown for invalid data.
198
+ *
199
+ * @param raw - The input as either a binary `String`, any `Array`-like byte
200
+ * storage (`Array`, `Uint8Array`, `Arguments`, `jQuery(Array)`, ...)
201
+ * @returns a Catalog
202
+ */
203
+ function parseMoCatalog(raw) {
204
+ const catalog = {
205
+ major: 0,
206
+ minor: 0,
207
+ entries: {},
208
+ pluralFunction: germanicPlural,
209
+ };
210
+ let offset = 0;
211
+ const blob = new DataViewlet(new Uint8Array(raw), 'ascii');
212
+ const magic = blob.readUInt32LE(offset);
213
+ let reader;
214
+ if (magic === 0x950412de) {
215
+ /* eslint-disable-next-line @typescript-eslint/explicit-function-return-type */
216
+ reader = (buf, off) => buf.readUInt32LE(off);
217
+ }
218
+ else if (magic === 0xde120495) {
219
+ /* eslint-disable-next-line @typescript-eslint/explicit-function-return-type */
220
+ reader = (buf, off) => buf.readUInt32BE(off);
221
+ }
222
+ else {
223
+ throw new Error(`invalid MO magic 0x${magic.toString(16)}`);
224
+ }
225
+ offset += 4;
226
+ // The revision is encoded in two shorts, major and minor. We don't care
227
+ // about the minor revision.
228
+ const major = reader(blob, offset) >> 16;
229
+ offset += 4;
230
+ if (major > 0) {
231
+ throw new Error(`unsupported major revision ${major}`);
232
+ }
233
+ const numStrings = reader(blob, offset);
234
+ offset += 4;
235
+ const msgidOffset = reader(blob, offset);
236
+ offset += 4;
237
+ const msgstrOffset = reader(blob, offset);
238
+ offset = msgidOffset;
239
+ const origTab = [];
240
+ for (let i = 0; i < numStrings; ++i) {
241
+ const l = reader(blob, offset);
242
+ offset += 4;
243
+ const stringOffset = reader(blob, offset);
244
+ offset += 4;
245
+ origTab.push([l, stringOffset]);
246
+ }
247
+ offset = msgstrOffset;
248
+ const transTab = [];
249
+ for (let i = 0; i < numStrings; ++i) {
250
+ const l = reader(blob, offset);
251
+ offset += 4;
252
+ const stringOffset = reader(blob, offset);
253
+ offset += 4;
254
+ transTab.push([l, stringOffset]);
255
+ }
256
+ const poHeader = {};
257
+ for (let i = 0; i < numStrings; ++i) {
258
+ const orig = origTab[i];
259
+ let l = orig[0];
260
+ offset = orig[1];
261
+ const msgid = blob.readString(offset, l).split('\u0000')[0];
262
+ const trans = transTab[i];
263
+ l = trans[0];
264
+ offset = trans[1];
265
+ const msgstr = blob.readString(offset, l).split('\u0000');
266
+ let pairs, kv;
267
+ if (i === 0 && msgid === '') {
268
+ pairs = msgstr[0].split('\n');
269
+ for (let j = 0; j < pairs.length; ++j) {
270
+ if (pairs[j] !== '') {
271
+ kv = pairs[j].split(/[ \t]*:[ \t]*/);
272
+ poHeader[kv[0].toLowerCase()] = kv[1];
273
+ }
274
+ }
275
+ if (poHeader['content-type'] !== undefined) {
276
+ const enc = poHeader['content-type'].replace(/.*=/, '');
277
+ if (enc !== poHeader['content-type']) {
278
+ blob.encoding = enc;
279
+ }
280
+ }
281
+ }
282
+ catalog.entries[msgid] = msgstr;
283
+ }
284
+ return catalog;
285
+ }
286
+
287
+ function validateMoJsonCatalog(udata) {
288
+ // We could use ajv but it results in almost 300 k minimized code
289
+ // for the browser bundle. This validator instead is absolutely
290
+ // minimalistic, and only avoids exceptions that can occur, when
291
+ // accessing entries.
292
+ if (udata === null || typeof udata === 'undefined') {
293
+ throw new Error('catalog is either null or undefined');
294
+ }
295
+ const data = udata;
296
+ if (data.constructor !== Object) {
297
+ throw new Error('catalog must be a dictionary');
298
+ }
299
+ // We don't care about major and minor because they are actually not
300
+ // used.
301
+ if (!Object.prototype.hasOwnProperty.call(data, 'entries')) {
302
+ throw new Error('catalog.entries does not exist');
303
+ }
304
+ const entries = data.entries;
305
+ if (entries === null || typeof entries === 'undefined') {
306
+ throw new Error('catalog.entries are not defined or null');
307
+ }
308
+ if (entries.constructor !== Object) {
309
+ throw new Error('catalog.entries must be a dictionary');
310
+ }
311
+ for (const [key, value] of Object.entries(entries)) {
312
+ if (!Array.isArray(value)) {
313
+ throw new Error(`catalog entry for key '${key}' is not an array`);
314
+ }
315
+ }
316
+ return data;
317
+ }
318
+ function parseMoJsonCatalog(json) {
319
+ const text = new TextDecoder().decode(json);
320
+ const data = JSON.parse(text);
321
+ return validateMoJsonCatalog(data);
322
+ }
323
+
324
+ function validateJsonCatalog(udata) {
325
+ // We could use ajv but it results in almost 300 k minimized code
326
+ // for the browser bundle. This validator instead is absolutely
327
+ // minimalistic, and only avoids exceptions that can occur, when
328
+ // accessing entries.
329
+ if (udata === null || typeof udata === 'undefined') {
330
+ throw new Error('catalog is either null or undefined');
331
+ }
332
+ const entries = udata;
333
+ if (entries.constructor !== Object) ;
334
+ // Convert to a regular catalog.
335
+ const catalog = {
336
+ major: 0,
337
+ minor: 1,
338
+ pluralFunction: () => 0,
339
+ entries: {},
340
+ };
341
+ for (const [msgid, msgstr] of Object.entries(entries)) {
342
+ // Just stringify all values but do not complain.
343
+ catalog.entries[msgid] = [msgstr.toString()];
344
+ }
345
+ return catalog;
346
+ }
347
+ function parseJsonCatalog(json) {
348
+ const text = new TextDecoder().decode(json);
349
+ const data = JSON.parse(text);
350
+ return validateJsonCatalog(data);
351
+ }
352
+
353
+ const tagHyphenRegex = new RegExp('^[a-z0-9]+(?:-[a-z0-9]+)*$', 'i');
354
+ const tagUnderscoreRegex = new RegExp('^[a-z0-9]+(?:_[a-z0-9]+)*$', 'i');
355
+ function splitLocale(locale) {
356
+ let charset = '', modifier = '';
357
+ const underscoreSeparator = locale.includes('_');
358
+ locale = locale.replace(/@([a-z]+)$/i, (_, match) => {
359
+ modifier = match;
360
+ return '';
361
+ });
362
+ locale = locale.replace(/\.([-0-9a-z]+)$/i, (_, match) => {
363
+ charset = match;
364
+ return '';
365
+ });
366
+ if (underscoreSeparator) {
367
+ if (!tagUnderscoreRegex.exec(locale)) {
368
+ return null;
369
+ }
370
+ }
371
+ else {
372
+ if (!tagHyphenRegex.exec(locale)) {
373
+ return null;
374
+ }
375
+ }
376
+ const separator = underscoreSeparator ? '_' : '-';
377
+ const tags = locale.split(separator);
378
+ const split = { tags: tags, underscoreSeparator };
379
+ if (charset.length) {
380
+ split.charset = charset;
381
+ }
382
+ if (modifier.length) {
383
+ split.modifier = modifier;
384
+ }
385
+ return split;
386
+ }
387
+
388
+ /*
389
+ * Caches catalog lookups by path, locale, and textdomain.
390
+ *
391
+ * Failed lookups are stored as null values.
392
+ *
393
+ * It is also possible to store a Promise. In that case, if a request is
394
+ * made to bind the textdomain, the promise is settled. Note that this
395
+ * mechanism is never used for message lookup but only for loading the
396
+ * catalog via resolve.
397
+ */
398
+ class CatalogCache {
399
+ constructor() {
400
+ /* Singleton. */
401
+ }
402
+ static getInstance() {
403
+ if (!CatalogCache.instance) {
404
+ CatalogCache.instance = new CatalogCache();
405
+ }
406
+ return CatalogCache.instance;
407
+ }
408
+ static clear() {
409
+ CatalogCache.cache = {};
410
+ }
411
+ /**
412
+ * Lookup a Catalog for a given base path, locale, and textdomain.
413
+ *
414
+ * The locale key is usually the locale identifier (e.g. de-DE or sr\@latin).
415
+ * But it can also be a colon separated list of such locale identifiers.
416
+ *
417
+ *
418
+ * @param localeKey - the locale key
419
+ * @param textdomain - the textdomain
420
+ * @returns the cached Catalog, a Promise or null for failure
421
+ */
422
+ static lookup(localeKey, textdomain) {
423
+ if (CatalogCache.cache[localeKey]) {
424
+ const ptr = CatalogCache.cache[localeKey];
425
+ if (Object.prototype.hasOwnProperty.call(ptr, textdomain)) {
426
+ return ptr[textdomain];
427
+ }
428
+ }
429
+ return null;
430
+ }
431
+ static store(localeKey, textdomain, entry) {
432
+ if (Promise.resolve(entry) !== entry) {
433
+ // Object.
434
+ entry = validateMoJsonCatalog(entry);
435
+ }
436
+ if (!CatalogCache.cache[localeKey]) {
437
+ CatalogCache.cache[localeKey] = {};
438
+ }
439
+ CatalogCache.cache[localeKey][textdomain] = entry;
440
+ }
441
+ }
442
+ CatalogCache.cache = {};
443
+
444
+ function explodeLocale(locale, vary) {
445
+ const retval = [];
446
+ const lsep = locale.underscoreSeparator ? '_' : '-';
447
+ let i = 0 ;
448
+ const hasCharset = typeof locale.charset !== 'undefined';
449
+ const hasModifier = typeof locale.modifier !== 'undefined';
450
+ const charsets = hasCharset ? [locale.charset] : [''];
451
+ if (hasCharset) {
452
+ const charset = locale.charset;
453
+ const ucCharset = charset.toUpperCase();
454
+ if (ucCharset !== charset) {
455
+ charsets.push(ucCharset);
456
+ }
457
+ charsets.push('');
458
+ }
459
+ for (; i < locale.tags.length; ++i) {
460
+ const lingua = locale.tags.slice(0, i + 1).join(lsep);
461
+ const ids = new Array();
462
+ charsets.forEach(charset => {
463
+ let id = charset.length ? lingua + '.' + charset : lingua;
464
+ if (hasModifier) {
465
+ id += '@' + locale.modifier;
466
+ }
467
+ ids.push(id);
468
+ });
469
+ retval.push(ids);
470
+ }
471
+ return retval;
472
+ }
473
+
474
+ function loadCatalog(url, format) {
475
+ return __awaiter(this, void 0, void 0, function* () {
476
+ let transportInstance;
477
+ {
478
+ transportInstance = new TransportHttp();
479
+ }
480
+ let validator;
481
+ if ('mo.json' === format) {
482
+ validator = parseMoJsonCatalog;
483
+ }
484
+ else if ('.json' === format) {
485
+ validator = parseJsonCatalog;
486
+ }
487
+ else {
488
+ validator = parseMoCatalog;
489
+ }
490
+ try {
491
+ const data = yield transportInstance.loadFile(url);
492
+ return validator(data);
493
+ }
494
+ catch (_a) {
495
+ return null;
496
+ }
497
+ });
498
+ }
499
+ function assemblePath(base, id, domainname, extender) {
500
+ return `${base}/${id}/LC_MESSAGES/${domainname}.${extender}`;
501
+ }
502
+ function loadLanguageFromObject(ids, base, domainname) {
503
+ return __awaiter(this, void 0, void 0, function* () {
504
+ for (let i = 0; i < ids.length; ++i) {
505
+ const id = ids[i];
506
+ // Language exists?
507
+ if (!Object.prototype.hasOwnProperty.call(base, id)) {
508
+ continue;
509
+ }
510
+ // LC_MESSAGES?
511
+ if (!Object.prototype.hasOwnProperty.call(base[id], 'LC_MESSAGES')) {
512
+ continue;
513
+ }
514
+ // Textdomain?
515
+ if (!Object.prototype.hasOwnProperty.call(base[id].LC_MESSAGES, domainname)) {
516
+ continue;
517
+ }
518
+ return base[id].LC_MESSAGES[domainname];
519
+ }
520
+ return null;
521
+ });
522
+ }
523
+ /*
524
+ * First tries to load a catalog with the specified charset, then with the
525
+ * charset converted to uppercase (if it differs from the original charset),
526
+ * and finally without a charset.
527
+ */
528
+ function loadLanguage(ids, base, domainname, format) {
529
+ return __awaiter(this, void 0, void 0, function* () {
530
+ // Check if `base` is an object (LocaleContainer).
531
+ if (typeof base === 'object' && base !== null) {
532
+ return loadLanguageFromObject(ids, base, domainname);
533
+ }
534
+ for (const id of ids) {
535
+ const catalog = yield loadCatalog(assemblePath(base, id, domainname, format), format);
536
+ if (catalog) {
537
+ return catalog;
538
+ }
539
+ }
540
+ return null;
541
+ });
542
+ }
543
+ function loadDomain(exploded, localeKey, base, domainname, format) {
544
+ return __awaiter(this, void 0, void 0, function* () {
545
+ const entries = {};
546
+ const catalog = {
547
+ major: 0,
548
+ minor: 0,
549
+ pluralFunction: germanicPlural,
550
+ entries,
551
+ };
552
+ const cacheHit = yield CatalogCache.lookup(localeKey, domainname);
553
+ if (cacheHit !== null) {
554
+ return cacheHit;
555
+ }
556
+ for (const tries of exploded) {
557
+ const result = yield loadLanguage(tries, base, domainname, format);
558
+ if (result) {
559
+ catalog.major = result.major;
560
+ catalog.minor = result.minor;
561
+ catalog.entries = Object.assign(Object.assign({}, catalog.entries), result.entries);
562
+ }
563
+ }
564
+ return catalog;
565
+ });
566
+ }
567
+ function pluralExpression(str) {
568
+ const tokens = str
569
+ .replace(/[ \t\r\013\014]/g, '')
570
+ .replace(/;$/, '')
571
+ // Do NOT allow square brackets here. JSFuck!
572
+ .split(/[<>!=]=|&&|\|\||[-!*/%+<>=?:;]/);
573
+ for (let i = 0; i < tokens.length; ++i) {
574
+ const token = tokens[i].replace(/^\(+/, '').replace(/\)+$/, '');
575
+ if (token !== 'nplurals' &&
576
+ token !== 'plural' &&
577
+ token !== 'n' &&
578
+ // Does not catch invalid octal numbers but the compiler
579
+ // takes care of that.
580
+ null === /^[0-9]+$/.exec(token)) {
581
+ throw new Error('invalid plural function');
582
+ }
583
+ }
584
+ const code = 'var nplurals = 1, plural = 0;' + str + '; return 0 + plural';
585
+ // This may throw an exception!
586
+ // eslint-disable-next-line @typescript-eslint/no-implied-eval
587
+ return new Function('n', code);
588
+ }
589
+ function setPluralFunction(catalog) {
590
+ if (!Object.prototype.hasOwnProperty.call(catalog.entries, '')) {
591
+ return catalog;
592
+ }
593
+ const headers = catalog.entries[''][0].split('\n');
594
+ headers.forEach(header => {
595
+ const tokens = header.split(':');
596
+ if ('plural-forms' === tokens.shift().toLowerCase()) {
597
+ const code = tokens.join(':');
598
+ try {
599
+ catalog.pluralFunction = pluralExpression(code);
600
+ }
601
+ catch (_a) {
602
+ catalog.pluralFunction = germanicPlural;
603
+ }
604
+ }
605
+ });
606
+ return catalog;
607
+ }
608
+ function resolveImpl(domainname, path, format, localeKey) {
609
+ return __awaiter(this, void 0, void 0, function* () {
610
+ const defaultCatalog = {
611
+ major: 0,
612
+ minor: 0,
613
+ pluralFunction: germanicPlural,
614
+ entries: {},
615
+ };
616
+ if (localeKey === 'C' || localeKey === 'POSIX') {
617
+ return defaultCatalog;
618
+ }
619
+ const exploded = explodeLocale(splitLocale(localeKey));
620
+ const catalog = yield loadDomain(exploded, localeKey, path, domainname, format);
621
+ setPluralFunction(catalog);
622
+ CatalogCache.store(localeKey, domainname, catalog);
623
+ return catalog;
624
+ });
625
+ }
626
+
627
+ function gettextImpl(args) {
628
+ var _a;
629
+ const key = typeof args.msgctxt === 'undefined'
630
+ ? args.msgid
631
+ : args.msgctxt + '\u0004' + args.msgid;
632
+ const translations = args.catalog.entries[key];
633
+ const numItems = (_a = args.numItems) !== null && _a !== void 0 ? _a : 1;
634
+ if (translations && translations.length) {
635
+ if (typeof args.msgidPlural === 'undefined') {
636
+ return translations[0];
637
+ }
638
+ else {
639
+ let pluralForm = args.catalog.pluralFunction(numItems);
640
+ if (pluralForm >= translations.length) {
641
+ if (translations.length === 1) {
642
+ return translations[0];
643
+ }
644
+ else {
645
+ pluralForm = germanicPlural(numItems);
646
+ }
647
+ }
648
+ return translations[pluralForm];
649
+ }
650
+ }
651
+ else if (typeof args.msgidPlural !== 'undefined') {
652
+ const pluralform = args.catalog.pluralFunction(numItems);
653
+ if (pluralform === 1) {
654
+ return args.msgidPlural;
655
+ }
656
+ }
657
+ return args.msgid;
658
+ }
659
+
660
+ const isNode = typeof process !== 'undefined' &&
661
+ process.versions !== null &&
662
+ process.versions.node !== null;
663
+ const pathSeparator = isNode && process.platform === 'win32' ? '\\' : '/';
664
+
665
+ function tagsEqual(left, right) {
666
+ if (left.length !== right.length) {
667
+ return false;
668
+ }
669
+ for (let i = 0; i < left.length; ++i) {
670
+ if (left[i].toLowerCase() !== right[i].toLowerCase()) {
671
+ return false;
672
+ }
673
+ }
674
+ return true;
675
+ }
676
+ function selectLocale(supported, requested) {
677
+ let languageMatch = '';
678
+ for (let i = 0; i < requested.length; ++i) {
679
+ const wanted = splitLocale(requested[i]);
680
+ if (!wanted) {
681
+ continue;
682
+ }
683
+ for (let j = 0; j < supported.length; ++j) {
684
+ const got = splitLocale(supported[j]);
685
+ if (!got) {
686
+ continue;
687
+ }
688
+ if (tagsEqual(wanted.tags, got.tags)) {
689
+ return supported[j];
690
+ }
691
+ if (!languageMatch.length &&
692
+ wanted.tags[0].toLowerCase() === got.tags[0].toLowerCase()) {
693
+ languageMatch = supported[j];
694
+ }
695
+ }
696
+ }
697
+ if (languageMatch.length) {
698
+ return languageMatch;
699
+ }
700
+ return 'C';
701
+ }
702
+
703
+ /**
704
+ * A Textdomain is a container for an esgettext configuration and all loaded
705
+ * LocaleContainer for the textual domain selected.
706
+ *
707
+ * The actual translation methods have quite funny names like `_()` or
708
+ * `_x()`. The purpose of this naming convention is to make the
709
+ * internationalization of your programs as little obtrusive as possible.
710
+ * Most of the times you just have to exchange
711
+ *
712
+ * ```
713
+ * doSomething('Hello, world!');
714
+ * ```
715
+ *
716
+ * with
717
+ *
718
+ * ```
719
+ * doSomething(gtx._('Hello, world!'));
720
+ * ```
721
+ *
722
+ * Besides, depending on the string extractor you are using, it may be useful
723
+ * that the method names do not collide with method names from other packages.
724
+ */
725
+ class Textdomain {
726
+ /**
727
+ * Retrieve a translation for a string.
728
+ *
729
+ * @param msgid - the string to translate
730
+ *
731
+ * @returns the translated string
732
+ */
733
+ _(msgid) {
734
+ return gettextImpl({ msgid: msgid, catalog: this.catalog });
735
+ }
736
+ /**
737
+ * Retrieve a translation for a string containing a possible plural.
738
+ * You will almost always want to call {@link _nx} instead so that
739
+ * you can interpolate the number of items into the strings.
740
+ *
741
+ * @param msgid - the string in the singular
742
+ * @param msgidPlural - the string in the plural
743
+ * @param numItems - the number of items
744
+ *
745
+ * @returns the translated string
746
+ */
747
+ _n(msgid, msgidPlural, numItems) {
748
+ return gettextImpl({
749
+ msgid: msgid,
750
+ msgidPlural: msgidPlural,
751
+ numItems: numItems,
752
+ catalog: this.catalog,
753
+ });
754
+ }
755
+ /**
756
+ * Translate a string with a context.
757
+ *
758
+ * @param msgctxt - the message context
759
+ * @param msgid - the string to translate
760
+ *
761
+ * @returns the translated string
762
+ */
763
+ _p(msgctxt, msgid) {
764
+ return gettextImpl({
765
+ msgctxt: msgctxt,
766
+ msgid: msgid,
767
+ catalog: this.catalog,
768
+ });
769
+ }
770
+ /**
771
+ * The method `_np()` combines `_n()` with `_p()`.
772
+ * You will almost always want to call {@link _npx} instead so that
773
+ * you can interpolate the number of items into the strings.
774
+
775
+ *
776
+ * @param msgctxt - the message context
777
+ * @param msgid - the message id
778
+ * @param placeholders - a dictionary with placehoders
779
+ * @returns the translated string
780
+ */
781
+ _np(msgctxt, msgid, msgidPlural, numItems) {
782
+ return gettextImpl({
783
+ msgctxt: msgctxt,
784
+ msgid: msgid,
785
+ msgidPlural: msgidPlural,
786
+ numItems: numItems,
787
+ catalog: this.catalog,
788
+ });
789
+ }
790
+ /**
791
+ * Translate a string with placeholders. The placeholders should be
792
+ * wrapped into curly braces and must match the regular expression
793
+ * "[_a-zA-Z][_a-zA-Z0-9]*".
794
+ *
795
+ * @param msgid - the msgid to translate
796
+ * @param placeholders - an optional dictionary of placeholders
797
+ *
798
+ * @returns the translated string with placeholders expanded
799
+ */
800
+ _x(msgid, placeholders) {
801
+ return Textdomain.expand(gettextImpl({ msgid: msgid, catalog: this.catalog }), placeholders || {});
802
+ }
803
+ /**
804
+ * Translate a string with a plural expression with placeholders.
805
+ *
806
+ * @param msgid - the string in the singular
807
+ * @param msgidPlural - the string in the plural
808
+ * @param numItems - the number of items
809
+ * @param placeholders - an optional dictionary of placeholders
810
+ *
811
+ * @returns the translated string
812
+ */
813
+ _nx(msgid, msgidPlural, numItems, placeholders) {
814
+ return Textdomain.expand(gettextImpl({
815
+ msgid: msgid,
816
+ msgidPlural: msgidPlural,
817
+ numItems: numItems,
818
+ catalog: this.catalog,
819
+ }), placeholders || {});
820
+ }
821
+ /**
822
+ * The method `_px()` combines `_p()` with `_x()`.
823
+ *
824
+ * @param msgctxt - the message context
825
+ * @param msgid - the message id
826
+ * @param placeholders - an optional dictionary with placehoders
827
+ * @returns the translated string
828
+ */
829
+ _px(msgctxt, msgid, placeholders) {
830
+ return Textdomain.expand(gettextImpl({ msgctxt: msgctxt, msgid: msgid, catalog: this.catalog }), placeholders || {});
831
+ }
832
+ /**
833
+ * The method `_npx()` brings it all together. It combines `_n()` and
834
+ * `_p()` and `_x()`.
835
+ *
836
+ * @param msgctxt - the message context
837
+ * @param msgid - the message id
838
+ * @param msgidPlural - the plural string
839
+ * @param numItems - the number of items
840
+ * @param placeholders - an optional dictionary with placehoders
841
+ * @returns the translated string
842
+ */
843
+ _npx(msgctxt, msgid, msgidPlural, numItems, placeholders) {
844
+ return Textdomain.expand(gettextImpl({
845
+ msgctxt: msgctxt,
846
+ msgid: msgid,
847
+ msgidPlural: msgidPlural,
848
+ numItems: numItems,
849
+ catalog: this.catalog,
850
+ }), placeholders || {});
851
+ }
852
+ static getCatalog(locale, textdomain) {
853
+ const catalog = CatalogCache.lookup(locale, textdomain);
854
+ if (!catalog || Promise.resolve(catalog) === catalog) {
855
+ return {
856
+ major: 0,
857
+ minor: 0,
858
+ pluralFunction: germanicPlural,
859
+ entries: {},
860
+ };
861
+ }
862
+ return catalog;
863
+ }
864
+ /**
865
+ * Retrieve a translation for a string with a fixed locale.
866
+ *
867
+ * @param locale - the locale identifier
868
+ * @param msgid - the string to translate
869
+ *
870
+ * @returns the translated string
871
+ */
872
+ _l(locale, msgid) {
873
+ const catalog = Textdomain.getCatalog(locale, this.textdomain());
874
+ return gettextImpl({ msgid: msgid, catalog: catalog });
875
+ }
876
+ /**
877
+ * Retrieve a translation for a string containing a possible plural with
878
+ * a fixed locale.
879
+ * You will almost always want to call {@link _nx} instead so that
880
+ * you can interpolate the number of items into the strings.
881
+ *
882
+ * @param locale - the locale identifier
883
+ * @param msgid - the string in the singular
884
+ * @param msgidPlural - the string in the plural
885
+ * @param numItems - the number of items
886
+ *
887
+ * @returns the translated string
888
+ */
889
+ _ln(locale, msgid, msgidPlural, numItems) {
890
+ const catalog = Textdomain.getCatalog(locale, this.textdomain());
891
+ return gettextImpl({
892
+ msgid: msgid,
893
+ msgidPlural: msgidPlural,
894
+ numItems: numItems,
895
+ catalog: catalog,
896
+ });
897
+ }
898
+ /**
899
+ * Translate a string with a context with a fixed locale.
900
+ *
901
+ * @param locale - the locale identifier
902
+ * @param msgctxt - the message context
903
+ * @param msgid - the string to translate
904
+ *
905
+ * @returns the translated string
906
+ */
907
+ _lp(locale, msgctxt, msgid) {
908
+ const catalog = Textdomain.getCatalog(locale, this.textdomain());
909
+ return gettextImpl({ msgctxt: msgctxt, msgid: msgid, catalog: catalog });
910
+ }
911
+ /**
912
+ * The method `_lnp()` combines `_ln()` with `_lp()`.
913
+ * You will almost always want to call {@link _npx} instead so that
914
+ * you can interpolate the number of items into the strings.
915
+
916
+ *
917
+ * @param locale - the locale identifier
918
+ * @param msgctxt - the message context
919
+ * @param msgid - the message id
920
+ * @param placeholders - a dictionary with placehoders
921
+ * @returns the translated string
922
+ */
923
+ _lnp(locale, msgctxt, msgid, msgidPlural, numItems) {
924
+ const catalog = Textdomain.getCatalog(locale, this.textdomain());
925
+ return gettextImpl({
926
+ msgctxt: msgctxt,
927
+ msgid: msgid,
928
+ msgidPlural: msgidPlural,
929
+ numItems: numItems,
930
+ catalog: catalog,
931
+ });
932
+ }
933
+ /**
934
+ * Translate a string with placeholders for a fixed locale.
935
+ * The placeholders should be
936
+ * wrapped into curly braces and must match the regular expression
937
+ * "[_a-zA-Z][_a-zA-Z0-9]*".
938
+ *
939
+ * @param locale - the locale identifier
940
+ * @param msgid - the msgid to translate
941
+ * @param placeholders - an optional dictionary of placeholders
942
+ *
943
+ * @returns the translated string with placeholders expanded
944
+ */
945
+ _lx(locale, msgid, placeholders) {
946
+ const catalog = Textdomain.getCatalog(locale, this.textdomain());
947
+ return Textdomain.expand(gettextImpl({ msgid: msgid, catalog: catalog }), placeholders || {});
948
+ }
949
+ /**
950
+ * Translate a string with a plural expression with placeholders into a
951
+ * fixed locale.
952
+ *
953
+ * @param locale - the locale identifier
954
+ * @param msgid - the string in the singular
955
+ * @param msgidPlural - the string in the plural
956
+ * @param numItems - the number of items
957
+ * @param placeholders - an optional dictionary of placeholders
958
+ *
959
+ * @returns the translated string
960
+ */
961
+ _lnx(locale, msgid, msgidPlural, numItems, placeholders) {
962
+ const catalog = Textdomain.getCatalog(locale, this.textdomain());
963
+ return Textdomain.expand(gettextImpl({
964
+ msgid: msgid,
965
+ msgidPlural: msgidPlural,
966
+ numItems: numItems,
967
+ catalog: catalog,
968
+ }), placeholders || {});
969
+ }
970
+ /**
971
+ * The method `_lpx()` combines `_lp()` with `_lx()`.
972
+ *
973
+ * @param locale - the locale identifier
974
+ * @param msgctxt - the message context
975
+ * @param msgid - the message id
976
+ * @param placeholders - an optional dictionary with placehoders
977
+ * @returns the translated string
978
+ */
979
+ _lpx(locale, msgctxt, msgid, placeholders) {
980
+ const catalog = Textdomain.getCatalog(locale, this.textdomain());
981
+ return Textdomain.expand(gettextImpl({ msgctxt: msgctxt, msgid: msgid, catalog: catalog }), placeholders || {});
982
+ }
983
+ /**
984
+ * The method `_lnpx()` brings it all together. It combines `_ln()` and
985
+ * `_lp()` and `_lx()`.
986
+ *
987
+ * @param locale - the locale identifier
988
+ * @param msgctxt - the message context
989
+ * @param msgid - the message id
990
+ * @param msgidPlural - the plural string
991
+ * @param numItems - the number of items
992
+ * @param placeholders - an optional dictionary with placehoders
993
+ * @returns the translated string
994
+ */
995
+ _lnpx(locale, msgctxt, msgid, msgidPlural, numItems, placeholders) {
996
+ const catalog = Textdomain.getCatalog(locale, this.textdomain());
997
+ return Textdomain.expand(gettextImpl({
998
+ msgctxt: msgctxt,
999
+ msgid: msgid,
1000
+ msgidPlural: msgidPlural,
1001
+ numItems: numItems,
1002
+ catalog: catalog,
1003
+ }), placeholders || {});
1004
+ }
1005
+ static expand(msg, placeholders) {
1006
+ return msg.replace(/\{([a-zA-Z][0-9a-zA-Z]*)\}/g, (_, match) => {
1007
+ if (Object.prototype.hasOwnProperty.call(placeholders, match)) {
1008
+ return placeholders[match];
1009
+ }
1010
+ else {
1011
+ return `{${match}}`;
1012
+ }
1013
+ });
1014
+ }
1015
+ /**
1016
+ * Instantiate a Textdomain object. Textdomain objects are singletons
1017
+ * for each textdomain identifier.
1018
+ *
1019
+ * @param textdomain - the textdomain of your application or library.
1020
+ *
1021
+ * @returns a [[`Textdomain`]]
1022
+ */
1023
+ static getInstance(textdomain) {
1024
+ if (typeof textdomain === 'undefined' ||
1025
+ textdomain === null ||
1026
+ textdomain === '') {
1027
+ throw new Error('Cannot instantiate TextDomain without a textdomain');
1028
+ }
1029
+ if (Object.prototype.hasOwnProperty.call(Textdomain.domains, textdomain)) {
1030
+ return Textdomain.domains[textdomain];
1031
+ }
1032
+ else {
1033
+ const domain = new Textdomain(textdomain);
1034
+ Textdomain.domains[textdomain] = domain;
1035
+ domain.catalog = {
1036
+ major: 0,
1037
+ minor: 0,
1038
+ pluralFunction: germanicPlural,
1039
+ entries: {},
1040
+ };
1041
+ return domain;
1042
+ }
1043
+ }
1044
+ /**
1045
+ * Delete all existing singletons. This method should usually be called
1046
+ * only, when you want to free memory.
1047
+ */
1048
+ static clearInstances() {
1049
+ Textdomain.boundDomains = {};
1050
+ }
1051
+ /**
1052
+ * This method is used for testing. Do not use it yourself!
1053
+ */
1054
+ static forgetInstances() {
1055
+ Textdomain.clearInstances();
1056
+ Textdomain.domains = {};
1057
+ }
1058
+ /**
1059
+ * Query the locale in use.
1060
+ */
1061
+ static get locale() {
1062
+ return Textdomain._locale;
1063
+ }
1064
+ /**
1065
+ * Change the locale.
1066
+ *
1067
+ * For the web you can use all valid language identifier tags that
1068
+ * [BCP47](https://tools.ietf.org/html/bcp47) allows
1069
+ * (and actually a lot more). The tag is always used unmodified.
1070
+ *
1071
+ * For server environments, the locale identifier has to match the following
1072
+ * scheme:
1073
+ *
1074
+ * `ll_CC.charset\@modifier`
1075
+ *
1076
+ * * `ll` is the two- or three-letter language code.
1077
+ * * `CC` is the optional two-letter country code.
1078
+ * * `charset` is an optional character set (letters, digits, and the hyphen).
1079
+ * * `modifier` is an optional variant (letters and digits).
1080
+ *
1081
+ * The language code is always converted to lowercase, the country code is
1082
+ * converted to uppercase, variant and charset are used as is.
1083
+ *
1084
+ * @param locale - the locale identifier
1085
+ * @returns the locale in use
1086
+ */
1087
+ static set locale(locale) {
1088
+ const ucLocale = locale.toUpperCase();
1089
+ if (ucLocale === 'POSIX' || ucLocale === 'C') {
1090
+ this._locale = 'POSIX';
1091
+ return;
1092
+ }
1093
+ const split = splitLocale(locale);
1094
+ if (!split) {
1095
+ throw new Error('invalid locale identifier');
1096
+ }
1097
+ // The check from splitLocale() is sufficient.
1098
+ if (browserEnvironment()) {
1099
+ this._locale = locale;
1100
+ return;
1101
+ }
1102
+ // Node.
1103
+ split.tags[0] = split.tags[0].toLowerCase();
1104
+ if (split.tags.length > 1) {
1105
+ split.tags[1] = split.tags[1].toUpperCase();
1106
+ }
1107
+ const separator = split.underscoreSeparator ? '_' : '-';
1108
+ this._locale = split.tags.join(separator);
1109
+ if (typeof split.charset !== 'undefined') {
1110
+ this._locale += '.' + split.charset;
1111
+ }
1112
+ if (typeof split.modifier !== 'undefined') {
1113
+ this._locale += '@' + split.modifier;
1114
+ }
1115
+ }
1116
+ constructor(domain) {
1117
+ this._catalogFormat = 'mo.json';
1118
+ this.catalog = undefined;
1119
+ this.domain = domain;
1120
+ const msg = "The property 'locale' is not an instance property but static. Use 'Textdomain.locale' instead!";
1121
+ Object.defineProperty(this, 'locale', {
1122
+ get: () => {
1123
+ throw new Error(msg);
1124
+ },
1125
+ set: () => {
1126
+ throw new Error(msg);
1127
+ },
1128
+ enumerable: true,
1129
+ configurable: true,
1130
+ });
1131
+ }
1132
+ /**
1133
+ * A textdomain is an identifier for your application or library. It is
1134
+ * the basename of your translation files which are either
1135
+ * TEXTDOMAIN.mo.json or TEXTDOMAIN.mo, depending on the format you have
1136
+ * chosen.
1137
+ *
1138
+ * FIXME! This should be a getter!
1139
+ *
1140
+ * @returns the textdomain
1141
+ */
1142
+ textdomain() {
1143
+ return this.domain;
1144
+ }
1145
+ /**
1146
+ * Bind a textdomain to a certain path or queries the path that a
1147
+ * textdomain is bound to. The catalog file will be searched
1148
+ * in `${path}/LC_MESSAGES/${domainname}.EXT` where `EXT` is the
1149
+ * selected catalog format (one of `mo.json`, `mo`, or `json`).
1150
+ *
1151
+ * Alternatively, you can pass a [[`LocaleContainer`]] that holds the
1152
+ * catalogs in memory.
1153
+ *
1154
+ * The returned string or `LocaleContainer` is valid until the next
1155
+ * `bindtextdomain` call with an argument.
1156
+ *
1157
+ * @param path - the base path or [[`LocaleContainer`]] for this textdomain
1158
+ *
1159
+ * @returns the current base directory or [[`LocaleContainer`]] for this domain, after possibly changing it.
1160
+ */
1161
+ bindtextdomain(path) {
1162
+ if (typeof path !== 'undefined') {
1163
+ Textdomain.boundDomains[this.domain] = path;
1164
+ }
1165
+ return Textdomain.boundDomains[this.domain];
1166
+ }
1167
+ /**
1168
+ * Resolve a textdomain, i.e. load the LocaleContainer for this domain and all
1169
+ * of its dependencies for the currently selected locale or the locale
1170
+ * specified.
1171
+ *
1172
+ * The promise will always resolve. If no catalog was found, an empty
1173
+ * catalog will be returned that is still usable.
1174
+ *
1175
+ * @param locale - an optional locale identifier, defaults to Textdomain.locale
1176
+ *
1177
+ * @returns a promise for a Catalog that will always resolve.
1178
+ */
1179
+ resolve(locale) {
1180
+ return __awaiter(this, void 0, void 0, function* () {
1181
+ const promises = [this.resolve1(locale)];
1182
+ for (const td in Textdomain.domains) {
1183
+ if (Object.prototype.hasOwnProperty.call(Textdomain.domains, td) &&
1184
+ Textdomain.domains[td] !== this) {
1185
+ promises.push(Textdomain.domains[td].resolve1(locale));
1186
+ }
1187
+ }
1188
+ return Promise.all(promises).then(values => {
1189
+ return new Promise(resolve => resolve(values[0]));
1190
+ });
1191
+ });
1192
+ }
1193
+ resolve1(locale) {
1194
+ return __awaiter(this, void 0, void 0, function* () {
1195
+ let path = this.bindtextdomain();
1196
+ if (typeof path === 'undefined' || path === null) {
1197
+ const parts = browserEnvironment()
1198
+ ? ['', 'assets', 'locale']
1199
+ : ['.', 'locale'];
1200
+ path = parts.join(pathSeparator);
1201
+ }
1202
+ const resolvedLocale = locale ? locale : Textdomain.locale;
1203
+ return resolveImpl(this.domain, path, this.catalogFormat, resolvedLocale).then(catalog => {
1204
+ if (!locale) {
1205
+ this.catalog = catalog;
1206
+ }
1207
+ return new Promise(resolve => resolve(catalog));
1208
+ });
1209
+ });
1210
+ }
1211
+ /**
1212
+ * Get the catalog format in use.
1213
+ *
1214
+ * @returns one of 'mo.json' or 'mo' (default is 'mo.json')
1215
+ */
1216
+ get catalogFormat() {
1217
+ return this._catalogFormat;
1218
+ }
1219
+ /**
1220
+ * Set the catalog format to use.
1221
+ *
1222
+ * @param format - one of 'mo.json' or 'mo'
1223
+ */
1224
+ set catalogFormat(format) {
1225
+ format = format.toLowerCase();
1226
+ if (format === 'mo.json') {
1227
+ this._catalogFormat = 'mo.json';
1228
+ }
1229
+ else if (format === 'mo') {
1230
+ this._catalogFormat = 'mo';
1231
+ }
1232
+ else {
1233
+ throw new Error(`unsupported format ${format}`);
1234
+ }
1235
+ }
1236
+ /**
1237
+ * Queries the user's preferred locales. On the server it queries the
1238
+ * environment variables `LANGUAGE`, `LC_ALL`, `LANG`, and `LC_MESSAGES`
1239
+ * (in that order). In the browser, it parses it checks the user preferences
1240
+ * in the variables `navigator.languages`, `navigator.language`,
1241
+ * `navigator.userLanguage`, `navigator.browserLanguage`, and
1242
+ * `navigator.systemLanguage`.
1243
+ *
1244
+ * @returns the set of locales in order of preference
1245
+ *
1246
+ * Added in \@runtime 0.1.0.
1247
+ */
1248
+ static userLocales() {
1249
+ return userLocales();
1250
+ }
1251
+ /**
1252
+ * Select one of the supported locales from a list of locales accepted by
1253
+ * the user.
1254
+ *
1255
+ * @param supported - the list of locales supported by the application
1256
+ * @param requested - the list of locales accepted by the user
1257
+ *
1258
+ * If called with just one argument, then the list of requested locales
1259
+ * is determined by calling [[Textdomain.userLocales]].
1260
+ *
1261
+ * @returns the negotiated locale or 'C' if not possible.
1262
+ */
1263
+ static selectLocale(supported, requested) {
1264
+ return selectLocale(supported, requested !== null && requested !== void 0 ? requested : Textdomain.userLocales());
1265
+ }
1266
+ /**
1267
+ * A no-op method for string marking.
1268
+ *
1269
+ * Sometimes you want to mark strings for translation but do not actually
1270
+ * want to translate them, at least not at the time of their definition.
1271
+ * This is often the case, when you have to preserve the original string.
1272
+ *
1273
+ * Take this example:
1274
+ *
1275
+ * ```
1276
+ * orangeColors = [gtx.N_('coral'), gtx.N_('tomato'), gtx.N_('orangered'),
1277
+ * gtx.N_('gold'), gtx.N_('orange'), gtx.N_('darkorange')]
1278
+ * ```
1279
+ *
1280
+ * These are standard CSS colors, and you cannot translate them inside
1281
+ * CSS styles. But for presentation you may want to translate them later:
1282
+ *
1283
+ * ```
1284
+ * console.log(gtx._x("The css color '{color}' is {translated}.",
1285
+ * {
1286
+ * color: orangeColors[2],
1287
+ * translated: gtx._(orangeColors[2]),
1288
+ * }
1289
+ * )
1290
+ * );
1291
+ * ```
1292
+ *
1293
+ * In other words: The method just marks strings for translation, so that
1294
+ * the extractor `esgettext-xgettext` finds them but it does not actually
1295
+ * translate anything.
1296
+ *
1297
+ * Similar methods are available for other cases (with placeholder
1298
+ * expansion, context, or both). They are *not* available for plural
1299
+ * methods because that would not make sense.
1300
+ *
1301
+ * Note that all of these methods are also available as instance methods.
1302
+ *
1303
+ * @param msgid - the message id
1304
+ * @returns the original string
1305
+ */
1306
+ static N_(msgid) {
1307
+ return msgid;
1308
+ }
1309
+ /**
1310
+ * Does the same as the static method `N_()`.
1311
+ *
1312
+ * @param msgid - the message id
1313
+ * @returns the original string
1314
+ */
1315
+ N_(msgid) {
1316
+ return msgid;
1317
+ }
1318
+ /**
1319
+ * Same as `N_()` but with placeholder expansion.
1320
+ *
1321
+ * @param msgid - the message id
1322
+ * @param placeholders - a dictionary of placeholders
1323
+ * @returns the original string with placeholders expanded
1324
+ */
1325
+ N_x(msgid, placeholders) {
1326
+ return Textdomain.expand(msgid, placeholders !== null && placeholders !== void 0 ? placeholders : {});
1327
+ }
1328
+ /**
1329
+ * Does the same as the static method `N_x()`.
1330
+ *
1331
+ * @param msgid - the message id
1332
+ * @param placeholders - a dictionary of placeholders
1333
+ * @returns the original string with placeholders expanded
1334
+ */
1335
+ static N_x(msgid, placeholders) {
1336
+ return Textdomain.expand(msgid, placeholders !== null && placeholders !== void 0 ? placeholders : {});
1337
+ }
1338
+ /**
1339
+ * Same as `N_()` but with context.
1340
+ *
1341
+ * @param _msgctxt - the message context (not used)
1342
+ * @param msgid - the message id
1343
+ * @returns the original string
1344
+ */
1345
+ N_p(_msgctxt, msgid) {
1346
+ return msgid;
1347
+ }
1348
+ /**
1349
+ * Does the same as the static method `N_p()`.
1350
+ *
1351
+ * @param _msgctxt - the message context (not used)
1352
+ * @param msgid - the message id
1353
+ * @returns the original string with placeholders expanded
1354
+ */
1355
+ static N_p(_msgctxt, msgid) {
1356
+ return msgid;
1357
+ }
1358
+ /**
1359
+ * Same as `N_()` but with context and placeholder expansion.
1360
+ *
1361
+ * @param _msgctxt - the message context (not used)
1362
+ * @param msgid - the message id
1363
+ * @param placeholders - a dictionary of placeholders
1364
+ * @returns the original string with placeholders expanded
1365
+ */
1366
+ N_px(_msgctxt, msgid, placeholders) {
1367
+ return Textdomain.expand(msgid, placeholders !== null && placeholders !== void 0 ? placeholders : {});
1368
+ }
1369
+ /**
1370
+ * Does the same as the static method `N_px()`.
1371
+ *
1372
+ * @param _msgctxt - the message context (not used)
1373
+ * @param msgid - the message id
1374
+ * @param placeholders - a dictionary of placeholders
1375
+ * @returns the original string with placeholders expanded
1376
+ */
1377
+ static N_px(_msgctxt, msgid, placeholders) {
1378
+ return Textdomain.expand(msgid, placeholders !== null && placeholders !== void 0 ? placeholders : {});
1379
+ }
1380
+ }
1381
+ Textdomain.domains = {};
1382
+ Textdomain.boundDomains = {};
1383
+ Textdomain._locale = 'C';
1384
+
1385
+ browserEnvironment(true);
1386
+ const locales = new Array();
1387
+ if (window.navigator.languages) {
1388
+ locales.push(...window.navigator.languages);
1389
+ }
1390
+ if (typeof window.navigator.language !== 'undefined') {
1391
+ locales.push(window.navigator.language);
1392
+ }
1393
+ const nav = window.navigator;
1394
+ if (Object.prototype.hasOwnProperty.call(nav, 'userLanguage') &&
1395
+ nav.userLanguage) {
1396
+ locales.push(nav.userLanguage);
1397
+ }
1398
+ if (Object.prototype.hasOwnProperty.call(nav, 'browserLanguage') &&
1399
+ nav['browserLanguage']) {
1400
+ locales.push(nav.browserLanguage);
1401
+ }
1402
+ if (Object.prototype.hasOwnProperty.call(nav, 'systemLanguage') &&
1403
+ nav['systemLanguage']) {
1404
+ locales.push(nav.systemLanguage);
1405
+ }
1406
+ userLocales(locales);
1407
+
1408
+ exports.CatalogCache = CatalogCache;
1409
+ exports.Textdomain = Textdomain;
1410
+ exports.parseJsonCatalog = parseJsonCatalog;
1411
+ exports.parseMoCatalog = parseMoCatalog;
1412
+ exports.parseMoJsonCatalog = parseMoJsonCatalog;
1413
+
1414
+ }));
1415
+ //# sourceMappingURL=esgettext.js.map