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