Skip to content

How to import i18n and $t? #404

Answered by antlionguard
HendrikJan asked this question in Q&A
Discussion options

You must be logged in to vote

You can use i18n inside script setup like this:

const { $i18n } = useNuxtApp();

const testVal = $i18n.t('key')

And you should already be able to use it in "template" without making any changes. You just need to set "vue-i18n.d.ts" file for type detection.

Here's my vue-i18n.d.ts file:

import VueI18n from '@nuxtjs/i18n/types';
import {
  Path, Values, Locale
} from 'vue-i18n/types';

/**
  * Overloads VueI18n interface to avoid needing to cast return value to string.
  * @see https://github.com/kazupon/vue-i18n/issues/410
  */
declare module '@nuxtjs/i18n/types' {
  export default class VueI18n {
    t(key: Path, locale: Locale, values?: Values): string;
    // eslint-disable-next-line no…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by HendrikJan
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants