JSPM

vue-i18n

2.4.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 1728590
  • Score
    100M100P100Q192197F
  • License MIT

Internationalization plugin for Vue.js

Package Exports

  • vue-i18n
  • vue-i18n/dist/vue-i18n.common
  • vue-i18n/src/extend
  • vue-i18n/src/index

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (vue-i18n) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

vue-i18n

Build Status Coverage Status NPM version Sauce Test Status Commitizen friendly

Internationalization plugin of Vue.js

Requirements

  • works with Vue.js 0.12.0+

Installation

npm

$ npm install vue-i18n

When used in CommonJS, you must explicitly install the router via Vue.use():

var Vue = require('vue')
var VueI18n = require('vue-i18n')

Vue.use(VueI18n, { ... })

Usage

var Vue = require('vue')
var i18n = require('vue-i18n')

// ready translated locales
var locales = {
  en: {
    message: {
      hello: 'the world'
    }
  },
  ja: {
    message: {
      hello: 'ザ・ワールド'
    }
  }
}

// set plugin
Vue.use(i18n, {
  lang: 'ja',
  locales: locales
})

// create instance
new Vue({
  el: '#test-i18n'
})

Template the following:

<div id="test-i18n" class="message">
  <p>{{ $t("message.hello") }}</p>
</div>

Output the following:

<div id="test-i18n" class="message">
  <p>ザ・ワールド</p>
</div>

Formatting

Named formatting

Locale the following:

var locales = {
  en: {
    message: {
      hello: '{msg} world'
    }
  }
}

Template the following:

<div class="message">
  <p>{{ $t('message.hello', { msg: "hello"}) }}</p>
</div>

Output the following:

<div class="message">
  <p>hello world</p>
</div>

List formatting

Locale the following:

var locales = {
  en: {
    message: {
      hello: '{0} world'
    }
  }
}

Template the following:

<div class="message">
  <p>{{ $t('message.hello', ["hello"]) }}</p>
</div>

Output the following:

<div class="message">
  <p>hello world</p>
</div>

API

$t(keypath, [lang], [arguments])

  • keypath: String required
  • lang: String optional
  • arguments: Array | Object optional

Translate the locale of keypath. If you specified lang, translate the locale of lang. If you specified keypath of list / named formatting local, you must specify arguments too. For arguments more details see Formatting.

Vue.t(keypath, [lang], [arguments])

  • keypath: String required
  • lang: String optional
  • arguments: Array | Object optional

This is the same as the $t method. This is translate function for global.

Options

Plugin options

Vue.use(plugin, {
  lang: 'en',
  locales: {
    en: {
      ...
    },
    ...
    ja: {
      ...
    }
  }
})

lang

Specify translate the language code.

If you abbreviated the lang option, translate as well as 'en' language code option (default: 'en').

locales

Specify translate some local dictionary.

If you abbreviated the locales option, set the empty local dictionary.

Configuration

Vue.config.lang

Get or set a global translation language code. Default by en string value. You can change the language of the global level dynamic translation in your application.

When specified with lang plugins option at Vue.use, Vue.config.lang is set that value.

Contributing

  • Fork it !
  • Create your top branch from dev: git branch my-new-topic origin/dev
  • Commit your changes: git commit -am 'Add some topic'
  • Push to the branch: git push origin my-new-topic
  • Submit a pull request to dev branch of kazupon/vue-i18n repository !

Testing

$ npm run unit

License

MIT

MIT