Components

<i18n-t>

The <i18n-t> component renders one translation, with plural forms, number and date formatting, HTML and slot interpolation.

<i18n-t> renders one translation into an element. Use it when a translation needs components inside it (a link in a sentence), a plural form, or a formatted number or date. It resolves the key for the current route, like $t.

Props

Rendering rules

The first matching case decides the output:

  1. number — the translation with { ...params, number: $tn(number) }.
  2. date — the translation with { ...params, date: $td(date) }.
  3. relativeDate — the translation with { ...params, relativeDate: $tdr(relativeDate) }.
  4. plural — the form $tc picks, the =0 marker included, with { ...params, count }; or customPluralRule(keypath, count, params, locale, t) when set, which reads the raw value, marker included, and whose answer is used as is, null being empty.
  5. Otherwise the translation with params.

null counts as not set. In every case:

  • defaultValue stands in for a missing key, in every branch.
  • hideIfEmpty renders defaultValue instead of a blank result.
  • html renders the result as HTML. params are escaped, the translation is not; slots are ignored.
  • A default slot receives { translation }, and named slots are ignored.
  • Otherwise each named slot replaces every {name} placeholder, before a param of that name. A param value that looks like a placeholder stays text.

date and relativeDate output carries data-allow-mismatch="text", because the server's time zone and clock are not the browser's. Set timeZone to render one calendar date in both; relativeDate depends on the clock, so it can still differ.

Example

{
  "terms": "I accept the {link}.",
  "termsLink": "terms of use",
  "items": "no items | one item | {count} items"
}
<template>
  <i18n-t keypath="terms" tag="p">
    <template #link>
      <NuxtLink :to="$localePath('/terms')">{{ $t('termsLink') }}</NuxtLink>
    </template>
  </i18n-t>

  <i18n-t keypath="items" :plural="cart.length" />
</template>

html sets innerHTML: use it only for translations you control. params are escaped, so user data is safe there, and so is a key that found no translation.

Helpers

$t, $tc, $tn, $td, $tdr

plural

The app-wide plural rule