UNPKG

1.07 kBJavaScriptView Raw
1import { warn } from './util'
2import extend from './extend'
3import mixin from './mixin'
4import component from './component'
5import { bind, update, unbind } from './directive'
6
7export let Vue
8
9export function install (_Vue) {
10 /* istanbul ignore if */
11 if (process.env.NODE_ENV !== 'production' && install.installed && _Vue === Vue) {
12 warn('already installed.')
13 return
14 }
15 install.installed = true
16
17 Vue = _Vue
18
19 const version = (Vue.version && Number(Vue.version.split('.')[0])) || -1
20 /* istanbul ignore if */
21 if (process.env.NODE_ENV !== 'production' && version < 2) {
22 warn(`vue-i18n (${install.version}) need to use Vue 2.0 or later (Vue: ${Vue.version}).`)
23 return
24 }
25
26 extend(Vue)
27 Vue.mixin(mixin)
28 Vue.directive('t', { bind, update, unbind })
29 Vue.component(component.name, component)
30
31 // use simple mergeStrategies to prevent i18n instance lose '__proto__'
32 const strats = Vue.config.optionMergeStrategies
33 strats.i18n = function (parentVal, childVal) {
34 return childVal === undefined
35 ? parentVal
36 : childVal
37 }
38}