Giter Site home page Giter Site logo

vue-i18n's Introduction

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.

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

$ make test

License

MIT

MIT

vue-i18n's People

Contributors

2betop avatar oxund avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

vue-i18n's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.