Quick Start

Vue

This page demonstrates the minimal setup of Intor in a Vue project.


Installation

In this example, we use Vite to create a Vue project.
See the official documentation for details: Vite

Install Intor:

npm install intor
yarn add intor
pnpm add intor
bun add intor

Project Structure

index.json
U

index.json
U

App.vue
M

HelloWorld.vue
M

intor-config.ts
U
intor-client-provider.vue
U

Integration Steps

♯1 Messages

Create a messages directory in your project, and add a subdirectory for each locale.
Each locale provides an index.json file.

index.json
U

index.json
U
{
  "hello": "Hello, {name}",
  "rich": "A <tag>text</tag>."
}
{
  "hello": "Bonjour, {name}",
  "rich": "Un <tag>texte</tag>."
}

♯2 Config

Create an i18n/ directory under src/, and add an intor-config.ts file inside it.
This example uses the most basic translation loading approach by defining messages directly in the config.

For more details, see: Message Loading

intor-config.ts
U
import { defineIntorConfig } from "intor";
import EN from "../../messages/en/index.json";
import FR from "../../messages/fr/index.json";

export const intorConfig = defineIntorConfig({
  defaultLocale: "en",
  supportedLocales: ["en", "fr"],
  messages: {
    en: EN,
    fr: FR,
  },
});

♯3 Initialization

Create intor-client-provider.vue inside the i18n/ directory.

intor-client-provider.vue
U
<script setup lang="ts">
import { getClientLocale } from "intor";
import { IntorProvider } from "intor/vue";
import { intorConfig } from "./intor-config";
const locale = getClientLocale(intorConfig);
</script>

<template>
  <IntorProvider :value="{ config: intorConfig, locale }">
    <slot />
  </IntorProvider>
</template>

Then, use this provider as the outermost wrapper of your application in App.vue.

App.vue
M
<script setup lang="ts">
import HelloWorld from "./components/HelloWorld.vue";
import IntorClientProvider from "./i18n/intor-client-provider.vue";
</script>

<template>
  <IntorClientProvider>
    <HelloWorld />
  </IntorClientProvider>
</template>

Usage Example

Use useTranslator to access translation capabilities:

  • t: returns the resolved text
  • setLocale: switches the active locale

<Trans />: renders structured messages with semantic tags

HelloWorld.vue
M
<script setup lang="ts">
import { Trans, useTranslator } from "intor/vue";
import { h } from "vue";
const { t, setLocale } = useTranslator();
</script>

<template>
  <p>{{ t("hello", { name: "Intor" }) }}</p>

  <button @click="setLocale('en')">English</button>
  <button @click="setLocale('fr')">French</button>

  <Trans
    :i18n-key="'rich'"
    :components="{ tag: (children) => h('b', null, children) }"
  />
</template>