API reference

Types

Types of tauri-plugin-i18n-next-api, generated from guest-js.

Every interface and type alias the package exports, generated from the guest-js sources.

Locale

One locale of meta().locales (Locale of @i18n-micro/types).

PropertyTypeDescription
codestring
iso?string
dir?'ltr' | 'rtl' | 'auto'
displayName?string
[key: string]unknown

Meta

What the meta command returns.

PropertyTypeDescription
versionnumberThe catalog version: grows with every change (event i18n-next://changed).
localestringThe locale the tags are for.
defaultLocalestring
fallbackLocalestring | null
localesLocale[]
chainsRecord<string, string[]>The fallback chain of every locale, strongest first: premerge a view in this order.
numberFormatsRecord<string, Record<string, Intl.NumberFormatOptions>>
datetimeFormatsRecord<string, Record<string, Intl.DateTimeFormatOptions>>
timeZonestring | nullThe IANA zone Rust shows dates in, when it is known by name (the catalog's time_zone, or the WebView's zone sent with the first meta); null: the system's. connect and createTauriI18n format dates in it too.
tagsRecord<string, string>The content tag of each chunk of the chain, by "<locale>/<page>": /{tag}/{locale}/{page}.json.
bundlestringThe tag of the protocol bundle: /{bundle}/bundle?locale=…&page=….

ChangedEvent

Payload of {@link EVENT_CHANGED}.

PropertyTypeDescription
localestringThe active locale after the change.
versionnumberThe catalog version the change produced.

MissingEvent

Payload of {@link EVENT_MISSING} (debug builds): a key missed for the first time.

PropertyTypeDescription
localestringThe locale it was looked up in.
pagestringThe page (index for the root).
keystringThe key.
countnumberMisses so far, Rust and front end together.

I18nInstance

What connect needs of an @i18n-micro instance: createI18n of @i18n-micro/runtime, /vue, /react, /preact and /solid all build one.

PropertyTypeDescription
localeunknownTakes a locale code (Vue's instance answers a Ref, the others a string).
fallbackLocaleunknown
setRoute(page: string) => void
addTranslations(locale: string, translations: Tree, merge?: boolean) => void
addRouteTranslations(locale: string, page: string, translations: Tree, merge?: boolean) => void
storage{ translations: Map<string, unknown> }
missingHandler?(locale: string, key: string, page: string) => void
formatter?{ getNumberFormats(): Record<string, unknown> setNumberFormats(f: Record<string, unknown>): void getDateTimeFormats(): Record<string, unknown> setDateTimeFormats(f: Record<string, unknown>): void }
addLocaleIso?(iso: Record<string, string>) => void

ConnectOptions

PropertyTypeDescription
page?stringThe page shown first (index, the root alone, by default).
maxPages?numberThe page chunks kept loaded; the current page and preloaded ones stay. Unbounded by default.
reportMissing?booleanSends keys the instance misses to report_missing, batched per microtask. The command exists in debug builds only: the first refusal turns reporting off. Default true.
transport?'auto' | 'protocol' | 'invoke'auto (default): the protocol, raw invoke once it fails.
document?Document | nullSets <html lang dir> of this document on every locale (default: the global one; null: never).

A connected instance. Every method waits for the ones before it.

PropertyTypeDescription
localestringThe active locale the instance shows.
pagestringThe page the instance shows (index: the root alone).
versionnumberThe catalog version the instance shows.
metaMetaThe last meta read.
fallbackbooleantrue while the protocol is out and raw invoke carries the data.
setPage(page: string) => Promise<void>Loads the page's chunks of the active chain, then shows the page (setRoute).
setLocale(locale: string) => Promise<void>Switches Rust, native labels and every window; resolves once this instance shows it.
preload(page: string) => Promise<void>Loads a page without showing it; it is never evicted and follows every locale.
load(page: string) => Promise<void>Loads a page about to be shown (a router guard, before the navigation is confirmed) without showing it: the shown page and its texts stay. It is kept until the next setPage or load, which a cancelled navigation may never bring.
refresh() => Promise<void>Reads the meta again and loads what changed.
close() => voidStops following changed and reporting misses; gives the instance its missingHandler back.

RouteLike

What the guard needs of a vue-router route (RouteLocationNormalized fits).

PropertyTypeDescription
name?unknown
matched?readonly unknown[]The matched records: none before the first navigation (START_LOCATION).

RouterLike

What the guards need of a vue-router Router.

PropertyTypeDescription
beforeResolve(guard: (to: RouteLike) => unknown) => () => void
afterEach(hook: (to: RouteLike, from: RouteLike, failure?: unknown) => unknown) => () => void
currentRoute{ readonly value: RouteLike }

TauriI18nOptions

Extends Omit<VueOptions, 'locale' \| 'fallbackLocale' \| 'locales' \| 'defaultLocale' \| 'messages'>, Omit<ConnectOptions, 'page'>.

PropertyTypeDescription
router?RouterLikeA vue-router router: beforeResolve loads the page of every route before it shows, afterEach shows it once the navigation is confirmed; the current route is loaded first.
pageOf?(to: RouteLike) => stringThe page of a route: its name by default (Nuxt names pages/user/profile user-profile), index without one.

TauriI18nPlugin

The plugin with its link to Rust; app.use also provides the link to useI18nLink. When the app unmounts, the link closes and the router hooks and the locale watch go (dispose does the same without an app).

type TauriI18nPlugin = I18nPlugin & { link: Link; dispose(): void }