Translating Text
useT() is the primary translation composable. Returns two methods — t for plain strings and tm for ICU-pluralized strings. Both are locale-reactive and update automatically when the active locale changes.
ts
import { useT } from 'vue-i18n-kit'
const { t, tm } = useT()Simple strings (t)
t(key, vars?) looks up a key in the active locale file and interpolates named {placeholder} tokens.
ts
t('buttons.submit') // → 'Submit'
t('greeting', { name: 'Alice' }) // → 'Hello, Alice!'Arguments
key—string. Dot-separated path in the locale file ('buttons.submit','greeting').vars—object, optional. Named values substituted into{placeholder}tokens.
Pluralized strings (tm)
tm(key, vars) looks up a key whose value is an ICU plural template, then selects the correct plural form using Intl.PluralRules for the active locale.
ts
tm('items', { count: 1 }) // → '1 item'
tm('items', { count: 5 }) // → '5 items'
tm('balance', { points: 3 }) // → '3 рубля'
tm('balance', { points: 11 }) // → '11 рублей'ICU template syntax
{varName, plural, …}— plural form selector.varNamemust be a key invars; its numeric value determines the CLDR category.one {…}few {…}many {…}other {…}— form for each CLDR category.otheris required — used as fallback.#inside a form — replaced with the variable's numeric value.{varName}outside plural — simple interpolation, replaced withvars.varName.
Examples
ts
// Display + plural in one template
tm('balance', { points: 21 })
// locale: "{points} {points, plural, one {рубль} few {рубля} many {рублей} other {рублей}}"
// → '21 рубль'
// Multiple variables
tm('score', { user: 'Даня', score: 21 })
// locale: "{user} набрал {score} {score, plural, one {балл} few {балла} many {баллов} other {баллов}}"
// → 'Даня набрал 21 балл'
// Multiple plural constructs in one string
tm('report', { files: 2, errors: 5 })
// → '2 файла (5 ошибок)'CLDR categories by language
- English, Turkish —
one,other - Russian, Polish —
one,few,many,other - Arabic —
zero,one,two,few,many,other - Japanese, Chinese —
other(no grammatical plural)
Full rules: CLDR Plural Rules