@vestra-player/sdk 1.6.19 → 1.6.21
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 +19 -0
- package/dist/commands.js +19 -18
- package/dist/docs-tree.json.gz +0 -0
- package/dist/i18n-tools.js +7 -2
- package/dist/plugin/runtime.d.ts +1 -0
- package/dist/plugin/runtime.js +3 -0
- package/dist/plugin/types/base.d.ts +1097 -0
- package/dist/plugin/types/base.js +1 -0
- package/dist/plugin/types/commands.d.ts +1189 -0
- package/dist/plugin/types/commands.js +1 -0
- package/dist/plugin/types/packages.d.ts +661 -0
- package/dist/plugin/types/packages.js +1 -0
- package/dist/plugin/types/playback.d.ts +1654 -0
- package/dist/plugin/types/playback.js +1 -0
- package/dist/plugin/types/processing.d.ts +974 -0
- package/dist/plugin/types/processing.js +1 -0
- package/dist/plugin/types/services.d.ts +1132 -0
- package/dist/plugin/types/services.js +1 -0
- package/dist/plugin/types/snapshots.d.ts +491 -0
- package/dist/plugin/types/snapshots.js +1 -0
- package/dist/plugin/types/sources.d.ts +302 -0
- package/dist/plugin/types/sources.js +1 -0
- package/dist/plugin/types/subtitles.d.ts +327 -0
- package/dist/plugin/types/subtitles.js +1 -0
- package/dist/plugin/types/ui-content.d.ts +692 -0
- package/dist/plugin/types/ui-content.js +1 -0
- package/dist/plugin/types/ui-layout.d.ts +1079 -0
- package/dist/plugin/types/ui-layout.js +1 -0
- package/dist/plugin/types/ui-locale.d.ts +490 -0
- package/dist/plugin/types/ui-locale.js +1 -0
- package/dist/plugin/types/ui-shell.d.ts +1072 -0
- package/dist/plugin/types/ui-shell.js +1 -0
- package/dist/plugin/types.d.ts +18 -11072
- package/llms.txt +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,490 @@
|
|
|
1
|
+
import type { Scope } from "./base.ts";
|
|
2
|
+
import type { FileResolverOptions, WebResolverOptions } from "./sources.ts";
|
|
3
|
+
import type { ConfirmOptions, Dialogs, Osd, OsdPanel } from "./ui-shell.ts";
|
|
4
|
+
import type { Disposable } from "./base.ts";
|
|
5
|
+
/**
|
|
6
|
+
* The player's palettes: `vestra`, the dark default, and `vestra-light`
|
|
7
|
+
* (player 0.4.0, SDK 1.5.0), a light palette whose video area stays dark.
|
|
8
|
+
* Both draw on the logo's colours. Read colours from `Theme` instead of
|
|
9
|
+
* branching on the id: a later version may add palettes.
|
|
10
|
+
*
|
|
11
|
+
* @remarks
|
|
12
|
+
* The player treats an id it does not have as `vestra`: plugins built with an
|
|
13
|
+
* older SDK that still ask for a palette removed in SDK 1.4.0 keep working,
|
|
14
|
+
* and a player older than 0.4.0 answers `vestra-light` with `vestra`.
|
|
15
|
+
*
|
|
16
|
+
* @since 1.0.0
|
|
17
|
+
* @category UI
|
|
18
|
+
*/
|
|
19
|
+
export type ThemeId = "vestra" | "vestra-light";
|
|
20
|
+
/**
|
|
21
|
+
* The player's palette, which every view uses. `plugin.appearance`.
|
|
22
|
+
*
|
|
23
|
+
* @remarks
|
|
24
|
+
* The player sets the palette on every view (the main window and its panels,
|
|
25
|
+
* the floating sidebar, tool windows, the Options window) before it appears
|
|
26
|
+
* and again when the palette changes. Slint code that reads its colours from
|
|
27
|
+
* `Theme` (`import { Theme } from "@vestra/theme.slint"`) follows it with no
|
|
28
|
+
* plugin code; hard-coded colours do not. Only colours change: corner radii,
|
|
29
|
+
* font sizes and control sizes are the same in every palette. A light palette
|
|
30
|
+
* also switches the std-widgets controls (`std-widgets.slint`) to their light
|
|
31
|
+
* colours, and keeps the video area dark.
|
|
32
|
+
*
|
|
33
|
+
* The player saves the choice; it stays after the plugin that set it stops.
|
|
34
|
+
* Tell the user about a change yourself (for example with
|
|
35
|
+
* {@link Osd.show}).
|
|
36
|
+
*
|
|
37
|
+
* @capability None to read `theme`; `events` to follow changes; `ui.theme`
|
|
38
|
+
* to change it.
|
|
39
|
+
*
|
|
40
|
+
* @example Offer the light palette as a menu item
|
|
41
|
+
* Settings ▸ Light colours switches every view of the player to the light
|
|
42
|
+
* palette and carries a radio mark while it is in use. `set` asks the
|
|
43
|
+
* player to switch (it saves the choice); `theme` holds the palette in use,
|
|
44
|
+
* and `checked` reads it again after every handler.
|
|
45
|
+
* ```ts
|
|
46
|
+
* plugin.commands.add({
|
|
47
|
+
* id: "light-colours",
|
|
48
|
+
* path: ["@settings", "Light colours"],
|
|
49
|
+
* radio: true, // a round mark instead of a check mark
|
|
50
|
+
* checked: () => plugin.appearance.theme === "vestra-light",
|
|
51
|
+
* run: () => plugin.appearance.set("vestra-light"),
|
|
52
|
+
* });
|
|
53
|
+
* ```
|
|
54
|
+
*
|
|
55
|
+
* @see [Windows, panels, settings pages, dialogs and the OSD](../../../docs/explanation/ui.md) (theme tokens)
|
|
56
|
+
* @since 1.0.0
|
|
57
|
+
* @category UI
|
|
58
|
+
*/
|
|
59
|
+
export interface Appearance {
|
|
60
|
+
/**
|
|
61
|
+
* The palette in use. Read before activation; with `events` it follows
|
|
62
|
+
* other plugins' changes from the first read on, without it only this
|
|
63
|
+
* plugin's own.
|
|
64
|
+
*/
|
|
65
|
+
readonly theme: ThemeId;
|
|
66
|
+
/**
|
|
67
|
+
* Run code when the palette changes.
|
|
68
|
+
*
|
|
69
|
+
* @remarks
|
|
70
|
+
* Needs `events`: without it the listener never runs for other plugins'
|
|
71
|
+
* changes. Views need no help to follow the palette; use this for things
|
|
72
|
+
* the plugin draws itself (a rendered image, colours it computes). Errors
|
|
73
|
+
* go to {@link Scope.onError}. When the player starts a stopped plugin
|
|
74
|
+
* for a palette change (player 0.5.21), {@link Appearance.theme} already
|
|
75
|
+
* has the new palette at start and the listener still hears the change
|
|
76
|
+
* (SDK 1.5.56; before, it did not run). A language change does not call
|
|
77
|
+
* it, except in one case: a plugin started for a language change alone
|
|
78
|
+
* may hear the unchanged palette once, since the player's event does not
|
|
79
|
+
* say which of the two changed.
|
|
80
|
+
*
|
|
81
|
+
* @capability events
|
|
82
|
+
*
|
|
83
|
+
* @param listener - Receives the new palette.
|
|
84
|
+
* @returns A handle that removes the listener.
|
|
85
|
+
*
|
|
86
|
+
* @example Redraw a picture the plugin renders when the palette changes
|
|
87
|
+
* The plugin renders a chart image in the palette's colours and draws it
|
|
88
|
+
* again when the user or another plugin switches palettes. Views that use
|
|
89
|
+
* `Theme` follow on their own; this listener (which needs `events`) is
|
|
90
|
+
* for what the plugin draws itself.
|
|
91
|
+
* ```ts
|
|
92
|
+
* declare function renderChart(dark: boolean): Promise<void>;
|
|
93
|
+
* // ---cut---
|
|
94
|
+
* plugin.appearance.onChange((theme) => {
|
|
95
|
+
* void renderChart(theme === "vestra"); // the dark default
|
|
96
|
+
* });
|
|
97
|
+
* ```
|
|
98
|
+
*
|
|
99
|
+
* @since 1.0.0
|
|
100
|
+
*/
|
|
101
|
+
onChange(listener: (theme: ThemeId) => void): Disposable;
|
|
102
|
+
/**
|
|
103
|
+
* Switch the palette of every view.
|
|
104
|
+
*
|
|
105
|
+
* @remarks
|
|
106
|
+
* The player applies it to every open view without interrupting a drag or
|
|
107
|
+
* an open menu, and saves it across restarts.
|
|
108
|
+
*
|
|
109
|
+
* @capability ui.theme
|
|
110
|
+
*
|
|
111
|
+
* @param theme - The palette to use.
|
|
112
|
+
* @returns Resolves once the player has accepted the change;
|
|
113
|
+
* {@link Appearance.theme} has the new value.
|
|
114
|
+
*
|
|
115
|
+
* @throws `invalid` (rejects) `theme` is not a {@link ThemeId}.
|
|
116
|
+
* @throws `capability` (rejects) The manifest does not declare `ui.theme`.
|
|
117
|
+
*
|
|
118
|
+
* @example Switch to the light palette
|
|
119
|
+
* Every view of the player turns light, and stays light after a restart.
|
|
120
|
+
* The player applies the palette to every open view and saves the
|
|
121
|
+
* choice; when the promise resolves, `appearance.theme` already has the
|
|
122
|
+
* new value. Without `ui.theme` it rejects with `capability`.
|
|
123
|
+
* ```ts
|
|
124
|
+
* await plugin.appearance.set("vestra-light");
|
|
125
|
+
* ```
|
|
126
|
+
*
|
|
127
|
+
* @since 1.0.0
|
|
128
|
+
*/
|
|
129
|
+
set(theme: ThemeId): Promise<void>;
|
|
130
|
+
/**
|
|
131
|
+
* The saved interface language: `"system"` (follow the system's
|
|
132
|
+
* languages, the default) or a {@link Locale}.
|
|
133
|
+
*
|
|
134
|
+
* @remarks
|
|
135
|
+
* This is the choice for the next start. The language of this run is
|
|
136
|
+
* {@link I18n.locale} and never changes while the player runs. Read before
|
|
137
|
+
* activation; with `events` it follows other plugins' changes, without it
|
|
138
|
+
* only this plugin's own. Players before 0.4.3 report `"system"`.
|
|
139
|
+
*
|
|
140
|
+
* @since 1.5.9
|
|
141
|
+
*/
|
|
142
|
+
readonly language: LanguagePreference;
|
|
143
|
+
/**
|
|
144
|
+
* Save the interface language for the next start.
|
|
145
|
+
*
|
|
146
|
+
* @remarks
|
|
147
|
+
* The player keeps the choice in its interface state; the language
|
|
148
|
+
* changes when the player starts again (tell the user, for example "Takes
|
|
149
|
+
* effect after restart"). Every plugin with `events` hears the change in
|
|
150
|
+
* {@link Appearance.language}.
|
|
151
|
+
*
|
|
152
|
+
* @capability ui.theme
|
|
153
|
+
* @player 0.4.3
|
|
154
|
+
*
|
|
155
|
+
* @param language - `"system"` or a {@link Locale}.
|
|
156
|
+
* @returns Resolves once the player saved it; {@link Appearance.language}
|
|
157
|
+
* has the new value.
|
|
158
|
+
*
|
|
159
|
+
* @throws `invalid` (rejects) `language` is not `"system"` or a {@link Locale}.
|
|
160
|
+
* @throws `capability` (rejects) The manifest does not declare `ui.theme`.
|
|
161
|
+
* @throws `unsupported` (rejects) A player before 0.4.3.
|
|
162
|
+
*
|
|
163
|
+
* @example Choose German for the next start
|
|
164
|
+
* The player will start in German next time, and the user is told so.
|
|
165
|
+
* `setLanguage` only saves the choice: the language of this run
|
|
166
|
+
* (`i18n.locale`) never changes while the player runs. Players before
|
|
167
|
+
* 0.4.3 reject it with `unsupported`.
|
|
168
|
+
* ```ts
|
|
169
|
+
* await plugin.appearance.setLanguage("de");
|
|
170
|
+
* await plugin.osd.show("Takes effect after restart"); // translated by the player
|
|
171
|
+
* ```
|
|
172
|
+
*
|
|
173
|
+
* @since 1.5.9
|
|
174
|
+
*/
|
|
175
|
+
setLanguage(language: LanguagePreference): Promise<void>;
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* An interface language of the player: English (`en`, the source language
|
|
179
|
+
* of every plugin text) or a translation. The list is `LOCALES` in
|
|
180
|
+
* `@vestra-player/sdk/testing`.
|
|
181
|
+
*
|
|
182
|
+
* @remarks
|
|
183
|
+
* Simplified Chinese is `zh-Hans`. There is no Traditional Chinese: a
|
|
184
|
+
* system set to Traditional Chinese (Taiwan, Hong Kong, Macao) gets English.
|
|
185
|
+
*
|
|
186
|
+
* @since 1.5.9
|
|
187
|
+
* @category UI
|
|
188
|
+
*/
|
|
189
|
+
export type Locale = "en" | "zh-Hans" | "ja" | "ko" | "de" | "fr" | "es";
|
|
190
|
+
/**
|
|
191
|
+
* The saved interface language ({@link Appearance.language}): follow the
|
|
192
|
+
* system, or one {@link Locale}.
|
|
193
|
+
*
|
|
194
|
+
* @since 1.5.9
|
|
195
|
+
* @category UI
|
|
196
|
+
*/
|
|
197
|
+
export type LanguagePreference = "system" | Locale;
|
|
198
|
+
/**
|
|
199
|
+
* Arguments of a template sentence ({@link Osd.show},
|
|
200
|
+
* {@link OsdPanel.set}, {@link ConfirmOptions.args}, {@link I18n.text}): an
|
|
201
|
+
* array for `{}` and `{0}`, `{1}` placeholders, or an object for `{name}`
|
|
202
|
+
* placeholders. At most 16. Strings and finite numbers are data, shown as
|
|
203
|
+
* they are (whole numbers without a fraction); a {@link Text} or
|
|
204
|
+
* {@link TextList} argument (SDK 1.5.11, player 0.4.3) is translated too,
|
|
205
|
+
* so a sentence can be built from translated parts.
|
|
206
|
+
*
|
|
207
|
+
* @since 1.5.9
|
|
208
|
+
* @category UI
|
|
209
|
+
*/
|
|
210
|
+
export type TemplateArgs = readonly TextArg[] | Readonly<Record<string, TextArg>>;
|
|
211
|
+
/**
|
|
212
|
+
* A text the player translates with the plugin's catalog and fills in:
|
|
213
|
+
* English source text with its arguments. Made by {@link I18n.text}; plain
|
|
214
|
+
* data, not a translation (the plugin never sees the translated string).
|
|
215
|
+
*
|
|
216
|
+
* @remarks
|
|
217
|
+
* Accepted wherever the player shows a plugin's text: command titles, path
|
|
218
|
+
* segments and reasons, {@link Osd.show} and {@link OsdPanel.set} (as the
|
|
219
|
+
* text or an argument), the texts of {@link Dialogs.confirm}, file dialog
|
|
220
|
+
* titles and `saveFile`'s `fileName`, and property values where Slint
|
|
221
|
+
* expects a `string` (at any depth: a `[string]` model, a struct field).
|
|
222
|
+
* Nested in another text's arguments it is translated too. Requires player
|
|
223
|
+
* 0.4.3. Limits: `TEXT_LIMITS` in `@vestra-player/sdk/testing`.
|
|
224
|
+
*
|
|
225
|
+
* The wire form `{ $vestraText, args }` is what the player reads; write it
|
|
226
|
+
* with {@link I18n.text}, so that `vestra-plugin i18n extract` finds the
|
|
227
|
+
* source text.
|
|
228
|
+
*
|
|
229
|
+
* @since 1.5.11
|
|
230
|
+
* @category UI
|
|
231
|
+
*/
|
|
232
|
+
export interface Text {
|
|
233
|
+
/** The English source text: a template with `{}`, `{0}` or `{name}`. */
|
|
234
|
+
readonly $vestraText: string;
|
|
235
|
+
/** Values for its placeholders. */
|
|
236
|
+
readonly args?: TemplateArgs;
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
239
|
+
* Values joined the way the interface language joins them ("a, b" in
|
|
240
|
+
* English, "a、b" in Chinese). Made by {@link I18n.list}; accepted where a
|
|
241
|
+
* {@link Text} is.
|
|
242
|
+
*
|
|
243
|
+
* @since 1.5.11
|
|
244
|
+
* @category UI
|
|
245
|
+
*/
|
|
246
|
+
export interface TextList {
|
|
247
|
+
/** The items: data, or texts the player translates. */
|
|
248
|
+
readonly $vestraList: readonly TextArg[];
|
|
249
|
+
/** How they are joined; `"list"` by default. */
|
|
250
|
+
readonly style?: ListStyle;
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* How a {@link TextList} is joined, per interface language:
|
|
254
|
+
*
|
|
255
|
+
* | style | English | 简体中文 | 日本語 |
|
|
256
|
+
* | --- | --- | --- | --- |
|
|
257
|
+
* | `list` (enumeration) | `, ` | `、` | `、` |
|
|
258
|
+
* | `clauses` (parts of one sentence) | `, ` | `,` | `、` |
|
|
259
|
+
* | `semicolons` | `; ` | `;` | `;` |
|
|
260
|
+
* | `sentences` (no final full stop) | `. ` | `。` | `。` |
|
|
261
|
+
* | `lines` | line break | line break | line break |
|
|
262
|
+
*
|
|
263
|
+
* Korean, German and Spanish join as English; French puts a narrow space
|
|
264
|
+
* before `;`.
|
|
265
|
+
*
|
|
266
|
+
* @since 1.5.11
|
|
267
|
+
* @category UI
|
|
268
|
+
*/
|
|
269
|
+
export type ListStyle = "list" | "clauses" | "semicolons" | "sentences" | "lines";
|
|
270
|
+
/**
|
|
271
|
+
* An argument of a template: data (a string or a finite number, shown as it
|
|
272
|
+
* is) or a {@link Text} or {@link TextList} (translated).
|
|
273
|
+
*
|
|
274
|
+
* @since 1.5.11
|
|
275
|
+
* @category UI
|
|
276
|
+
*/
|
|
277
|
+
export type TextArg = string | number | Text | TextList;
|
|
278
|
+
/**
|
|
279
|
+
* A text the player shows: English source text (translated as a whole), a
|
|
280
|
+
* {@link Text} or a {@link TextList}.
|
|
281
|
+
*
|
|
282
|
+
* @since 1.5.11
|
|
283
|
+
* @category UI
|
|
284
|
+
*/
|
|
285
|
+
export type TextValue = string | Text | TextList;
|
|
286
|
+
/**
|
|
287
|
+
* The interface language of this run. `plugin.i18n`.
|
|
288
|
+
*
|
|
289
|
+
* @remarks
|
|
290
|
+
* Plugins write no translation code. Every user-visible text is English
|
|
291
|
+
* source text in one of three places, and the player translates it with
|
|
292
|
+
* the plugin's own catalog (`locales/<lang>.po`, compiled into the package
|
|
293
|
+
* by `vestra-plugin build`):
|
|
294
|
+
*
|
|
295
|
+
* 1. declarations: command titles and paths, settings page and panel
|
|
296
|
+
* titles, the manifest's `name`, `punchline`, `description` and `tags`;
|
|
297
|
+
* 2. Slint: `@tr("…")` in the plugin's `.slint` files;
|
|
298
|
+
* 3. sentences the plugin hands the player: {@link Osd.show},
|
|
299
|
+
* {@link OsdPanel.set} and {@link Dialogs.confirm} take a template and
|
|
300
|
+
* its arguments (`osd.show("Speed {}×", [rate])`), never a sentence
|
|
301
|
+
* composed in TypeScript.
|
|
302
|
+
*
|
|
303
|
+
* Where words and data cannot be separated that way (a menu item with a
|
|
304
|
+
* number, a `[string]` model, a sentence made of translated parts), the
|
|
305
|
+
* plugin passes a text value ({@link I18n.text}, {@link I18n.list}; SDK
|
|
306
|
+
* 1.5.11): data the player translates, never a translated string.
|
|
307
|
+
*
|
|
308
|
+
* The language is fixed when the player starts: {@link I18n.locale} never
|
|
309
|
+
* changes during a run. Read it for what is not text, such as the order of
|
|
310
|
+
* names or a date format. `vestra-plugin i18n extract` collects the texts
|
|
311
|
+
* into `locales/messages.pot`; see the
|
|
312
|
+
* [i18n guide](../../../docs/how-to/i18n.md).
|
|
313
|
+
*
|
|
314
|
+
* @capability None.
|
|
315
|
+
*
|
|
316
|
+
* @example Format a date the way the interface language writes it
|
|
317
|
+
* The OSD shows today's date in the user's language and date format. The
|
|
318
|
+
* sentence is a template the player translates; only the data in it, the
|
|
319
|
+
* date, is formatted by the plugin, with `i18n.locale` (the language the
|
|
320
|
+
* player runs in, fixed for the whole run).
|
|
321
|
+
* ```ts
|
|
322
|
+
* const day = new Date().toLocaleDateString(plugin.i18n.locale);
|
|
323
|
+
* await plugin.osd.show("Today is {}", [day]);
|
|
324
|
+
* ```
|
|
325
|
+
*
|
|
326
|
+
* @since 1.5.9
|
|
327
|
+
* @category UI
|
|
328
|
+
*/
|
|
329
|
+
export interface I18n {
|
|
330
|
+
/**
|
|
331
|
+
* The interface language of this run, chosen at start-up from the saved
|
|
332
|
+
* {@link Appearance.language} or the system's languages; English when
|
|
333
|
+
* neither names a {@link Locale}. Players before 0.4.3 report `"en"`.
|
|
334
|
+
*/
|
|
335
|
+
readonly locale: Locale;
|
|
336
|
+
/**
|
|
337
|
+
* A text that mixes words with data, for the player to translate: the
|
|
338
|
+
* English source text (a template) and its arguments. It returns a plain
|
|
339
|
+
* {@link Text} value, not a translation; pass it where the player shows
|
|
340
|
+
* text (see {@link Text}) and the player shows it translated with this
|
|
341
|
+
* plugin's catalog. `vestra-plugin i18n extract` collects `source` from
|
|
342
|
+
* every call, so write it as a literal (or a conditional of literals, or
|
|
343
|
+
* an `as const` table entry).
|
|
344
|
+
*
|
|
345
|
+
* Arguments are data unless they are texts themselves, so a sentence can
|
|
346
|
+
* be built from translated parts without composing it in TypeScript.
|
|
347
|
+
* `text` does not use `this`: `const { text, list } = plugin.i18n` works.
|
|
348
|
+
*
|
|
349
|
+
* @param source - English source text; `{}`, `{0}` or `{name}` for the
|
|
350
|
+
* arguments, `{{` and `}}` for braces.
|
|
351
|
+
* @param args - Values for its placeholders.
|
|
352
|
+
* @throws `invalid` A malformed or over-limit value (`TEXT_LIMITS`).
|
|
353
|
+
*
|
|
354
|
+
* @example Fill a drop-down with fixed words and data
|
|
355
|
+
* The drop-down lists "No Audio" and one "Track 7 · en" entry per track,
|
|
356
|
+
* in the user's language. A `[string]` model may hold `text()` values: the
|
|
357
|
+
* player translates each source text with the plugin's catalog and fills
|
|
358
|
+
* in its arguments, so the plugin never composes translated strings.
|
|
359
|
+
* ```ts
|
|
360
|
+
* const { text } = plugin.i18n;
|
|
361
|
+
* const picker = plugin.windows.create("ui/clip.slint");
|
|
362
|
+
* const tracks = [{ id: 7, title: "en" }];
|
|
363
|
+
* // Each entry is translated, then filled in: "Track 7 · en".
|
|
364
|
+
* picker.set({
|
|
365
|
+
* labels: [text("No Audio"), ...tracks.map((t) => text("Track {} · {}", [t.id, t.title]))],
|
|
366
|
+
* });
|
|
367
|
+
* ```
|
|
368
|
+
*
|
|
369
|
+
* @example Build a message from translated parts
|
|
370
|
+
* The OSD says "Download failed: Connection timed out", both parts in the
|
|
371
|
+
* user's language. An argument made with `text()` is translated too,
|
|
372
|
+
* while string arguments are shown as they are.
|
|
373
|
+
* ```ts
|
|
374
|
+
* await plugin.osd.show("Download failed: {}", [plugin.i18n.text("Connection timed out")]);
|
|
375
|
+
* ```
|
|
376
|
+
*
|
|
377
|
+
* @capability None.
|
|
378
|
+
*
|
|
379
|
+
* @since 1.5.11
|
|
380
|
+
*/
|
|
381
|
+
text(source: string, args?: TemplateArgs): Text;
|
|
382
|
+
/**
|
|
383
|
+
* Items joined the way the interface language joins them (see
|
|
384
|
+
* {@link ListStyle}): `list(["a.glsl", "b.glsl"])` shows "a.glsl, b.glsl"
|
|
385
|
+
* in English and "a.glsl、b.glsl" in Chinese. Items are data, or texts the
|
|
386
|
+
* player translates. Accepted where a {@link Text} is.
|
|
387
|
+
*
|
|
388
|
+
* @param items - At most 256.
|
|
389
|
+
* @param style - `"list"` by default.
|
|
390
|
+
* @throws `invalid` A malformed or over-limit value.
|
|
391
|
+
*
|
|
392
|
+
* @example List file names the way the language joins them
|
|
393
|
+
* The OSD says "Removed missing shaders: a.glsl, b.glsl" in English and
|
|
394
|
+
* joins the names with "、" in Chinese. `list` makes a value the player
|
|
395
|
+
* joins per interface language; the names themselves are data and stay
|
|
396
|
+
* as they are.
|
|
397
|
+
* ```ts
|
|
398
|
+
* const missing = ["a.glsl", "b.glsl"];
|
|
399
|
+
* await plugin.osd.show("Removed missing shaders: {}", [plugin.i18n.list(missing)]);
|
|
400
|
+
* ```
|
|
401
|
+
*
|
|
402
|
+
* @capability None.
|
|
403
|
+
*
|
|
404
|
+
* @since 1.5.11
|
|
405
|
+
*/
|
|
406
|
+
list(items: readonly TextArg[], style?: ListStyle): TextList;
|
|
407
|
+
/**
|
|
408
|
+
* An `Error` whose words the player shows translated: throw it where the
|
|
409
|
+
* player shows a plugin's failure to the user, such as from a
|
|
410
|
+
* file or web resolver's `resolve` ({@link FileResolverOptions}, {@link WebResolverOptions}) (also when a stream
|
|
411
|
+
* fails while it starts). The player shows `text` translated with this
|
|
412
|
+
* plugin's catalog (as `player.state.error` and the failure message);
|
|
413
|
+
* `message` is the English rendering, for logs and older players.
|
|
414
|
+
* Elsewhere it is an ordinary `Error`.
|
|
415
|
+
*
|
|
416
|
+
* @param source - English source text, as {@link I18n.text}'s.
|
|
417
|
+
* @param args - Values for its placeholders.
|
|
418
|
+
* @throws `invalid` A malformed or over-limit value.
|
|
419
|
+
*
|
|
420
|
+
* @example Fail an open with a message the user can read
|
|
421
|
+
* Opening a `.ch8` file the plugin cannot load shows "The program file
|
|
422
|
+
* was not found." in the user's language. The player shows the message of
|
|
423
|
+
* an error thrown from `resolve`; `i18n.error` makes an `Error` whose text
|
|
424
|
+
* the player translates with this plugin's catalog, while its `message`
|
|
425
|
+
* stays English for logs and older players.
|
|
426
|
+
* ```ts
|
|
427
|
+
* import { readFile } from "node:fs/promises";
|
|
428
|
+
* declare function startEmulator(program: Uint8Array): ResolvedStream;
|
|
429
|
+
* // ---cut---
|
|
430
|
+
* plugin.resolvers.add({
|
|
431
|
+
* id: "chip8",
|
|
432
|
+
* extensions: ["ch8"],
|
|
433
|
+
* async resolve(path, signal) {
|
|
434
|
+
* const program = await readFile(path, { signal }).catch(() => {
|
|
435
|
+
* // Shown as the open's failure, translated (locales/<lang>.po).
|
|
436
|
+
* throw plugin.i18n.error("The program file was not found.");
|
|
437
|
+
* });
|
|
438
|
+
* return startEmulator(program);
|
|
439
|
+
* },
|
|
440
|
+
* });
|
|
441
|
+
* ```
|
|
442
|
+
*
|
|
443
|
+
* @capability None.
|
|
444
|
+
*
|
|
445
|
+
* @since 1.5.11
|
|
446
|
+
*/
|
|
447
|
+
error(source: string, args?: TemplateArgs): TextError;
|
|
448
|
+
/**
|
|
449
|
+
* The string a text shows in this run's language, for text that leaves
|
|
450
|
+
* the player: what the plugin copies to the clipboard or writes to a file
|
|
451
|
+
* ("Copy info", "Save as…"). Translated with this plugin's catalog (a
|
|
452
|
+
* string as a whole, a {@link Text} or {@link TextList} with its
|
|
453
|
+
* arguments), the way the player would show it.
|
|
454
|
+
*
|
|
455
|
+
* Only for text leaving the player. Never use it for the interface (a
|
|
456
|
+
* window, the menu, the OSD, a dialog): pass the value itself there, so
|
|
457
|
+
* the player translates it and `vestra-plugin i18n check` can see the
|
|
458
|
+
* sentence is whole.
|
|
459
|
+
*
|
|
460
|
+
* @param value - Source text, or a text value.
|
|
461
|
+
* @returns The translated string.
|
|
462
|
+
* @throws `invalid` A malformed value.
|
|
463
|
+
*
|
|
464
|
+
* @example Copy version information in the user's language
|
|
465
|
+
* "Copy info" puts two translated lines on the clipboard. Text that
|
|
466
|
+
* leaves the player cannot be translated by it, so `resolve` turns the
|
|
467
|
+
* values into the string the player would show, using this plugin's
|
|
468
|
+
* catalog; inside the player, pass the values themselves instead.
|
|
469
|
+
* ```ts
|
|
470
|
+
* const { text, list, resolve } = plugin.i18n;
|
|
471
|
+
* const lines = list([text("Version {}", ["1.0"]), text("Cores: {}", [8])], "lines");
|
|
472
|
+
* await plugin.clipboard.writeText(resolve(lines));
|
|
473
|
+
* ```
|
|
474
|
+
*
|
|
475
|
+
* @capability None.
|
|
476
|
+
*
|
|
477
|
+
* @since 1.5.11
|
|
478
|
+
*/
|
|
479
|
+
resolve(value: TextValue): string;
|
|
480
|
+
}
|
|
481
|
+
/**
|
|
482
|
+
* An `Error` the player shows translated ({@link I18n.error}).
|
|
483
|
+
*
|
|
484
|
+
* @since 1.5.11
|
|
485
|
+
* @category UI
|
|
486
|
+
*/
|
|
487
|
+
export interface TextError extends Error {
|
|
488
|
+
/** What the player shows. */
|
|
489
|
+
readonly text: Text;
|
|
490
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|