interface TextTranslations The application's Translations runtime, as configureTranslatedText takes it. With the generated ESM of Runic Translations:
import { m } from "virtual:runic-translations/app/messages";
import { configureLocaleResolver, createLocaleSource, localeDirection } from "virtual:runic-translations/app/runtime";
import { resolveTextReference } from "virtual:runic-translations/app/transport";
const locale = createLocaleSource({ initialLocale: navigator.language });
configureLocaleResolver(locale.getLocale);
configureTranslatedText({
...locale,
resolve: (reference, language) => resolveTextReference(reference, m, { locale: language }).text,
direction: localeDirection,
});A template that calls m.*() renders again on a language switch when the locale resolver reads the framework's reactive text locale (useTextLocale in React, Vue and Svelte, textLocaleSignal in Angular). With library catalogs on the page, configureSharedLocaleResolver (Runic Translations 0.9) sets the locale of every catalog, and the transport's createReferenceResolver resolves references of each catalog: ```ts import { configureTranslatedText } from "@runic-artifex/views"; import { m } from "virtual:runic-translations/app"; import { configureSharedLocaleResolver, createLocaleSource, localeDirection } from "virtual:runic-translations/app/runtime"; import * as appTransport from "virtual:runic-translations/app/transport"; import { m as grid } from "virtual:runic-translations/acme.grid"; import * as gridTransport from "virtual:runic-translations/acme.grid/transport"; const locale = createLocaleSource({ initialLocale: navigator.language }); configureSharedLocaleResolver(locale.getRequestedLocale); // createReferenceResolver belongs to a generated transport module, not to
Methods
resolve
resolve(reference: TextReference, locale: string): string | undefined; Formats a reference in a locale, or returns undefined when it cannot, such as `resolveTextReference(reference, m, { locale }).text. A reference it cannot format shows its fallbackText`.
getLocale
getLocale(): string; The locale the page shows, such as the getLocale of a Translations locale source.
setLocale
setLocale?(locale: string): void; Sets the page's locale: the window's locale is passed here when the application sets it, so the page's own messages follow too. Without it, references resolve in the window's locale and the page's messages keep theirs.
subscribe
subscribe?(listener: (locale: string) => void): () => void; Observes the page's locale, such as a locale source's subscribe, so a switch on the page updates the text.
direction
direction?(locale: string): "ltr" | "rtl"; The writing direction of a locale, such as the generated runtime's localeDirection. textDirection and syncDocumentLocale use it; without it, the direction comes from the locale's script as Intl.Locale gives it.