Interpolation
Write parameters in the form
{name}. Each required argument accepts a string, number or boolean; a required value cannot be null or undefined.
{
"greeting": "Hola {name}",
"ready": "Listo para traducir",
"cart": {
"items": {
"plural": "total",
"forms": {
"=0": "Tu cesta está vacía",
"one": "{count} elemento en tu cesta",
"other": "{count} elementos en tu cesta"
}
}
}
}const { t } = useI18n()
t('greeting', { name: 'Meeko' })
t('ready')
t('cart.items', { total: 3 })
// Expected TypeScript diagnostics:
t('greeting') // missing name
t('cart.items', { total: 'three' }) // requires a number
t('unknown') // nonexistent keyThe same contract between languages
Every language needs the same namespaces, keys and parameters. If one translation uses
name
and another uses
user
for the same message, preparing the module fails. Plural categories can vary by language.
Public types
| Name | Type / default | Description |
|---|---|---|
I18n
|
interface
| Contract of the translator and its formatters. |
I18nValue
|
string | number | boolean
| Values for interpolation and selectors. |
I18nMessageValues<K>
|
generic type
| Required arguments for a key of the generated registry. |
Dynamic keys
A union of keys needs valid arguments for every alternative. Narrow the key with an
if
when each case has different parameters. If any alternative requires values, the argument cannot be omitted.
Old registries declared as
true
keep their open contract. The module generates new registries with explicit parameters.