Documentation / @zerotal/i18n / Translator
Class: Translator
Defined in: i18n/src/Translator.ts:14
Resolves translation keys against per-locale catalogs, with fallback,
interpolation, and pluralization. Resolved from the container as i18n.
Constructors
Constructor
new Translator(
opts):Translator
Defined in: i18n/src/Translator.ts:19
Parameters
opts
Returns
Translator
Properties
defaultLocale
readonlydefaultLocale:string
Defined in: i18n/src/Translator.ts:16
fallbackLocale
readonlyfallbackLocale:string
Defined in: i18n/src/Translator.ts:17
Accessors
locales
Get Signature
get locales():
string[]
Defined in: i18n/src/Translator.ts:26
Loaded locales.
Returns
string[]
Methods
addCatalog()
addCatalog(
locale,messages):void
Defined in: i18n/src/Translator.ts:31
Merge messages into a locale's catalog (used by tooling/tests).
Parameters
locale
string
messages
Returns
void
has()
has(
key,locale?):boolean
Defined in: i18n/src/Translator.ts:41
True if key exists in the given (or active) locale or the fallback.
Parameters
key
string
locale?
string
Returns
boolean
translate()
translate(
key,replacements?,locale?):string
Defined in: i18n/src/Translator.ts:56
Translate key. Missing keys return the key itself (so the UI degrades
visibly rather than throwing).
Parameters
key
string
replacements?
Replacements = {}
locale?
string
Returns
string
Example
t.translate('welcome.greeting', { name: 'Alice' }, 'fr');
t.translate('apples', { count: 2 }); // pipe-pluralized