JavaScript API
Everything tauri-plugin-i18n-next-api exports, generated from the guest-js sources.
Option and result types are on the types page.
tauri-plugin-i18n-next-api
From crates/tauri-plugin-i18n-next/guest-js/index.ts.
| Function | Description |
|---|---|
meta() | Asks the plugin for the meta of locale (the active one by default) and page. The command answers raw JSON bytes (no serde round trip): they are parsed here. languages (navigator.languages) lets the first call pick the start locale; timeZone (the WebView's IANA zone) becomes the zone of Rust dates unless the catalog has one. |
connect() | Connects i18n to the plugin: loads the active locale's root (and page), follows changed from Rust and other windows (late or out-of-order events are dropped by version), reports misses in dev and keeps <html lang dir> in step. |
meta()
meta(options: { locale?: string; page?: string; languages?: readonly string[]; timeZone?: string } = {}): Promise<Meta>
Asks the plugin for the meta of locale (the active one by default) and page. The
command answers raw JSON bytes (no serde round trip): they are parsed here. languages
(navigator.languages) lets the first call pick the start locale; timeZone
(the WebView's IANA zone) becomes the zone of Rust dates unless the catalog has one.
connect()
connect(i18n: I18nInstance, options: ConnectOptions = {}): Promise<Link>
Connects i18n to the plugin: loads the active locale's root (and page), follows
changed from Rust and other windows (late or out-of-order events are dropped by version),
reports misses in dev and keeps <html lang dir> in step.
import { createI18n } from '@i18n-micro/runtime'
const link = await connect(createI18n({ locale: 'en' }), { page: 'index' })
await link.setPage('settings')
await link.setLocale('de')
Constants
| Constant | Value | Description |
|---|---|---|
EVENT_CHANGED | 'i18n-next://changed' | The event every window gets after a change. |
EVENT_MISSING | 'i18n-next://missing' | The dev event of the missing-key report: one { locale, page, key, count } per new key. |
tauri-plugin-i18n-next-api/vue
From crates/tauri-plugin-i18n-next/guest-js/vue.ts.
Also exported here, documented once above: Locale, Meta, EVENT_CHANGED, EVENT_MISSING, ChangedEvent, MissingEvent, meta(), I18nInstance, ConnectOptions, Link, connect().
| Function | Description |
|---|---|
useI18nLink() | The link of the app's createTauriI18n plugin (setLocale, preload, version, …). |
createTauriI18n() | createI18n of @i18n-micro/vue fed by the plugin: |
useI18nLink()
useI18nLink(): Link
The link of the app's createTauriI18n plugin (setLocale, preload, version, …).
createTauriI18n()
createTauriI18n(options: TauriI18nOptions = {}): Promise<TauriI18nPlugin>
createI18n of @i18n-micro/vue fed by the plugin:
import { createTauriI18n } from 'tauri-plugin-i18n-next-api/vue'
app.use(router)
app.use(await createTauriI18n({ router })) // beforeResolve loads the page chunk
The locale, locales, defaultLocale and the named formats come from Rust. A
failed page load keeps what is shown and lets the navigation through. A locale set on the
instance (useI18n().locale.value = 'de', <I18nSwitcher>) goes to Rust like
link.setLocale; the old texts stay until the new ones are in, and a locale Rust refuses
puts the shown one back.