@vestra-player/sdk 1.5.7 → 1.5.9

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/dist/i18n.d.ts ADDED
@@ -0,0 +1,130 @@
1
+ /**
2
+ * The player's interface languages: English (the source language) first,
3
+ * then the translations, as the player's own table (its tests check that
4
+ * they agree).
5
+ */
6
+ export declare const LOCALES: readonly ["en", "zh-Hans", "ja", "ko", "de", "fr", "es"];
7
+ /** One message of a `.po` file (the header `msgid ""` is not one). */
8
+ export interface PoEntry {
9
+ /** `msgctxt`, if any. */
10
+ context?: string;
11
+ /** `msgid`: the English source text. */
12
+ id: string;
13
+ /** `msgid_plural`, for a plural message. */
14
+ plural?: string;
15
+ /** `msgstr`, or `msgstr[0]`, `msgstr[1]`, … of a plural message. */
16
+ strings: string[];
17
+ /** Flagged `fuzzy`: left out of the compiled catalog. */
18
+ fuzzy: boolean;
19
+ /** `#.` lines: notes for translators. */
20
+ notes: string[];
21
+ /** `#:` references (`file:line`). */
22
+ references: string[];
23
+ /** Other `#,` flags than `fuzzy`. */
24
+ flags: string[];
25
+ /** A `#~` entry: no longer in the source. */
26
+ obsolete: boolean;
27
+ }
28
+ /** The catalog key: `msgid`, or `msgctxt` U+0004 `msgid`. */
29
+ export declare const keyOf: (context: string | undefined, id: string) => string;
30
+ /** Parse a `.po` (or `.pot`) file. Throws with the line number on errors. */
31
+ export declare function parsePo(text: string): {
32
+ header: string;
33
+ entries: PoEntry[];
34
+ };
35
+ /** Write a `.po` file: the header, then the entries in the given order. */
36
+ export declare function writePo(header: string, entries: readonly PoEntry[]): string;
37
+ /** A message of a compiled catalog: a translation, or `[one, other]`. */
38
+ export type CompiledMessage = string | [string, string];
39
+ /**
40
+ * The compiled catalog of one language (`locales/<lang>.json`): translated
41
+ * entries only (not fuzzy, not obsolete, not empty), keys sorted. Plurals
42
+ * have two forms, as the player shows them: `msgstr[0]` for `n == 1` and
43
+ * `msgstr[1]` (else `msgstr[0]`) for every other `n`.
44
+ */
45
+ export declare function compileCatalog(language: string, entries: readonly PoEntry[]): {
46
+ language: string;
47
+ messages: Record<string, CompiledMessage>;
48
+ };
49
+ /** Lookups in one language's messages, as the player does them. */
50
+ export declare class Catalog {
51
+ readonly messages: ReadonlyMap<string, CompiledMessage>;
52
+ constructor(messages?: Record<string, CompiledMessage>);
53
+ /** From parsed `.po` entries. */
54
+ static fromEntries(entries: readonly PoEntry[]): Catalog;
55
+ /** The translation of `id` (the one form of a plural), or `undefined`. */
56
+ lookup(id: string, context?: string): string | undefined;
57
+ /** The translation of `id`, or `id` itself. */
58
+ text(id: string): string;
59
+ /**
60
+ * A plugin sentence (`osd.show(template, args)`, dialogs): translated,
61
+ * then formatted with `args` when given; without `args` the text shows
62
+ * as it is, braces included.
63
+ */
64
+ template(text: string, args?: TemplateArgsValue): string;
65
+ /** What an `@tr` call becomes, `undefined` when untranslated. */
66
+ slint(call: TrCall): [string, string | undefined] | undefined;
67
+ }
68
+ /** Template arguments: positional (`{}`, `{0}`) or named (`{name}`). */
69
+ export type TemplateArgsValue = readonly (string | number)[] | Readonly<Record<string, string | number>> | null;
70
+ /**
71
+ * Format a template the way Slint's `@tr` and the player do: `{}` takes
72
+ * the next argument, `{0}` the first, `{name}` a field of an object; `{{`
73
+ * and `}}` are braces. A placeholder without an argument stays as written.
74
+ */
75
+ export declare function format(template: string, args: TemplateArgsValue): string;
76
+ /**
77
+ * The placeholders of a template, sorted: `""` per `{}`, else the name or
78
+ * number (`{n}` of a Slint plural is `"n"`). Translations must keep them.
79
+ */
80
+ export declare function placeholders(text: string): string[];
81
+ /** One `@tr("context" => "id" | "plural" % n, args…)` call. */
82
+ export interface TrCall {
83
+ context?: string;
84
+ id: string;
85
+ plural?: string;
86
+ /** 1-based line of `@tr`. */
87
+ line: number;
88
+ /** Source offsets of the id literal (quotes included). */
89
+ idSpan: [number, number];
90
+ /** And of the plural literal. */
91
+ pluralSpan?: [number, number];
92
+ }
93
+ /**
94
+ * Every `@tr` call of a Slint source, in order; the same scanner as the
95
+ * player's (both run the shared cases of the player's
96
+ * `src/host/tests/fixtures/slint-tr.json`). Comments, strings and string
97
+ * interpolation are skipped; a malformed call is left out.
98
+ */
99
+ export declare function scanSlint(source: string): TrCall[];
100
+ /** A Slint string literal for `text`. */
101
+ export declare function slintQuote(text: string): string;
102
+ /** `source` with its `@tr` literals translated (what the player compiles). */
103
+ export declare function rewriteSlint(source: string, catalog: Catalog): string;
104
+ /**
105
+ * The supported locale for a BCP 47 tag, as the player maps the system's
106
+ * languages: Simplified Chinese is `zh-Hans`; Traditional Chinese (`zh-Hant`,
107
+ * or Taiwan, Hong Kong, Macao) is English; other languages by their primary
108
+ * subtag; `undefined` for a language the player does not have.
109
+ */
110
+ export declare function matchLocale(tag: string): (typeof LOCALES)[number] | undefined;
111
+ /**
112
+ * The player's built-in top-level menus: id → key (the English text paths
113
+ * merge by), as the player's `MENU_ANCHORS`.
114
+ */
115
+ export declare const MENU_KEYS: Readonly<Record<string, string>>;
116
+ /** The player's own submenus, by key path (their labels are the player's). */
117
+ export declare const HOST_GROUPS: string[];
118
+ /**
119
+ * The keys a path merges by, as the player normalizes it: `@id` becomes the
120
+ * built-in menu's key, the player's old Chinese titles of its own submenus
121
+ * their keys.
122
+ */
123
+ export declare function menuKeys(path: readonly string[]): string[];
124
+ /**
125
+ * The player's own texts that the test host repeats (core actions, its
126
+ * refusals, its menus), English → the player's Simplified Chinese
127
+ * (`src/host/locales/zh-Hans.po` in the player; its tests check that they
128
+ * agree).
129
+ */
130
+ export declare const HOST_ZH_HANS: Readonly<Record<string, string>>;