std/build/i18n
std/build/i18n
Interfaces
I18nRuntime
Defined in: apps/website/.api-docs-entry/std/build/i18n/index.d.ts:14
The non-reactive translation runtime: a catalog set plus an explicit locale, translated on demand.
Svelte surfaces wrap this in reactive state (see @norbital-ai/ui/i18n);
server code can use this directly, selecting the locale per request.
Type Parameters
| Type Parameter | Default type |
|---|---|
Keys extends string |
string |
Properties
intlLocale
readonly intlLocale: string;Defined in: apps/website/.api-docs-entry/std/build/i18n/index.d.ts:20
The Intl.* locale string for the active locale (en-US / zh-CN).
locale
readonly locale: string;Defined in: apps/website/.api-docs-entry/std/build/i18n/index.d.ts:16
The active application locale.
locales
readonly locales: readonly string[];Defined in: apps/website/.api-docs-entry/std/build/i18n/index.d.ts:18
The locale order the catalogs ship (toggle order, primary first).
t
readonly t: TranslateFn<Keys>;Defined in: apps/website/.api-docs-entry/std/build/i18n/index.d.ts:22
Translate a typed key, with {placeholder} interpolation.
Methods
has()
has(key): key is Keys;Defined in: apps/website/.api-docs-entry/std/build/i18n/index.d.ts:24
True when the key exists in any locale of the catalog set.
Parameters
| Parameter | Type |
|---|---|
key |
string |
Returns
key is Keys
setLocale()
setLocale(locale): void;Defined in: apps/website/.api-docs-entry/std/build/i18n/index.d.ts:26
Switch the active locale.
Parameters
| Parameter | Type |
|---|---|
locale |
string |
Returns
void
Type Aliases
TranslateFn
type TranslateFn<Keys> = (key, vars?) => string;Defined in: apps/website/.api-docs-entry/std/build/i18n/index.d.ts:6
A locale-aware translation function, typed over the catalog key union.
Type Parameters
| Type Parameter | Default type |
|---|---|
Keys extends string |
string |
Parameters
| Parameter | Type |
|---|---|
key |
Keys |
vars? |
MessageVars |
Returns
string
Functions
createI18n()
function createI18n<C>(catalogs, initialLocale?): I18nRuntime<KeysOf<C>>;Defined in: apps/website/.api-docs-entry/std/build/i18n/index.d.ts:35
Create a translation runtime over a catalog set.
Not reactive on its own: consumers that need reactivity (Svelte) hold the
locale in $state and call translate through their own wrapper; this
runtime is for server code and one-off lookups.
Type Parameters
| Type Parameter |
|---|
C extends Readonly<Record<string, Readonly<Record<string, string>>>> |
Parameters
| Parameter | Type |
|---|---|
catalogs |
C |
initialLocale? |
string |
Returns
I18nRuntime<KeysOf<C>>
References
DEFAULT_LOCALE
Re-exports DEFAULT_LOCALE
defineMessages
Re-exports defineMessages
interpolate
Re-exports interpolate
INTL_LOCALES
Re-exports INTL_LOCALES
intlLocale
Re-exports intlLocale
KeysOf
Re-exports KeysOf
LocaleCatalogs
Re-exports LocaleCatalogs
MessageCatalog
Re-exports MessageCatalog
MessageVars
Re-exports MessageVars
parseLocale
Re-exports parseLocale
pickLocale
Re-exports pickLocale
setHtmlLang
Re-exports setHtmlLang
STORED_LOCALE_KEY
Re-exports STORED_LOCALE_KEY
storedLocale
Re-exports storedLocale
storeLocale
Re-exports storeLocale
SUPPORTED_LOCALES
Re-exports SUPPORTED_LOCALES
translate
Re-exports translate