0Pricing
Vue Academy · Lesson

vue-i18n Setup and Message Files

createI18n(), locale JSON files, message syntax {name}, nested keys, fallback locale.

vue-i18n Setup and Message Files is a free Vue Academy lesson on CoddyKit — lesson 1 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Vue Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

What Is i18n?

Internationalization (i18n) is building your app so it can present text in multiple languages. Vue I18n is the official-style library for translating Vue apps.

Instead of hardcoding English strings, you look up keys that resolve to the active language.

Installing Vue I18n

Add the package. For Vue 3 you use version 9 or later, which is built around the Composition API.

// terminal
// npm install vue-i18n

Message Files

Translations live in message objects, one per locale. Keys map to translated strings. Start with English.

const en = {
  greeting: "Hello",
  nav: {
    home: "Home",
    about: "About",
  },
}

Adding a Turkish Locale

Each locale mirrors the same key structure so every key exists in every language.

const tr = {
  greeting: "Merhaba",
  nav: {
    home: "Ana Sayfa",
    about: "Hakkinda",
  },
}

Creating the i18n Instance

createI18n builds the instance. Set locale (the active language), fallbackLocale (used when a key is missing), and the messages map.

import { createI18n } from "vue-i18n"

const i18n = createI18n({
  legacy: false,
  locale: "en",
  fallbackLocale: "en",
  messages: { en, tr },
})

Why legacy: false

Setting legacy: false enables Composition API mode, which is what modern Vue 3 apps use. It unlocks the useI18n composable you will meet next lesson.

const i18n = createI18n({
  legacy: false, // Composition API mode
  locale: "en",
  messages: { en, tr },
})

Registering with the App

Install the instance as a plugin with app.use(i18n). This makes translation helpers available throughout the component tree.

import { createApp } from "vue"
import App from "./App.vue"

const app = createApp(App)
app.use(i18n)
app.mount("#app")

Using $t in Templates

Once installed, every template can call $t(key) to look up a translation in the active locale.

<template>
  <h1>{{ $t("greeting") }}</h1>
  <a>{{ $t("nav.home") }}</a>
</template>

How fallbackLocale Works

If a key is missing in the active locale, Vue I18n falls back to fallbackLocale rather than showing the raw key. This keeps the UI sensible while translations are in progress.

// tr is missing "tagline" -> falls back to en
// {{ $t("tagline") }} renders the English text

Interpolation with Placeholders

Messages can contain named placeholders in curly braces. Pass values as the second argument to fill them in.

const en = {
  welcome: "Welcome, {name}!",
}

// template:
// {{ $t("welcome", { name: "Ada" }) }}
// => "Welcome, Ada!"

Organizing Message Files

For real apps, put each locale in its own file (en.json, tr.json) and import them. This keeps translations manageable and lets translators work independently.

// locales/en.json, locales/tr.json
import en from "./locales/en.json"
import tr from "./locales/tr.json"

createI18n({ locale: "en", messages: { en, tr } })

Quick Check

Check your understanding of Vue I18n setup.

Recap

You set up Vue I18n:

  • i18n means presenting text in multiple languages by looking up keys.
  • Define a message object per locale with the same key structure.
  • createI18n takes locale, fallbackLocale, and messages; use legacy: false for Composition mode.
  • Install with app.use(i18n) and translate in templates with $t(key).
  • Placeholders like {name} are filled via a second argument.

Frequently asked questions

Is the “vue-i18n Setup and Message Files” lesson free?

Yes — the full text of “vue-i18n Setup and Message Files” is free to read here on the web, and the Vue Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Vue Academy course, upgrade to CoddyKit PRO.

What will I learn in “vue-i18n Setup and Message Files”?

createI18n(), locale JSON files, message syntax {name}, nested keys, fallback locale. You practise Vue Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Vue Academy?

No prior experience is required. Vue Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 1 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “vue-i18n Setup and Message Files” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Vue Academy lesson?

Yes. Every Vue Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. vue-i18n Setup and Message Files
  2. useI18n Composable and t() Function
  3. Pluralization and Linked Messages
  4. Number, Date, and Currency Formatting
← Back to Vue Academy