Types
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).
| Property | Type | Description |
|---|---|---|
code | string | |
iso? | string | |
dir? | 'ltr' | 'rtl' | 'auto' | |
displayName? | string | |
[key: string] | unknown |
Meta
What the meta command returns.
| Property | Type | Description |
|---|---|---|
version | number | The catalog version: grows with every change (event i18n-next://changed). |
locale | string | The locale the tags are for. |
defaultLocale | string | |
fallbackLocale | string | null | |
locales | Locale[] | |
chains | Record<string, string[]> | The fallback chain of every locale, strongest first: premerge a view in this order. |
numberFormats | Record<string, Record<string, Intl.NumberFormatOptions>> | |
datetimeFormats | Record<string, Record<string, Intl.DateTimeFormatOptions>> | |
timeZone | string | null | The 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. |
tags | Record<string, string> | The content tag of each chunk of the chain, by "<locale>/<page>": /{tag}/{locale}/{page}.json. |
bundle | string | The tag of the protocol bundle: /{bundle}/bundle?locale=…&page=…. |
ChangedEvent
Payload of {@link EVENT_CHANGED}.
| Property | Type | Description |
|---|---|---|
locale | string | The active locale after the change. |
version | number | The catalog version the change produced. |
MissingEvent
Payload of {@link EVENT_MISSING} (debug builds): a key missed for the first time.
| Property | Type | Description |
|---|---|---|
locale | string | The locale it was looked up in. |
page | string | The page (index for the root). |
key | string | The key. |
count | number | Misses 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.
| Property | Type | Description |
|---|---|---|
locale | unknown | Takes a locale code (Vue's instance answers a Ref, the others a string). |
fallbackLocale | unknown | |
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
| Property | Type | Description |
|---|---|---|
page? | string | The page shown first (index, the root alone, by default). |
maxPages? | number | The page chunks kept loaded; the current page and preloaded ones stay. Unbounded by default. |
reportMissing? | boolean | Sends 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 | null | Sets <html lang dir> of this document on every locale (default: the global one; null: never). |
Link
A connected instance. Every method waits for the ones before it.
| Property | Type | Description |
|---|---|---|
locale | string | The active locale the instance shows. |
page | string | The page the instance shows (index: the root alone). |
version | number | The catalog version the instance shows. |
meta | Meta | The last meta read. |
fallback | boolean | true 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 | () => void | Stops following changed and reporting misses; gives the instance its missingHandler back. |
RouteLike
What the guard needs of a vue-router route (RouteLocationNormalized fits).
| Property | Type | Description |
|---|---|---|
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.
| Property | Type | Description |
|---|---|---|
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'>.
| Property | Type | Description |
|---|---|---|
router? | RouterLike | A 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) => string | The 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 }