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 intoryarn add intorpnpm add intorbun add intor
Project Structure
index.jsonUindex.jsonUApp.vueMHelloWorld.vueMintor-config.tsUintor-client-provider.vueU
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.jsonUindex.jsonU
{ "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.tsU
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.vueU
<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.vueM
<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 textsetLocale: switches the active locale
<Trans />: renders structured messages with semantic tags
HelloWorld.vueM
<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>