Convert Figma logo to code with AI

kazupon logovue-i18n

:globe_with_meridians: Internationalization plugin for Vue.js

7,269
861
7,269
259

Top Related Projects

๐ŸŒ ๐Ÿ“– A readable, automated, and optimized (3 kb) internationalization for JavaScript

14,292

The monorepo home to all of the FormatJS related libraries, most notably react-intl.

7,730

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

  1. 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')
  1. Using translations in a component:
<template>
  <p>{{ $t('hello') }}</p>
</template>

<script>
export default {
  name: 'HelloWorld'
}
</script>
  1. 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

  1. Install Vue I18n:
npm install vue-i18n@next
  1. 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')
  1. 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
14,292

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.

7,730

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 Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

Vue I18n logo

vue-i18n

Test Status NPM version vue-i18n channel on Discord

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

MIT

NPM DownloadsLast 30 Days