biu-i18n

1.1.2 • Public • Published

i18n Build Status codecov

The simplest I18n plugin for vue.

Installation

npm install biu-i18n --save
 
import i18n from 'biu-i18n'
 
// Ready translated locale messages
const message = {
  'cn-ZH': {
    first: 'first',
    second: 'second',
    third: 'third',
    withParams: '{:param} with'
  },
  pattern: '{:param}',
  locale: 'cn-ZH'
}
 
Vue.use(i18n, message)
 
// OR
 
// Create VueI18n instance with options
const i18n = new VueI18n({
  'cn-ZH': {
    first: 'first',
    second: 'second',
    third: 'third',
    withParams: '{:param} with'
  },
  pattern: '{:param}',
  locale: 'cn-ZH'
})
 
new Vue({ i18n }).$mount('#app')

Usage

this.$i18n(toBeTranslateKey: any, isObject: boolean)
 
this.$i18n('first')
this.$i18n(['first', 'second'])
this.$i18n({content: 'withParams', params: ['second']})
// if first is not in languege package , it'll return undifined.
this.$i18n.db.first
 
// setLangs, and if you have bind vue to window.vm it will updates auto.
this.$i18n.setLangs({
  'en': {
    first: 'first',
    second: 'second',
    third: 'third',
    withParams: '{:param} with'
  },
  locale: 'en'
})
// if already has 'cn-ZH' language package, you can use follow instruction:
this.$i18n.setLangs({
  locale: 'cn-ZH'
})
 
// hasLangs
this.$i18n('en') // return true
 
// clearLangs
this.$i18n.clearLangs('cn-ZH')
// OR
this.$i18n.clearLangs(['cn-ZH', 'en'])
 

Readme

Keywords

Package Sidebar

Install

npm i biu-i18n

Weekly Downloads

1

Version

1.1.2

License

MIT

Unpacked Size

25.1 kB

Total Files

15

Last publish

Collaborators

  • qinghuangniao