What is $t() in Vue?

Andreas Löw
Last updated:

The $t function is part of the Vue-i18n library, and it is used to translate text in a Vue.js application. It works by looking up a translation key in a language file, and returning the translated text associated with that key.

For example, if you have a language file that contains the following:


    "hello": "Bonjour"

You can use the $t function to translate the key "hello" like this:

    <div>{{ $t("hello") }}</div>

In this example, the $t function will return "Bonjour". The language file and the translation keys can be customized to meet the needs of your application.

The $t function also takes additional parameters that you can use inside the translation messages - e.g. to pass a name or other values.

See our tutorial How to translate your Vue.js application with vue-i18n for an in-depth description of how to use vue-i18n.