Documentation
supastarter for Nuxtsupastarter for Nuxt

Internationalization

For internationaliztion supastarter integrates nuxt/i18n.

Why nuxt/i18n:
nuxt/i18n is a lightweight internationalization library based on vue-i18n especially designed to leverage Nuxt 3 features (auto-imports, file-based route generation, etc.). It also supports automatic language detection and url based language routing.

Usage

In Vue components, you can use the auto-imported composable useTranslations(). This composable exposes the useI18n() composable from nuxt/i18n and adds types for the translation keys.

index.vue
<script setup lang="ts">
  const { t } = useTranslations();
</script>

<template>
  <div>{{ t('hello') }}</div>
</template>

nuxt/i18n also auto-imports useLocalePath(), a useful composable to generate localized links.

If you want to use a link, the auto-imported component <NuxtLinkLocale> is built on top of <NuxtLink> but changes the default behavior by internally using localePath() to make it easier to link to localized routes.

index.vue
<template>
  <NuxtLinkLocale to="/">{{ $t('home') }}</NuxtLinkLocale>
</template>

is equivalent to

index.vue
<script setup lang="ts">
  const localePath = useLocalePath();
</script>

<template>
  <NuxtLink :to="localePath('/')">{{ $t('home') }}</NuxtLink>
</template>

Translations

Translations are stored in the packages/i18n/translations folder. They are organized by locale and scope:

packages/i18n/translations
β”œβ”€β”€ en
β”‚   β”œβ”€β”€ shared.json    # Shared translations across all apps
β”‚   β”œβ”€β”€ saas.json      # SaaS app translations
β”‚   β”œβ”€β”€ marketing.json # Marketing app translations
β”‚   └── mail.json      # Email template translations
β”œβ”€β”€ de
β”‚   β”œβ”€β”€ shared.json
β”‚   β”œβ”€β”€ saas.json
β”‚   β”œβ”€β”€ marketing.json
β”‚   └── mail.json
└── ...
packages/i18n/translations/en/shared.json
{
  "hello": "Hello World!"
}

Add a new locale

To add a new locale you need to create a new folder in the packages/i18n/translations directory with the locale code as the folder name. For example fr for French. Then create the translation files for each scope:

packages/i18n/translations/fr/shared.json
{
  "hello": "Bonjour le monde!"
}

Then register this locale in the i18n config file:

packages/i18n/config.ts
export const config = {
  locales: {
    fr: {
      label: "FranΓ§ais",
      currency: "EUR",
    },
    // ...
  },
  defaultLocale: "en",
  defaultCurrency: "USD",
  localeCookieName: "NEXT_LOCALE",
} as const satisfies I18nConfig;