---
title: "Translate the UI"
description: "Translate every packaged page and component with @nuxtjs/i18n: backend.* messages per locale, placeholders and plurals, dates and money in the active locale, and localized page paths. Russian, German, Spanish and French come with the package."
canonical_url: "https://nuxt-backend.dev/docs/build/ui/customize/translation"
---
# Translate the UI

> Translate every packaged page and component with @nuxtjs/i18n: backend.* messages per locale, placeholders and plurals, dates and money in the active locale, and localized page paths. Russian, German, Spanish and French come with the package.

Version: nuxt-backend 0.6.x · Tab: Build · Kind: how-to · Status: stable

Every page: [llms.txt](https://nuxt-backend.dev/llms.txt) · Skill for coding agents: [nuxt-backend](https://nuxt-backend.dev/.well-known/skills/nuxt-backend/SKILL.md)

Commands use npm; use your project's package manager.

- [API reference](https://nuxt-backend.dev/docs/reference/api/use-labels)
- [Source](https://github.com/qruto/nuxt-backend/blob/main/src/runtime/vue/composables/use-labels.ts)

The packaged pages and components read every word through [labels](https://nuxt-backend.dev/docs/build/ui/customize/labels). Without `@nuxtjs/i18n` they render English, or your app config's copy. With it, each label also looks for a message in the active locale: the label `auth.sendCode` is the message `backend.auth.sendCode`. `@nuxtjs/i18n` stays optional: the package never installs it and works the same without it. It needs `@nuxtjs/i18n` 10 or later, which brings vue-i18n 11.

## Set up the locales

Install the module and list your locales as you would for any app:

```ts [nuxt.config.ts]
export default defineNuxtConfig({
  modules: ['@nuxtjs/i18n', 'nuxt-backend'],
  i18n: {
    defaultLocale: 'en',
    strategy: 'prefix_except_default',
    locales: [
      { code: 'en', language: 'en-US', file: 'en.json' },
      { code: 'fr', language: 'fr-FR', file: 'fr.json' },
    ],
  },
})
```

For every locale you list in a language the package speaks (English, Russian, German, Spanish or French: `en`, `en-GB`, `de-AT`, or one whose `language` is one of them), the module registers the package's messages in that language under `backend`. Your own `$t('backend.errors.rate_limited')` works in your templates, and a `backend.*` key in your own `en.json` replaces the package's: an app's messages always win over a module's.

The messages are a JSON file per language, so `@nuxtjs/i18n` precompiles them at build time like your own. An app that ships without vue-i18n's message compiler (`bundle.runtimeOnly`, or `bundle.dropMessageCompiler`) loses nothing: keep its own messages in JSON or YAML files too, which the module precompiles the same way.

The package ships English, Russian, German, Spanish and French ([The package's own translations](#the-packages-own-translations)); your messages carry every other language, as below.

## Translate the messages

Add a `backend` object to each locale's messages, one key per group, with the keys of [the groups](https://nuxt-backend.dev/docs/build/ui/customize/labels#the-groups):

```json [i18n/locales/fr.json]
{
  "backend": {
    "auth": {
      "title": "Se connecter",
      "titleBrand": "Se connecter à {brand}",
      "emailCode": "Continuer avec un code par e-mail",
      "email": "E-mail",
      "sendCode": "M'envoyer un code",
      "sent": "Nous avons envoyé un code à {email}."
    },
    "usage": {
      "units": "{count} crédit | {count} crédits"
    },
    "errors": {
      "rate_limited": "Trop de requêtes. Réessayez dans un instant."
    }
  }
}
```

A key you leave out follows your `fallbackLocale`, then English, without a warning in the console, so a locale can be translated a group at a time. In development, the module names every locale whose JSON messages have no `backend` key at all, so a locale that would show the packaged UI wholly in English does not ship by accident.

The messages use vue-i18n's syntax, which the labels already follow:

- keep each `{param}` a message has: `{email}`, `{count}`, `{plan}`, and the nodes some messages place, such as `{inviter}` and `{workspace}`. A param you leave out of a translation is left out of the text; one the package does not fill stays as written, `{name}`, on every path;
- separate plural forms with `|`: two forms are one and other, three are zero, one and other. The package passes `count` wherever a message counts;
- a word order your language needs is yours to choose: the params land wherever the message puts them;
- a `…Named` label (`security.removeNamed`, `security.revokeNamed`) is a button's accessible name: start it with the button's own visible label (`security.remove`), so a person using speech input can name the button they see.

Copy you set in `appConfig.backend.labels` wins over every locale's message, because app config holds one language. An app that translates keeps its copy in its messages.

## The package's own translations

Every label and every email of the package comes in Russian, German, Spanish and French, beside English. For each locale you list in one of those languages (`ru`, `de`, `es`, `fr`, or a locale whose `language` is one of them, such as `de-AT`), the module registers the package's messages under `backend`, as it does English, and the development note on untranslated locales leaves it out. The backend reads the same translations for each recipient's language, so `setupEmail` needs no `messages` for them.

Your messages still win, key by key: a `backend.*` key in your own `de.json` replaces the package's German for that key alone.

The translations address the reader as `Sie`, `vous`, `tú` and `вы`. Their plural forms are the ones vue-i18n's default rule picks between, the same number as the English message has: the first for exactly one, the last for every other count. The Russian messages are worded so that last form reads right for 2, 5 and 21 alike (`Кредитов: {count}`); an app with its own Russian `pluralRules` and forms of its own replaces those keys in its `ru.json`.

## Dates, money and errors

`useLabels(group).locale` is the active locale's language: its `language` from `i18n.locales` when it names one, else its code (`pt_BR` reads as `pt-BR`). The packaged components format with it: session and invoice dates, a plan's renewal date, and prices. A code that is not a language tag falls back to the browser's language, as everything does without `@nuxtjs/i18n`.

Failures read through the `errors` group in the active locale, so a refusal from your own functions translates too when it carries a catalog code and no sentence of its own: `throw backendError('forbidden', { reason: 'banned' })` reads `backend.errors.forbidden_banned`, then `backend.errors.forbidden`; a reason of your own reads its own `forbidden_<reason>` key once your messages have one. A sentence written in `data.message` is shown as written. The auth server's own refusals translate the same way: a wrong sign-in code is `invalid_input` on `otp` and reads `backend.errors.invalid_input_otp`, never the server's English.

## Localized pages and links

The ready-made pages follow your routing strategy like any page of your app: under `prefix_except_default`, the pricing page answers at `/fr/pricing` too. Their links to each other (sign in to subscribe, view plans, the sign-in page after signing out) go through `useBackendPagePath`, which passes each path through the module's `localePath`, so a French visitor stays in French. Link to a packaged page from your own components the same way:

```vue
<script setup lang="ts">
const pricing = useBackendPagePath('pricing')
</script>

<template>
  <NuxtLink :to="pricing">{{ $t('nav.plans') }}</NuxtLink>
</template>
```

## Routing strategies

The pages and their links follow `prefix_except_default`, `prefix_and_default` and `no_prefix`. Under `prefix` no page answers without a locale, and the module's own redirects (to sign in, after a session ends, from an emailed invitation or an agent's consent link) name paths without one, so the module warns in development: use one of the other strategies, or redirect the unprefixed paths yourself. A localized copy of a page carries the page's own route rules: `/fr/profile` stays out of caches, search indexes and sitemaps, as `/profile` does.

## Emails

The emails the package sends render on the backend, which `@nuxtjs/i18n` never reaches: pass the same message files to `setupEmail({ messages: { fr } })`, and each email reads its `backend.email.*` keys in its recipient's language. Russian, German, Spanish and French need no messages: the backend has the package's own. Any other language without messages reads `defaultLocale` (English unless you set it), and a key a language leaves out reads the package's translation into it, then your `en` messages, then the package's English. The account's language is captured at sign-up from the active locale, and stored again on every switch: [Send email in each reader's language](https://nuxt-backend.dev/docs/build/email/templates/languages) has the details.

The [advanced example](https://github.com/qruto/nuxt-backend/tree/main/examples/advanced) runs this setup with a French locale.

## Related

- [Change copy and labels](https://nuxt-backend.dev/docs/build/ui/customize/labels): every group, and the order a label resolves in.
- [Replace a page](https://nuxt-backend.dev/docs/build/ui/customize/parts#replace-a-page): where each packaged page mounts.
- [Ecosystem](https://nuxt-backend.dev/docs/reference/ecosystem): `@nuxtjs/i18n` among the supported modules.


## Sitemap

See the full [sitemap](https://nuxt-backend.dev/sitemap.md) for all pages.
