Skip to main content
Version: 5.x.x

Translating (Vue)

Check our Vue example application

There are several ways how to translate with Tolgee.

Global $t function

If you use VueTolgee plugin, you can use $t function in any component.

<template>
<div>{{ $t('this_is_a_key') }}</div>
</template>

useTranslate composable

The other option how to translate is useTranslate composable.

<template>
<div :title="t('key')">...</div>
</template>

<script setup>
import { useTranslate } from '@tolgee/vue';

const { t } = useTranslate();
</script>

t function

This function allows you to render the actual translation.

Simple usage

t('app_title')

The t function looks into your translations finds an appropriate key and renders the translation for currently selected language

If you use Typescript read about typed keys

Default value

You can pass the default value as second parameter, which will be rendered if the key doesn't exist yet.

t('non_existant_key', 'Default value')

Parameter interpolation

You can supply a variable parameters which will then be rendered in your translations.

t('user_points', 'User has {count} points', { count: 10 })

// -> User has 10 points

There are more options you can do with the variable parameters, but it depends on selected formatter plugin.

To get the full t function specification check it's API

The T component

An alternative way is to use T component, which has a very similar use case and API to the t function mentioned above.

<template>
<T
keyName="translation_key"
defaultValue="User has {count} points"
:params="{ count: 10 }"
/>
</template>

<script setup>
import { T } from '@tolgee/vue';
</script>

Using namespaces

The useTranslate composable can be also used for loading additional namespaces.

const { t, isLoading } = useTranslate('common');

This example will load common namespace which can be then used with t function.

Read more about namespaces here.