# Vue Tiny Translation 🌍✨
A minimalist reactive translation plugin for Vue 3. Super lightweight (**~0.35 KB gzipped**) — zero dependencies, full TypeScript support, reactive out of the box.
[](https://www.npmjs.com/package/vue-tiny-translation)
[](https://www.npmjs.com/package/vue-tiny-translation)
[](https://bundlephobia.com/package/vue-tiny-translation)
[](./src/index.d.ts)
[](https://vuejs.org/)
[](./LICENSE)
🌐 **[Live Demo](https://vue-tiny-translation.netlify.app/)** — 35 languages, reactive language switching, no page reload.
[ {{ $t('goodbye', 'Bye!') }}](https://vue-tiny-translation.netlify.app/)
## Contents
- [Features](#features)
- [Installation](#installation)
- [Quick Start](#quick-start)
- [Composition API](#composition-api)
- [Loading translations](#loading-translations)
- [TypeScript](#typescript)
- [CDN usage](#cdn-usage)
- [API Reference](#api-reference)
- [vs vue-i18n](#vs-vue-i18n)
- [Troubleshooting](#troubleshooting)
- [Local development](#local-development)
- [License](#license)
## Features
- 🚀 **Tiny** — ~0.35 KB gzipped. Zero runtime dependencies.
- ⚡ **Reactive** — components re-render automatically when the language changes. No page reload.
- 🔧 **Four-function API** — `$t`, `translate`, `loadTranslations`, `setTranslations`. Nothing else to learn.
- 🌐 **Any source** — load translations from a static file, an API, a CMS, or a bundled import.
- 📦 **TypeScript** — full `.d.ts` with `$t` augmentation for `ComponentCustomProperties`.
- 🌳 **Tree-shakeable** — `sideEffects: false`, ESM-only, dev warnings stripped from the production build.
## Installation
```bash
npm install vue-tiny-translation
# or
pnpm add vue-tiny-translation
# or
yarn add vue-tiny-translation
```
## Quick Start
**1. Register the plugin**
```js
// main.js
import { createApp } from 'vue'
import TinyTranslation from 'vue-tiny-translation'
import App from './App.vue'
createApp(App).use(TinyTranslation).mount('#app')
```
You can also seed initial translations at install time:
```js
app.use(TinyTranslation, { hello: 'Hello', goodbye: 'Goodbye' })
```
**2. Use `$t` in templates**
```vue
{{ $t('hello') }}
{{ t('hello') }}
```
## Loading translations
```js
import { loadTranslations, setTranslations } from 'vue-tiny-translation'
// from a static file in /public
await loadTranslations('/translations/en.json')
// from your API
await loadTranslations('/api/i18n?lang=en')
// from an already-imported object (no fetch)
import en from './locales/en.json'
setTranslations(en)
```
### Organizing translation files
Put JSON files wherever your bundler can serve them. A common layout:
```
public/translations/
en.json
fr.json
ja.json
```
```json
{
"hello": "Hello",
"goodbye": "Goodbye",
"hero.title": "Welcome",
"hero.subtitle": "Enjoy your stay"
}
```
Dot-notation keys are strings — there's no nested-object lookup by design. Keep it flat and searchable.
## TypeScript
Types ship with the package, no `@types/` install needed. The plugin augments Vue's `ComponentCustomProperties` so `this.$t` is typed in every component.
```ts
import { translate, useTranslation, setTranslations } from 'vue-tiny-translation'
translate('hello') // string
translate('missing', 'Fallback') // string
const { t } = useTranslation()
const greeting: string = t('hello')
setTranslations({ hello: 'Hello', 'hero.title': 'Welcome' })
```
## CDN usage
Because the package is ESM-only, you can load it directly from a CDN via an import map:
```html