0Pricing
Vue Academy · Lesson

useI18n Composable and t() Function

useI18n(), t('key'), $t in templates, locale.value switching, locale detection.

Translating in script setup

In Composition API mode, components reach translation tools through the useI18n() composable. It returns the t function and a reactive locale ref, among others.

Calling useI18n

Call useI18n() inside <script setup> and destructure what you need.

import { useI18n } from "vue-i18n"

const { t, locale } = useI18n()

All lessons in this course

  1. vue-i18n Setup and Message Files
  2. useI18n Composable and t() Function
  3. Pluralization and Linked Messages
  4. Number, Date, and Currency Formatting
← Back to Vue Academy