@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.
package/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- This software is Copyright (C) 2020 by Guido Flohr.
1
+ This software is Copyright (C) 2020-2024 by Guido Flohr.
2
2
 
3
3
  This is free software, licensed under:
4
4
 
package/README.md CHANGED
@@ -6,22 +6,22 @@ GNU gettext-alike translation runtime library.
6
6
 
7
7
  - [API Documentation](#api-documentation)
8
8
  - [Internationalizing Hello World](#internationalizing-hello-world)
9
- - [Choosing a Textdomain](#choosing-a-textdomain)
10
- - [Install the Library](#install-the-library)
11
- - [Import the Library](#import-the-library)
12
- - [Prepare Your Sources](#prepare-your-sources)
13
- - [Translation Methods](#translation-methods)
14
- - [Simple Translations With `_()`](#simple-translations-with-_)
15
- - [Variable Interpolation With `_x()`](#variable-interpolation-with-_x)
16
- - [Plural Forms With `_nx()`](#plural-forms-with-_nx)
17
- - [Message Context With `_p()`](#message-context-with-_p)
18
- - [Specific Locale with `_l`](#specific-locale-with-_l)
19
- - [TODO: Gender-Specific Translations](#todo-gender-specific-translations)
20
- - [Selecting the Preferred Language with `selectLocale()`](#selecting-the-preferred-language-with-selectlocale)
9
+ - [Choosing a Textdomain](#choosing-a-textdomain)
10
+ - [Install the Library](#install-the-library)
11
+ - [Import the Library](#import-the-library)
12
+ - [Prepare Your Sources](#prepare-your-sources)
13
+ - [Translation Methods](#translation-methods)
14
+ - [Simple Translations With `_()`](#simple-translations-with-_)
15
+ - [Variable Interpolation With `_x()`](#variable-interpolation-with-_x)
16
+ - [Plural Forms With `_nx()`](#plural-forms-with-_nx)
17
+ - [Message Context With `_p()`](#message-context-with-_p)
18
+ - [Specific Locale with `_l`](#specific-locale-with-_l)
19
+ - [TODO: Gender-Specific Translations](#todo-gender-specific-translations)
20
+ - [Selecting the Preferred Language with `selectLocale()`](#selecting-the-preferred-language-with-selectlocale)
21
21
  - [Internationalizing a Library](#internationalizing-a-library)
22
22
  - [Frequently-Asked Questions](#frequently-asked-questions)
23
- - [Why do Template Strings not Work?](#why-do-template-strings-not-work)
24
- - [What Does the Error "template literals with embedded expressions are not allowed as arguments to gettext functions because they are not constant" Mean?](#what-does-the-error-template-literals-with-embedded-expressions-are-not-allowed-as-arguments-to-gettext-functions-because-they-are-not-constant-mean)
23
+ - [Why do Template Strings not Work?](#why-do-template-strings-not-work)
24
+ - [What Does the Error "template literals with embedded expressions are not allowed as arguments to gettext functions because they are not constant" Mean?](#what-does-the-error-template-literals-with-embedded-expressions-are-not-allowed-as-arguments-to-gettext-functions-because-they-are-not-constant-mean)
25
25
  - [Copyright](#copyright)
26
26
 
27
27
  ## API Documentation
@@ -82,7 +82,7 @@ $ yarn add @esgettext/runtime
82
82
 
83
83
  How to import the library, depends on your environment.
84
84
 
85
- If you have the `import` keyword:
85
+ If you have the `import` keyword (TypeScript or ES module syntax):
86
86
 
87
87
  ```javascript
88
88
  import { Textdomain } from '@esgettext/runtime';
@@ -91,11 +91,9 @@ import { Textdomain } from '@esgettext/runtime';
91
91
  If you can use `require`:
92
92
 
93
93
  ```javascript
94
- const esgettext = require('@esgettext/runtime');
95
- const Textdomain = esgettext.Textdomain;
94
+ const { Textdomain } = require('@esgettext/runtime');
96
95
  ```
97
96
 
98
- _FIXME! Is this correct?_
99
97
 
100
98
  If you are writing javascript loaded by a browser:
101
99
 
@@ -404,7 +402,7 @@ template string with interpolated expressions.
404
402
 
405
403
  ## Copyright
406
404
 
407
- Copyright (C) 2020 Guido Flohr <guido.flohr@cantanea.com>, all
405
+ Copyright (C) 2020-2024 Guido Flohr <guido.flohr@cantanea.com>, all
408
406
  rights reserved.
409
407
 
410
408
  This software is available under the terms and conditions of the
@@ -5,6 +5,17 @@ export declare class CatalogCache {
5
5
  private constructor();
6
6
  static getInstance(): CatalogCache;
7
7
  static clear(): void;
8
+ /**
9
+ * Lookup a Catalog for a given base path, locale, and textdomain.
10
+ *
11
+ * The locale key is usually the locale identifier (e.g. de-DE or sr\@latin).
12
+ * But it can also be a colon separated list of such locale identifiers.
13
+ *
14
+ *
15
+ * @param localeKey - the locale key
16
+ * @param textdomain - the textdomain
17
+ * @returns the cached Catalog, a Promise or null for failure
18
+ */
8
19
  static lookup(localeKey: string, textdomain: string): Catalog | Promise<Catalog> | null;
9
20
  static store(localeKey: string, textdomain: string, entry: Catalog | Promise<Catalog>): void;
10
21
  }
@@ -1 +1 @@
1
- {"version":3,"file":"catalog-cache.d.ts","sourceRoot":"","sources":["../../src/core/catalog-cache.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAoBpC,qBAAa,YAAY;IACxB,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAe;IACtC,OAAO,CAAC,MAAM,CAAC,KAAK,CAA6B;IAEjD,OAAO;IAIP,MAAM,CAAC,WAAW,IAAI,YAAY;IAQlC,MAAM,CAAC,KAAK,IAAI,IAAI;WAeN,MAAM,CACnB,SAAS,EAAE,MAAM,EACjB,UAAU,EAAE,MAAM,GAChB,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,GAAG,IAAI;WAWtB,KAAK,CAClB,SAAS,EAAE,MAAM,EACjB,UAAU,EAAE,MAAM,EAClB,KAAK,EAAE,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,GAC/B,IAAI;CAWP"}
1
+ {"version":3,"file":"catalog-cache.d.ts","sourceRoot":"","sources":["../../src/core/catalog-cache.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAoBpC,qBAAa,YAAY;IACxB,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAe;IACtC,OAAO,CAAC,MAAM,CAAC,KAAK,CAA6B;IAEjD,OAAO;IAIP,MAAM,CAAC,WAAW,IAAI,YAAY;IAQlC,MAAM,CAAC,KAAK,IAAI,IAAI;IAIpB;;;;;;;;;;OAUG;WACW,MAAM,CACnB,SAAS,EAAE,MAAM,EACjB,UAAU,EAAE,MAAM,GAChB,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,GAAG,IAAI;WAWtB,KAAK,CAClB,SAAS,EAAE,MAAM,EACjB,UAAU,EAAE,MAAM,EAClB,KAAK,EAAE,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,GAC/B,IAAI;CAWP"}
@@ -1,10 +1,48 @@
1
- export interface CatalogEntries {
1
+ /**
2
+ * The set of translations found in a [[`Catalog`]].
3
+ *
4
+ * This interface is used internally. You will only need it if you want to
5
+ * write your own message retrieval method or want to inspect a loaded
6
+ * [[`Catalog`]].
7
+ *
8
+ * The translations are looked up by their singular form in the original
9
+ * language. The value is an array of strings. The first item is the singular
10
+ * translation, the optional following items are the plural forms.
11
+ *
12
+ * If a translation has a message context, the key is the context joined
13
+ * with the translation by a `'\u0004'` character. For example, the key for
14
+ * the msgid "Open" with the msgctxt "Menu|File" would be `Menu|File\u0004Open`.
15
+ */
16
+ export type CatalogEntries = {
2
17
  [key: string]: Array<string>;
3
- }
4
- export interface Catalog {
18
+ };
19
+ /**
20
+ * A [[`Catalog`]] is a container for a set of translations loaded from a
21
+ * `mo.json` or a binary `.mo` file.
22
+ *
23
+ * This interface is used internally. You will only need it if you want to
24
+ * write your own message retrieval method or want to inspect a loaded
25
+ * [[`Catalog`]].
26
+ */
27
+ export type Catalog = {
28
+ /** The major revision number of the catalog, currently always 0. */
5
29
  major: number;
30
+ /** The minor revision number of the catalog, currently always 0 or 1. */
6
31
  minor: number;
32
+ /**
33
+ * Compute the index of a plural form from a number of items. If a language
34
+ * has one singular and two plural forms, the singular form would have
35
+ * index 0 and the plural forms have index 1 and 2.
36
+ *
37
+ * The plural function would then compute one of 0, 1, or 2 from an
38
+ * arbitrary non-negative integer.
39
+ *
40
+ * @param numItems - the number of items.
41
+ *
42
+ * @returns the index of the plural form.
43
+ */
7
44
  pluralFunction(numItems: number): number;
45
+ /** The actual translations. */
8
46
  entries: CatalogEntries;
9
- }
47
+ };
10
48
  //# sourceMappingURL=catalog.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"catalog.d.ts","sourceRoot":"","sources":["../../src/core/catalog.ts"],"names":[],"mappings":"AAeA,MAAM,WAAW,cAAc;IAC9B,CAAC,GAAG,EAAE,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC;CAC7B;AAUD,MAAM,WAAW,OAAO;IAEvB,KAAK,EAAE,MAAM,CAAC;IAGd,KAAK,EAAE,MAAM,CAAC;IAcd,cAAc,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAAC;IAGzC,OAAO,EAAE,cAAc,CAAC;CACxB"}
1
+ {"version":3,"file":"catalog.d.ts","sourceRoot":"","sources":["../../src/core/catalog.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,MAAM,MAAM,cAAc,GAAG;IAC5B,CAAC,GAAG,EAAE,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC;CAC7B,CAAC;AAEF;;;;;;;GAOG;AACH,MAAM,MAAM,OAAO,GAAG;IACrB,oEAAoE;IACpE,KAAK,EAAE,MAAM,CAAC;IAEd,yEAAyE;IACzE,KAAK,EAAE,MAAM,CAAC;IAEd;;;;;;;;;;;OAWG;IACH,cAAc,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAAC;IAEzC,+BAA+B;IAC/B,OAAO,EAAE,cAAc,CAAC;CACxB,CAAC"}
@@ -3,7 +3,17 @@ export declare class DataViewlet {
3
3
  private decoder;
4
4
  private _encoding;
5
5
  constructor(array: Uint8Array, encoding?: string);
6
+ /**
7
+ * Get the encoding for strings.
8
+ *
9
+ * @returns the encoding in use
10
+ */
6
11
  get encoding(): string;
12
+ /**
13
+ * Switch to a new encoding.
14
+ *
15
+ * @param encoding - new encoding to use
16
+ */
7
17
  set encoding(encoding: string);
8
18
  readUInt32BE(offset?: number): number;
9
19
  readUInt32LE(offset?: number): number;
@@ -1 +1 @@
1
- {"version":3,"file":"data-viewlet.d.ts","sourceRoot":"","sources":["../../src/core/data-viewlet.ts"],"names":[],"mappings":"AAIA,qBAAa,WAAW;IAYtB,OAAO,CAAC,QAAQ,CAAC,KAAK;IAXvB,OAAO,CAAC,OAAO,CAAc;IAC7B,OAAO,CAAC,SAAS,CAAS;gBAUR,KAAK,EAAE,UAAU,EAClC,QAAQ,SAAU;IAWnB,IAAI,QAAQ,IAAI,MAAM,CAErB;IAOD,IAAI,QAAQ,CAAC,QAAQ,EAAE,MAAM,EAG5B;IAUD,YAAY,CAAC,MAAM,SAAI,GAAG,MAAM;IAuBhC,YAAY,CAAC,MAAM,SAAI,GAAG,MAAM;IAqBhC,UAAU,CAAC,MAAM,SAAI,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM;CAc/C"}
1
+ {"version":3,"file":"data-viewlet.d.ts","sourceRoot":"","sources":["../../src/core/data-viewlet.ts"],"names":[],"mappings":"AAIA,qBAAa,WAAW;IAYtB,OAAO,CAAC,QAAQ,CAAC,KAAK;IAXvB,OAAO,CAAC,OAAO,CAAc;IAC7B,OAAO,CAAC,SAAS,CAAS;gBAUR,KAAK,EAAE,UAAU,EAClC,QAAQ,SAAU;IAMnB;;;;OAIG;IACH,IAAI,QAAQ,IAAI,MAAM,CAErB;IAED;;;;OAIG;IACH,IAAI,QAAQ,CAAC,QAAQ,EAAE,MAAM,EAG5B;IAUD,YAAY,CAAC,MAAM,SAAI,GAAG,MAAM;IAuBhC,YAAY,CAAC,MAAM,SAAI,GAAG,MAAM;IAqBhC,UAAU,CAAC,MAAM,SAAI,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM;CAc/C"}
@@ -1,9 +1,32 @@
1
- import { Catalog } from './catalog';
2
- export interface LocaleContainer {
1
+ import type { Catalog } from './catalog';
2
+ /**
3
+ * An object storing locale information. It resembles the directory structure
4
+ * that [[`Catalog`]] objects are found in.
5
+ *
6
+ * Example, if your textdomain is 'myapp':
7
+ *
8
+ * <pre class="language-javascript"><code class="language-javascript">\{
9
+ * fr: \{
10
+ * LC_MESSAGES: \{
11
+ * myapp: catalogs['fr']
12
+ * \}
13
+ * \},
14
+ * 'de-DE': \{
15
+ * LC_MESSAGES: \{
16
+ * myapp: catalogs['de-DE']
17
+ * \}
18
+ * \}
19
+ * \}
20
+ * </code></pre>
21
+ */
22
+ export type LocaleContainer = {
23
+ /** A language code like 'fr' or 'de-DE'. */
3
24
  [key: string]: {
25
+ /** The Locale category, always 'LC_MESSAGES'. */
4
26
  [key: string]: {
27
+ /** The textdomain. */
5
28
  [key: string]: Catalog;
6
29
  };
7
30
  };
8
- }
31
+ };
9
32
  //# sourceMappingURL=locale-container.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"locale-container.d.ts","sourceRoot":"","sources":["../../src/core/locale-container.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAsBpC,MAAM,WAAW,eAAe;IAE/B,CAAC,GAAG,EAAE,MAAM,GAAG;QAEd,CAAC,GAAG,EAAE,MAAM,GAAG;YAEd,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;SACvB,CAAC;KACF,CAAC;CACF"}
1
+ {"version":3,"file":"locale-container.d.ts","sourceRoot":"","sources":["../../src/core/locale-container.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEzC;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,MAAM,eAAe,GAAG;IAC7B,4CAA4C;IAC5C,CAAC,GAAG,EAAE,MAAM,GAAG;QACd,iDAAiD;QACjD,CAAC,GAAG,EAAE,MAAM,GAAG;YACd,sBAAsB;YACtB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;SACvB,CAAC;KACF,CAAC;CACF,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"resolve-impl.d.ts","sourceRoot":"","sources":["../../src/core/resolve-impl.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,OAAO,EAAkB,MAAM,WAAW,CAAC;AAKpD,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAiPrD,wBAAgB,WAAW,CAC1B,UAAU,EAAE,MAAM,EAClB,IAAI,EAAE,MAAM,GAAG,eAAe,EAC9B,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,MAAM,GACf,OAAO,CAAC,OAAO,CAAC,CAyBlB"}
1
+ {"version":3,"file":"resolve-impl.d.ts","sourceRoot":"","sources":["../../src/core/resolve-impl.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,OAAO,EAAkB,MAAM,WAAW,CAAC;AAKpD,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AA4MrD,wBAAsB,WAAW,CAChC,UAAU,EAAE,MAAM,EAClB,IAAI,EAAE,MAAM,GAAG,eAAe,EAC9B,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,MAAM,GACf,OAAO,CAAC,OAAO,CAAC,CAiBlB"}