Top Related Projects
๐ ๐ A readable, automated, and optimized (3 kb) internationalization for JavaScript
The monorepo home to all of the FormatJS related libraries, most notably react-intl.
i18next: learn once - translate everywhere
๐ All in one i18n extension for VS Code
Give your JavaScript the ability to speak many languages.
Quick Overview
Vue I18n is a powerful internationalization plugin for Vue.js applications. It provides a simple and flexible way to add multi-language support to Vue projects, allowing developers to easily manage and switch between different language translations.
Pros
- Seamless integration with Vue.js ecosystem
- Supports both simple and complex translation scenarios
- Offers various formatting options for numbers, dates, and times
- Provides pluralization support for handling singular and plural forms
Cons
- Learning curve for advanced features and configurations
- Performance impact on large-scale applications with numerous translations
- Limited built-in support for right-to-left (RTL) languages
- Occasional challenges with dynamic content translation
Code Examples
- Basic usage:
import { createApp } from 'vue'
import { createI18n } from 'vue-i18n'
const i18n = createI18n({
locale: 'en',
messages: {
en: { hello: 'Hello!' },
fr: { hello: 'Bonjour!' }
}
})
const app = createApp(App)
app.use(i18n)
app.mount('#app')
- Using translations in a component:
<template>
<p>{{ $t('hello') }}</p>
</template>
<script>
export default {
name: 'HelloWorld'
}
</script>
- Pluralization example:
<template>
<p>{{ $tc('car', 1) }}</p>
<p>{{ $tc('car', 2) }}</p>
</template>
<script>
export default {
name: 'CarCount',
i18n: {
messages: {
en: { car: 'no car | one car | {n} cars' }
}
}
}
</script>
Getting Started
- Install Vue I18n:
npm install vue-i18n@next
- Create an I18n instance and use it in your Vue app:
import { createApp } from 'vue'
import { createI18n } from 'vue-i18n'
import App from './App.vue'
const i18n = createI18n({
locale: 'en',
fallbackLocale: 'en',
messages: {
en: { /* translations */ },
fr: { /* translations */ }
}
})
const app = createApp(App)
app.use(i18n)
app.mount('#app')
- Use translations in your components:
<template>
<h1>{{ $t('welcome') }}</h1>
</template>
Competitor Comparisons
๐ ๐ A readable, automated, and optimized (3 kb) internationalization for JavaScript
Pros of js-lingui
- Framework-agnostic, supporting React, Vue, and vanilla JavaScript
- Supports plural forms and other complex language rules out-of-the-box
- Offers a command-line interface for managing translations
Cons of js-lingui
- Steeper learning curve due to its more complex API
- Less Vue-specific features and integrations
Code Comparison
js-lingui:
import { t } from "@lingui/macro";
function Welcome({ name }) {
return <h1>{t`Hello ${name}`}</h1>;
}
vue-i18n:
<template>
<h1>{{ $t('hello', { name: name }) }}</h1>
</template>
<script>
export default {
props: ['name']
}
</script>
Key Differences
- vue-i18n is specifically designed for Vue.js, while js-lingui is more versatile
- js-lingui uses macros for translation, while vue-i18n relies on template syntax
- vue-i18n has tighter integration with Vue's reactivity system
Use Cases
- Choose vue-i18n for Vue-specific projects with simpler internationalization needs
- Opt for js-lingui in multi-framework environments or when dealing with complex language rules
Community and Ecosystem
- vue-i18n has a larger community within the Vue ecosystem
- js-lingui offers broader support across different JavaScript frameworks
The monorepo home to all of the FormatJS related libraries, most notably react-intl.
Pros of formatjs
- Framework-agnostic, supporting React, Angular, Vue, and vanilla JavaScript
- More comprehensive internationalization features, including pluralization and gender-aware formatting
- Larger ecosystem with additional tools for message extraction and compilation
Cons of formatjs
- Steeper learning curve due to more complex API and features
- Potentially larger bundle size when using all features
- Less Vue-specific optimizations and integrations
Code Comparison
vue-i18n:
const i18n = new VueI18n({
locale: 'en',
messages: {
en: { hello: 'Hello' },
ja: { hello: 'ใใใซใกใฏ' }
}
})
formatjs:
import { IntlProvider, FormattedMessage } from 'react-intl';
const messages = {
en: { hello: 'Hello' },
ja: { hello: 'ใใใซใกใฏ' }
};
<IntlProvider messages={messages[locale]} locale={locale}>
<FormattedMessage id="hello" />
</IntlProvider>
Both libraries provide similar basic functionality for internationalization, but formatjs offers a more comprehensive set of features at the cost of increased complexity. vue-i18n is more tightly integrated with Vue.js, making it easier to use in Vue projects, while formatjs provides a more flexible solution for various frameworks and vanilla JavaScript applications.
i18next: learn once - translate everywhere
Pros of i18next
- Framework-agnostic, can be used with any JavaScript project
- More extensive features, including pluralization and context-based translations
- Larger ecosystem with numerous plugins and integrations
Cons of i18next
- Steeper learning curve due to more complex API
- Requires additional setup for framework-specific integrations
Code Comparison
vue-i18n:
const i18n = new VueI18n({
locale: 'en',
messages: {
en: { hello: 'Hello' },
ja: { hello: 'ใใใซใกใฏ' }
}
})
i18next:
i18next.init({
lng: 'en',
resources: {
en: { translation: { hello: 'Hello' } },
ja: { translation: { hello: 'ใใใซใกใฏ' } }
}
})
Key Differences
- vue-i18n is specifically designed for Vue.js applications, while i18next is framework-agnostic
- i18next offers more advanced features like pluralization and context-based translations out of the box
- vue-i18n has a simpler API and easier integration with Vue.js components
- i18next has a larger ecosystem with more plugins and integrations available
Both libraries are popular choices for internationalization, with vue-i18n being the go-to option for Vue.js projects and i18next offering more flexibility for various JavaScript environments.
๐ All in one i18n extension for VS Code
Pros of i18n-ally
- IDE integration: Provides a Visual Studio Code extension for managing translations
- Multi-framework support: Works with various frameworks and libraries, not limited to Vue.js
- Advanced features: Offers machine translation, auto-completion, and inline annotations
Cons of i18n-ally
- Learning curve: May require more setup and configuration compared to vue-i18n
- Dependency: Relies on Visual Studio Code, limiting its use in other development environments
Code Comparison
vue-i18n:
import Vue from 'vue'
import VueI18n from 'vue-i18n'
Vue.use(VueI18n)
const i18n = new VueI18n({
locale: 'en',
messages: {
en: { hello: 'Hello' },
ja: { hello: 'ใใใซใกใฏ' }
}
})
i18n-ally (configuration in VS Code settings.json):
{
"i18n-ally.localesPaths": ["locales"],
"i18n-ally.keystyle": "nested",
"i18n-ally.sourceLanguage": "en",
"i18n-ally.displayLanguage": "en"
}
While vue-i18n is specifically designed for Vue.js applications and offers seamless integration, i18n-ally provides a more versatile solution for managing translations across different frameworks and file formats. i18n-ally's IDE integration offers powerful features for developers, but it may require more initial setup and is primarily focused on Visual Studio Code users.
Give your JavaScript the ability to speak many languages.
Pros of Polyglot.js
- Framework-agnostic, can be used with any JavaScript project
- Lightweight and has minimal dependencies
- Supports pluralization and interpolation out of the box
Cons of Polyglot.js
- Lacks built-in integration with Vue.js components and reactivity
- Does not support nested translation keys or locale messages
- Limited features compared to Vue I18n's rich ecosystem
Code Comparison
Vue I18n:
const i18n = new VueI18n({
locale: 'en',
messages: {
en: { greeting: 'Hello, {name}!' },
fr: { greeting: 'Bonjour, {name}!' }
}
})
// Usage in a Vue component
this.$t('greeting', { name: 'John' })
Polyglot.js:
const polyglot = new Polyglot();
polyglot.extend({
en: { greeting: 'Hello, %{name}!' },
fr: { greeting: 'Bonjour, %{name}!' }
});
// Usage
polyglot.t('greeting', { name: 'John' })
Both libraries offer similar basic functionality for internationalization, but Vue I18n provides deeper integration with Vue.js and more advanced features for complex applications. Polyglot.js is more suitable for simpler projects or when framework independence is required.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
vue-i18n
Internationalization plugin for Vue.js
[!IMPORTANT] Vue I18n v8 is no longer actively maintained. Please upgrade to Vue I18n v9. The seucirty hotfix is only provided for Vue I18n v8.28 until end of 2024. Thereafter, security fix is not provide for that version later. However, if it is absolutely necessary, please contact to contact@frapwings.jp
รฐยยย Platinum Sponsors
รขยยจ Special Sponsors
รฐยยฅย Gold Sponsors
รฐยยฅย Silver Sponsors
รฐยยฅย Bronze Sponsors
รขยย รฏยธย NOTICE
This repository is for Vue I18n v8.x and Vue 2
If you want to know about how to usage for Vue I18n v9 on Vue 3, See the this repository)
รฐยยยรขยยรขยยรฏยธย About support for v8
We will follow Vue v2 maintenance lifespan
รฐยยย Documentation
About Vue I18n v8.x, See here
If you want to read Vue I18n v9 docs, See here
รฐยยย Changelog
Detailed changes for each release are documented in the CHANGELOG.md.
รขยย Issues
Please make sure to read the Issue Reporting Checklist before opening an issue. Issues not conforming to the guidelines may be closed immediately.
รฐยยยช Contribution
Please make sure to read the Contributing Guide before making a pull request.
รยฉรฏยธย License
Top Related Projects
๐ ๐ A readable, automated, and optimized (3 kb) internationalization for JavaScript
The monorepo home to all of the FormatJS related libraries, most notably react-intl.
i18next: learn once - translate everywhere
๐ All in one i18n extension for VS Code
Give your JavaScript the ability to speak many languages.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot