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
- vue-i18n Setup and Message Files
- useI18n Composable and t() Function
- Pluralization and Linked Messages
- Number, Date, and Currency Formatting