@vestra-player/sdk 1.5.8 → 1.5.11
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/CHANGELOG.md +39 -0
- package/README.md +4 -1
- package/bin/vestra-plugin.mjs +170 -7
- package/dist/commands.d.ts +7 -4
- package/dist/i18n-tools.d.ts +67 -0
- package/dist/i18n-tools.js +787 -0
- package/dist/i18n.d.ts +222 -0
- package/dist/i18n.js +972 -0
- package/dist/player-runtime.d.ts +2 -0
- package/dist/player-runtime.js +2 -0
- package/dist/plugin/appearance.js +27 -1
- package/dist/plugin/bindings.js +1 -0
- package/dist/plugin/commands.js +24 -4
- package/dist/plugin/index.js +9 -1
- package/dist/plugin/language.d.ts +8 -0
- package/dist/plugin/language.js +79 -0
- package/dist/plugin/osd.d.ts +11 -0
- package/dist/plugin/osd.js +64 -9
- package/dist/plugin/packages.js +10 -0
- package/dist/plugin/runtime.d.ts +3 -1
- package/dist/plugin/runtime.js +6 -0
- package/dist/plugin/scope.d.ts +1 -0
- package/dist/plugin/scope.js +2 -0
- package/dist/plugin/subtitles.js +9 -1
- package/dist/plugin/testing.d.ts +184 -5
- package/dist/plugin/testing.js +459 -67
- package/dist/plugin/timeline.js +3 -1
- package/dist/plugin/types.d.ts +523 -54
- package/dist/plugin/ui.js +29 -10
- package/dist/plugin/values.d.ts +55 -0
- package/dist/plugin/values.js +117 -0
- package/dist/plugin/window.d.ts +2 -0
- package/dist/plugin/window.js +4 -0
- package/dist/source-resolvers.d.ts +0 -1
- package/dist/source-resolvers.js +9 -1
- package/dist/subtitles.d.ts +3 -1
- package/dist/wire.d.ts +38 -6
- package/dist/wire.js +13 -2
- package/llms-full.txt +646 -58
- package/llms.txt +44 -40
- package/package.json +1 -1
- package/slint/vestra/markdown.slint +5 -5
- package/slint/vestra/widgets.slint +4 -4
package/dist/i18n.d.ts
ADDED
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
import type { ListStyle, Locale } from "./plugin/types.ts";
|
|
2
|
+
/**
|
|
3
|
+
* The player's interface languages: English (the source language) first,
|
|
4
|
+
* then the translations, as the player's own table (its tests check that
|
|
5
|
+
* they agree).
|
|
6
|
+
*/
|
|
7
|
+
export declare const LOCALES: readonly ["en", "zh-Hans", "ja", "ko", "de", "fr", "es"];
|
|
8
|
+
/** One message of a `.po` file (the header `msgid ""` is not one). */
|
|
9
|
+
export interface PoEntry {
|
|
10
|
+
/** `msgctxt`, if any. */
|
|
11
|
+
context?: string;
|
|
12
|
+
/** `msgid`: the English source text. */
|
|
13
|
+
id: string;
|
|
14
|
+
/** `msgid_plural`, for a plural message. */
|
|
15
|
+
plural?: string;
|
|
16
|
+
/** `msgstr`, or `msgstr[0]`, `msgstr[1]`, … of a plural message. */
|
|
17
|
+
strings: string[];
|
|
18
|
+
/** Flagged `fuzzy`: left out of the compiled catalog. */
|
|
19
|
+
fuzzy: boolean;
|
|
20
|
+
/** `#.` lines: notes for translators. */
|
|
21
|
+
notes: string[];
|
|
22
|
+
/** `#:` references (`file:line`). */
|
|
23
|
+
references: string[];
|
|
24
|
+
/** Other `#,` flags than `fuzzy`. */
|
|
25
|
+
flags: string[];
|
|
26
|
+
/** A `#~` entry: no longer in the source. */
|
|
27
|
+
obsolete: boolean;
|
|
28
|
+
}
|
|
29
|
+
/** The catalog key: `msgid`, or `msgctxt` U+0004 `msgid`. */
|
|
30
|
+
export declare const keyOf: (context: string | undefined, id: string) => string;
|
|
31
|
+
/** Parse a `.po` (or `.pot`) file. Throws with the line number on errors. */
|
|
32
|
+
export declare function parsePo(text: string): {
|
|
33
|
+
header: string;
|
|
34
|
+
entries: PoEntry[];
|
|
35
|
+
};
|
|
36
|
+
/** Write a `.po` file: the header, then the entries in the given order. */
|
|
37
|
+
export declare function writePo(header: string, entries: readonly PoEntry[]): string;
|
|
38
|
+
/** A message of a compiled catalog: a translation, or `[one, other]`. */
|
|
39
|
+
export type CompiledMessage = string | [string, string];
|
|
40
|
+
/**
|
|
41
|
+
* The compiled catalog of one language (`locales/<lang>.json`): translated
|
|
42
|
+
* entries only (not fuzzy, not obsolete, not empty), keys sorted. Plurals
|
|
43
|
+
* have two forms, as the player shows them: `msgstr[0]` for `n == 1` and
|
|
44
|
+
* `msgstr[1]` (else `msgstr[0]`) for every other `n`.
|
|
45
|
+
*/
|
|
46
|
+
export declare function compileCatalog(language: string, entries: readonly PoEntry[]): {
|
|
47
|
+
language: string;
|
|
48
|
+
messages: Record<string, CompiledMessage>;
|
|
49
|
+
};
|
|
50
|
+
/** Lookups in one language's messages, as the player does them. */
|
|
51
|
+
export declare class Catalog {
|
|
52
|
+
readonly messages: ReadonlyMap<string, CompiledMessage>;
|
|
53
|
+
constructor(messages?: Record<string, CompiledMessage>);
|
|
54
|
+
/** From parsed `.po` entries. */
|
|
55
|
+
static fromEntries(entries: readonly PoEntry[]): Catalog;
|
|
56
|
+
/** The translation of `id` (the one form of a plural), or `undefined`. */
|
|
57
|
+
lookup(id: string, context?: string): string | undefined;
|
|
58
|
+
/** The translation of `id`, or `id` itself. */
|
|
59
|
+
text(id: string): string;
|
|
60
|
+
/**
|
|
61
|
+
* A plugin sentence (`osd.show(template, args)`, dialogs): translated,
|
|
62
|
+
* then formatted with `args` when given; without `args` the text shows
|
|
63
|
+
* as it is, braces included.
|
|
64
|
+
*/
|
|
65
|
+
template(text: string, args?: TemplateArgsValue): string;
|
|
66
|
+
/** What an `@tr` call becomes, `undefined` when untranslated. */
|
|
67
|
+
slint(call: TrCall): [string, string | undefined] | undefined;
|
|
68
|
+
}
|
|
69
|
+
/** Template arguments: positional (`{}`, `{0}`) or named (`{name}`). */
|
|
70
|
+
export type TemplateArgsValue = readonly (string | number)[] | Readonly<Record<string, string | number>> | null;
|
|
71
|
+
/**
|
|
72
|
+
* Format a template the way Slint's `@tr` and the player do: `{}` takes
|
|
73
|
+
* the next argument, `{0}` the first, `{name}` a field of an object; `{{`
|
|
74
|
+
* and `}}` are braces. A placeholder without an argument stays as written.
|
|
75
|
+
*/
|
|
76
|
+
export declare function format(template: string, args: TemplateArgsValue): string;
|
|
77
|
+
/**
|
|
78
|
+
* The placeholders of a template, sorted: `""` per `{}`, else the name or
|
|
79
|
+
* number (`{n}` of a Slint plural is `"n"`). Translations must keep them.
|
|
80
|
+
*/
|
|
81
|
+
export declare function placeholders(text: string): string[];
|
|
82
|
+
/**
|
|
83
|
+
* The ways a `TextList` is joined (`ListStyle`), as the player
|
|
84
|
+
* joins them in each interface language (`LIST_SEPARATORS`).
|
|
85
|
+
*/
|
|
86
|
+
export declare const LIST_STYLES: readonly ListStyle[];
|
|
87
|
+
/**
|
|
88
|
+
* The separator of each list style per interface language, as the player's
|
|
89
|
+
* table (`i18n::text::SEPARATORS`; its tests check that they agree).
|
|
90
|
+
*/
|
|
91
|
+
export declare const LIST_SEPARATORS: Readonly<Record<Locale, Readonly<Record<ListStyle, string>>>>;
|
|
92
|
+
/**
|
|
93
|
+
* The player's limits on one text value (a
|
|
94
|
+
* {@link @vestra-player/sdk!Text | Text} or
|
|
95
|
+
* {@link @vestra-player/sdk!TextList | TextList} with everything nested in it), as the player's
|
|
96
|
+
* `i18n::text` (its tests check that they agree).
|
|
97
|
+
*/
|
|
98
|
+
export declare const TEXT_LIMITS: {
|
|
99
|
+
/** Nesting depth of texts and lists; the value itself is depth 0 (8). */
|
|
100
|
+
readonly depth: 8;
|
|
101
|
+
/** Texts, lists and arguments in all, the value itself included (1024). */
|
|
102
|
+
readonly nodes: 1024;
|
|
103
|
+
/** Arguments of one text (16). */
|
|
104
|
+
readonly args: 16;
|
|
105
|
+
/** Items of one list (256). */
|
|
106
|
+
readonly items: 256;
|
|
107
|
+
/** UTF-8 bytes of a source text or a string argument (4096). */
|
|
108
|
+
readonly stringBytes: 4096;
|
|
109
|
+
};
|
|
110
|
+
/** A translatable text on the wire: English source text and its arguments. */
|
|
111
|
+
export type TextJson = {
|
|
112
|
+
$vestraText: string;
|
|
113
|
+
args?: ArgJson[] | {
|
|
114
|
+
[name: string]: ArgJson;
|
|
115
|
+
};
|
|
116
|
+
};
|
|
117
|
+
/** A list on the wire: items joined the interface language's way. */
|
|
118
|
+
export type ListJson = {
|
|
119
|
+
$vestraList: ArgJson[];
|
|
120
|
+
style?: ListStyle;
|
|
121
|
+
};
|
|
122
|
+
/** An argument of a text: data (strings and numbers) or another text. */
|
|
123
|
+
export type ArgJson = string | number | TextJson | ListJson;
|
|
124
|
+
/** A text or list value (by its marker key). */
|
|
125
|
+
export declare function isTextValue(value: unknown): value is TextJson | ListJson;
|
|
126
|
+
/**
|
|
127
|
+
* Why the player would refuse a text value or template arguments, or
|
|
128
|
+
* `null`. `args` mode checks template arguments (an array or object of
|
|
129
|
+
* arguments) instead of one value. The same rules and messages as the
|
|
130
|
+
* player's `i18n::text::check`.
|
|
131
|
+
*/
|
|
132
|
+
export declare function textProblem(value: unknown, mode?: "value" | "args"): string | null;
|
|
133
|
+
type TemplateArgsLike = readonly ArgJson[] | Readonly<Record<string, ArgJson>> | null;
|
|
134
|
+
/**
|
|
135
|
+
* A text value as the player shows it: the source translated with the
|
|
136
|
+
* plugin's catalog and formatted with its (rendered) arguments; a list's
|
|
137
|
+
* items joined with the locale's separator.
|
|
138
|
+
*/
|
|
139
|
+
export declare function renderText(value: TextJson | ListJson, catalog: Catalog, locale: string): string;
|
|
140
|
+
/**
|
|
141
|
+
* Template arguments with their texts rendered (for `format`): what the
|
|
142
|
+
* player fills a template with.
|
|
143
|
+
*/
|
|
144
|
+
export declare function renderTemplateArgs(args: TemplateArgsLike | undefined, catalog: Catalog, locale: string): TemplateArgsValue | undefined;
|
|
145
|
+
/** The English rendering of a text value: the key a menu merges by. */
|
|
146
|
+
export declare function textKey(value: TextJson | ListJson): string;
|
|
147
|
+
/**
|
|
148
|
+
* A property value with every text value in it replaced by its shown
|
|
149
|
+
* string, as the player does before it hands the value to Slint. Returns
|
|
150
|
+
* a problem (`textProblem`) instead when a text value is malformed.
|
|
151
|
+
*/
|
|
152
|
+
export declare function resolveTexts<T>(value: T, catalog: Catalog, locale: string): {
|
|
153
|
+
value: T;
|
|
154
|
+
} | {
|
|
155
|
+
problem: string;
|
|
156
|
+
};
|
|
157
|
+
/** Whether a value holds a text value anywhere (a cheap pre-check). */
|
|
158
|
+
export declare function hasTexts(value: unknown): boolean;
|
|
159
|
+
/** One `@tr("context" => "id" | "plural" % n, args…)` call. */
|
|
160
|
+
export interface TrCall {
|
|
161
|
+
context?: string;
|
|
162
|
+
id: string;
|
|
163
|
+
plural?: string;
|
|
164
|
+
/** 1-based line of `@tr`. */
|
|
165
|
+
line: number;
|
|
166
|
+
/** Source offsets of the id literal (quotes included). */
|
|
167
|
+
idSpan: [number, number];
|
|
168
|
+
/** And of the plural literal. */
|
|
169
|
+
pluralSpan?: [number, number];
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Every `@tr` call of a Slint source, in order; the same scanner as the
|
|
173
|
+
* player's (both run the shared cases of the player's
|
|
174
|
+
* `src/host/tests/fixtures/slint-tr.json`). Comments, strings and string
|
|
175
|
+
* interpolation are skipped; a malformed call is left out.
|
|
176
|
+
*/
|
|
177
|
+
export declare function scanSlint(source: string): TrCall[];
|
|
178
|
+
/** A Slint string literal for `text`. */
|
|
179
|
+
export declare function slintQuote(text: string): string;
|
|
180
|
+
/** `source` with its `@tr` literals translated (what the player compiles). */
|
|
181
|
+
export declare function rewriteSlint(source: string, catalog: Catalog): string;
|
|
182
|
+
/**
|
|
183
|
+
* The supported locale for a BCP 47 tag, as the player maps the system's
|
|
184
|
+
* languages: Simplified Chinese is `zh-Hans`; Traditional Chinese (`zh-Hant`,
|
|
185
|
+
* or Taiwan, Hong Kong, Macao) is English; other languages by their primary
|
|
186
|
+
* subtag; `undefined` for a language the player does not have.
|
|
187
|
+
*/
|
|
188
|
+
export declare function matchLocale(tag: string): (typeof LOCALES)[number] | undefined;
|
|
189
|
+
/**
|
|
190
|
+
* The player's built-in top-level menus: id → key (the English text paths
|
|
191
|
+
* merge by), as the player's `MENU_ANCHORS`.
|
|
192
|
+
*/
|
|
193
|
+
export declare const MENU_KEYS: Readonly<Record<string, string>>;
|
|
194
|
+
/** The player's own submenus, by key path (their labels are the player's). */
|
|
195
|
+
export declare const HOST_GROUPS: string[];
|
|
196
|
+
/**
|
|
197
|
+
* The keys a path merges by, as the player normalizes it: `@id` becomes the
|
|
198
|
+
* built-in menu's key, the player's old Chinese titles of its own submenus
|
|
199
|
+
* their keys.
|
|
200
|
+
*/
|
|
201
|
+
export declare function menuKeys(path: readonly string[]): string[];
|
|
202
|
+
/**
|
|
203
|
+
* The player's own texts that the test host repeats (core actions, its
|
|
204
|
+
* refusals, its menus), English → the player's Simplified Chinese
|
|
205
|
+
* (`src/host/locales/zh-Hans.po` in the player; its tests check that they
|
|
206
|
+
* agree).
|
|
207
|
+
*/
|
|
208
|
+
export declare const HOST_ZH_HANS: Readonly<Record<string, string>>;
|
|
209
|
+
/**
|
|
210
|
+
* The catalog of a package directory for `locale`, as the player loads it:
|
|
211
|
+
* the compiled `locales/<lang>.json` of a built package, else the source
|
|
212
|
+
* `locales/<lang>.po`. Empty for English and without a file; a broken file
|
|
213
|
+
* throws.
|
|
214
|
+
*/
|
|
215
|
+
export declare function loadPackageCatalog(directory: string, locale: string): Catalog;
|
|
216
|
+
/**
|
|
217
|
+
* Each line of `text` cut to `max` columns, ending with `…` when cut, as
|
|
218
|
+
* the player cuts an OSD panel's lines (`OsdPanelOptions.maxColumns`; the
|
|
219
|
+
* player measures with Unicode's East Asian Width, this is close to it).
|
|
220
|
+
*/
|
|
221
|
+
export declare function fitColumns(text: string, max: number): string;
|
|
222
|
+
export {};
|