Quick Start (Vue)
-
Install packages
Terminal window pnpm add @fluenti/core @fluenti/vuepnpm add -D @fluenti/cli @fluenti/vite-plugin -
Configure Vite
vite.config.ts import { defineConfig } from 'vite'import vue from '@vitejs/plugin-vue'import fluenti from '@fluenti/vite-plugin'export default defineConfig({plugins: [vue(),fluenti({ framework: 'vue' }),],}) -
Create
fluenti.config.tsfluenti.config.ts export default {sourceLocale: 'en',locales: ['en', 'zh-CN'],catalogDir: './locales',format: 'po',include: ['./src/**/*.{vue,ts}'],compileOutDir: './src/locales/compiled',} -
Write your component — just use
v-t<script setup>import { useI18n } from '@fluenti/vue'const { t, setLocale } = useI18n()</script><template><h1 v-t>Welcome to my app</h1><p v-t>This text will be automatically extracted for translation.</p><p>{{ t('Hello, {name}!', { name: 'World' }) }}</p><button @click="setLocale('en')">English</button><button @click="setLocale('zh-CN')">中文</button></template> -
Extract messages
Terminal window npx fluenti extractThis scans your source files and generates catalog files in
./locales/:locales/en.po— source messages (auto-filled)locales/zh-CN.po— empty translations to fill in
-
Add translations
Open
locales/zh-CN.poand fill inmsgstrfields:msgid "Welcome to my app"msgstr "欢迎使用我的应用"msgid "Hello, {name}!"msgstr "你好,{name}!" -
Compile messages
Terminal window npx fluenti compileThis generates optimized JS modules in
src/locales/compiled/. -
Initialize from compiled output
src/main.ts import { createApp } from 'vue'import { createFluentVue } from '@fluenti/vue'import App from './App.vue'import en from './locales/compiled/en'import zhCN from './locales/compiled/zh-CN'const i18n = createFluentVue({locale: 'en',fallbackLocale: 'en',messages: { en, 'zh-CN': zhCN },})const app = createApp(App)app.use(i18n)app.mount('#app')
What’s happening under the hood?
Section titled “What’s happening under the hood?”v-tdirective — The Vite plugin transforms<h1 v-t>Welcome</h1>into<h1>{{ $t('hash') }}</h1>at compile timet()calls —t('Hello, {name}!')is extracted by the CLI and looked up at runtime via the compiled catalog- No manual keys — Message IDs are auto-generated hashes. You write source text, not key names.
Rich text with <Trans>
Section titled “Rich text with <Trans>”Trans, Plural, and Select are globally registered by app.use(i18n) — no import needed.
<template> <Trans>Click <a href="/next">here</a> to continue</Trans></template>Plurals with <Plural>
Section titled “Plurals with <Plural>”<script setup>import { ref } from 'vue'
const count = ref(0)</script>
<template> <Plural :value="count" one="# item" other="# items" /> <button @click="count++">Add</button></template>Lazy messages with msg\“
Section titled “Lazy messages with msg\“”<script setup>import { msg } from '@fluenti/core'import { useI18n } from '@fluenti/vue'
const { t } = useI18n()
const ROLES = { admin: msg`Administrator`, user: msg`Regular User`,}</script>
<template> <span>{{ t(ROLES.admin) }}</span></template>