@vestra-player/sdk - v1.11.3
    Preparing search index...

    Interface I18n

    The interface language of this run. plugin.i18n.

    Plugins write no translation code. Every user-visible text is English source text in one of three places, and the player translates it with the plugin's own catalog (locales/<lang>.po, compiled into the package by vestra-plugin build):

    1. declarations: command titles and paths, settings page and panel titles, the manifest's name, punchline, description and tags;
    2. Slint: @tr("…") in the plugin's .slint files;
    3. sentences the plugin hands the player: Osd.show, OsdPanel.set and Dialogs.confirm take a template and its arguments (osd.show("Speed {}×", [rate])), never a sentence composed in TypeScript.

    Where words and data cannot be separated that way (a menu item with a number, a [string] model, a sentence made of translated parts), the plugin passes a text value (I18n.text, I18n.list): data the player translates, never a translated string.

    The language is fixed when the player starts: I18n.locale never changes during a run. Read it for what is not text, such as the order of names or a date format. vestra-plugin i18n extract collects the texts into locales/messages.pot; see the i18n guide.

    The OSD shows today's date in the user's language and date format. The sentence is a template the player translates; only the data in it, the date, is formatted by the plugin, with i18n.locale (the language the player runs in, fixed for the whole run).

    const day = new Date().toLocaleDateString(plugin.i18n.locale);
    await plugin.osd.show("Today is {}", [day]);

    1.5.9

    interface I18n {
        locale: Locale;
        text(source: string, args?: TemplateArgs): Text;
        list(items: readonly TextArg[], style?: ListStyle): TextList;
        error(source: string, args?: TemplateArgs): TextError;
        resolve(value: TextValue): string;
    }
    Index
    • A text that mixes words with data, for the player to translate: the English source text (a template) and its arguments. It returns a plain Text value, not a translation; pass it where the player shows text (see Text) and the player shows it translated with this plugin's catalog. vestra-plugin i18n extract collects source from every call, so write it as a literal (or a conditional of literals, or an as const table entry).

      Arguments are data unless they are texts themselves, so a sentence can be built from translated parts without composing it in TypeScript. text does not use this: const { text, list } = plugin.i18n works.

      Parameters

      • source: string

        English source text; {}, {0} or {name} for the arguments, {{ and }} for braces.

      • Optionalargs: TemplateArgs

        Values for its placeholders.

      Returns Text

      invalid A malformed or over-limit value (TEXT_LIMITS).

      The drop-down lists "No Audio" and one "Track 7 · en" entry per track, in the user's language. A [string] model may hold text() values: the player translates each source text with the plugin's catalog and fills in its arguments, so the plugin never composes translated strings.

      const { text } = plugin.i18n;
      const picker = plugin.windows.create("ui/clip.slint");
      const tracks = [{ id: 7, title: "en" }];
      // Each entry is translated, then filled in: "Track 7 · en".
      picker.set({
      labels: [text("No Audio"), ...tracks.map((t) => text("Track {} · {}", [t.id, t.title]))],
      });

      The OSD says "Download failed: Connection timed out", both parts in the user's language. An argument made with text() is translated too, while string arguments are shown as they are.

      await plugin.osd.show("Download failed: {}", [plugin.i18n.text("Connection timed out")]);
      

      1.5.11

    • Items joined the way the interface language joins them (see ListStyle): list(["a.glsl", "b.glsl"]) shows "a.glsl, b.glsl" in English and "a.glsl、b.glsl" in Chinese. Items are data, or texts the player translates. Accepted where a Text is.

      Parameters

      • items: readonly TextArg[]

        At most 256.

      • Optionalstyle: ListStyle

        "list" by default.

      Returns TextList

      invalid A malformed or over-limit value.

      The OSD says "Removed missing shaders: a.glsl, b.glsl" in English and joins the names with "、" in Chinese. list makes a value the player joins per interface language; the names themselves are data and stay as they are.

      const missing = ["a.glsl", "b.glsl"];
      await plugin.osd.show("Removed missing shaders: {}", [plugin.i18n.list(missing)]);

      1.5.11

    • An Error whose words the player shows translated: throw it where the player shows a plugin's failure to the user, such as from a file or web resolver's resolve (FileResolverOptions, WebResolverOptions) (also when a stream fails while it starts). The player shows text translated with this plugin's catalog (as player.state.error and the failure message); message is the English rendering, for logs. Elsewhere it is an ordinary Error.

      Parameters

      • source: string

        English source text, as I18n.text's.

      • Optionalargs: TemplateArgs

        Values for its placeholders.

      Returns TextError

      invalid A malformed or over-limit value.

      Opening a .ch8 file the plugin cannot load shows "The program file was not found." in the user's language. The player shows the message of an error thrown from resolve; i18n.error makes an Error whose text the player translates with this plugin's catalog, while its message stays English for logs.

      plugin.resolvers.add({
      id: "chip8",
      extensions: ["ch8"],
      async resolve(path, signal) {
      const program = await readFile(path, { signal }).catch(() => {
      // Shown as the open's failure, translated (locales/<lang>.po).
      throw plugin.i18n.error("The program file was not found.");
      });
      return startEmulator(program);
      },
      });

      1.5.11

    • The string a text shows in this run's language, for text that leaves the player: what the plugin copies to the clipboard or writes to a file ("Copy info", "Save as…"). Translated with this plugin's catalog (a string as a whole, a Text or TextList with its arguments), the way the player would show it.

      Only for text leaving the player. Never use it for the interface (a window, the menu, the OSD, a dialog): pass the value itself there, so the player translates it and vestra-plugin i18n check can see the sentence is whole.

      Parameters

      • value: TextValue

        Source text, or a text value.

      Returns string

      The translated string.

      invalid A malformed value.

      "Copy info" puts two translated lines on the clipboard. Text that leaves the player cannot be translated by it, so resolve turns the values into the string the player would show, using this plugin's catalog; inside the player, pass the values themselves instead.

      const { text, list, resolve } = plugin.i18n;
      const lines = list([text("Version {}", ["1.0"]), text("Cores: {}", [8])], "lines");
      await plugin.clipboard.writeText(resolve(lines));

      1.5.11

    locale: Locale

    The interface language of this run, chosen at start-up from the saved Appearance.language or the system's languages; English when neither names a Locale. Players before 0.4.3 report "en".