diff --git a/src/index.js b/src/index.js index 744d65e4c..f081c3dac 100644 --- a/src/index.js +++ b/src/index.js @@ -22,10 +22,8 @@ function plugin (Vue, opts = {}) { return } - if (process.env.NODE_ENV !== 'production' && version < 1) { - warn('vue-i18n (' + plugin.version - + ') need to use vue version 1.0 or later (vue version: ' - + Vue.version + ').') + if (process.env.NODE_ENV !== 'production' && version < 2) { + warn(`vue-i18n (${plugin.version}) need to use Vue 2.0 or later (Vue: ${Vue.version}).`) return } @@ -33,7 +31,7 @@ function plugin (Vue, opts = {}) { setupLangVM(Vue, lang) Asset(Vue, langVM) - Override(Vue, langVM, version) + Override(Vue, langVM) Config(Vue, langVM, lang) Extend(Vue) } diff --git a/src/override.js b/src/override.js index ae6fe92bd..5db0f2e39 100644 --- a/src/override.js +++ b/src/override.js @@ -1,15 +1,4 @@ -export default function (Vue, langVM, version) { - function update (vm) { - if (version > 1) { - vm.$forceUpdate() - } else { - let i = vm._watchers.length - while (i--) { - vm._watchers[i].update(true) // shallow updates - } - } - } - +export default function (Vue, langVM) { // override _init const init = Vue.prototype._init Vue.prototype._init = function (options) { @@ -18,7 +7,7 @@ export default function (Vue, langVM, version) { if (!this.$parent) { // root this._$lang = langVM this._langUnwatch = this._$lang.$watch('$data', (val, old) => { - update(this) + this.$forceUpdate() }, { deep: true }) } } diff --git a/test/specs/component.js b/test/specs/component.js index d89525920..ce465cd05 100644 --- a/test/specs/component.js +++ b/test/specs/component.js @@ -4,8 +4,6 @@ import locales from './fixture/locales' describe('component locales', () => { - const version = Number(Vue.version.split('.')[0]) - before(done => { Object.keys(locales).forEach(lang => { Vue.locale(lang, locales[lang]) @@ -31,12 +29,8 @@ describe('component locales', () => { } } } - if (version >= 2) { - compOptions.render = function (h) { - return h('p', {}, [this.$t('foo.bar.buz')]) - } - } else { - compOptions.template = '

{{* $t("foo.bar.buz") }}

' + compOptions.render = function (h) { + return h('p', {}, [this.$t('foo.bar.buz')]) } const options = { @@ -44,12 +38,8 @@ describe('component locales', () => { components: { component1: compOptions } } - if (version >= 2) { - options.render = function (h) { - return h('div', {}, [h('component1', {})]) - } - } else { - options.template = '
' + options.render = function (h) { + return h('div', {}, [h('component1', {})]) } vm = new Vue(options) diff --git a/test/specs/hot.js b/test/specs/hot.js index a1495d119..907625816 100644 --- a/test/specs/hot.js +++ b/test/specs/hot.js @@ -3,8 +3,6 @@ import Vue from 'vue' import locales from './fixture/locales' describe('hot reloading', () => { - const version = Number(Vue.version.split('.')[0]) - let el let orgLocale const expectLocale = 'the world updated' @@ -34,17 +32,11 @@ describe('hot reloading', () => { el, data () { return { lang: 'en' } } } - - if (version >= 2) { - options.render = function (h) { - return h('p', {}, [this.$t('message.hello', this.lang)]) - } - } else { - options.template = '

{{ $t("message.hello", lang) }}

' + options.render = function (h) { + return h('p', {}, [this.$t('message.hello', this.lang)]) } const vm = new Vue(options) - Vue.nextTick(() => { assert.equal(vm.$el.textContent, locales.en.message.hello) diff --git a/test/specs/i18n.js b/test/specs/i18n.js index 299153ba9..39207a83d 100644 --- a/test/specs/i18n.js +++ b/test/specs/i18n.js @@ -4,8 +4,6 @@ import locales from './fixture/locales' describe('i18n', () => { - const version = Number(Vue.version.split('.')[0]) - before(done => { Object.keys(locales).forEach(lang => { Vue.locale(lang, locales[lang]) @@ -540,13 +538,8 @@ describe('i18n', () => { return { lang: 'en' } } } - - if (version >= 2) { - options.render = function (h) { - return h('p', {}, [this.$t('message.hello', this.lang)]) - } - } else { - options.template = '

{{ $t("message.hello", lang) }}

' + options.render = function (h) { + return h('p', {}, [this.$t('message.hello', this.lang)]) } const vm = new Vue(options) @@ -572,12 +565,8 @@ describe('i18n', () => { it('should translate', done => { const compOptions = {} - if (version >= 2) { - compOptions.render = function (h) { - return h('p', {}, [this.$t('message.hoge')]) - } - } else { - compOptions.template = '

{{* $t("message.hoge") }}

' + compOptions.render = function (h) { + return h('p', {}, [this.$t('message.hoge')]) } const options = { @@ -585,15 +574,11 @@ describe('i18n', () => { components: { hoge: compOptions } } - if (version >= 2) { - options.render = function (h) { - return h('div', {}, [ - h('p', {}, [this.$t('message.hello')]), - h('hoge', {}) - ]) - } - } else { - options.template = '

{{ $t("message.hello") }}

' + options.render = function (h) { + return h('div', {}, [ + h('p', {}, [this.$t('message.hello')]), + h('hoge', {}) + ]) } const vm = new Vue(options) @@ -651,7 +636,6 @@ describe('i18n', () => { }) it('should translate', done => { - let vm const parentLocales = { en: { foo: { bar: 'hello parent' } }, ja: { foo: { bar: 'こんにちは、親' } } @@ -669,79 +653,45 @@ describe('i18n', () => { ja: { foo: { bar: 'こんにちは、子3' } } } - if (version >= 2) { - vm = new Vue({ - render (h) { - return h('div', [ - h('p', { attrs: { id: 'parent' } }, [this.$t('foo.bar')]), - h('child1'), - h('child2') - ]) - }, - locales: parentLocales, - components: { - child1: { - render (h) { - return h('div', [ - h('p', { attrs: { id: 'child1' } }, [this.$t('foo.bar')]), - h('child3') - ]) - }, - locales: child1Locales, - components: { - child3: { - render (h) { - return h('div', [ - h('p', { attrs: { id: 'child3' } }, [this.$t('foo.bar')]) - ]) - }, - locales: child3Locales - } - } + const vm = new Vue({ + render (h) { + return h('div', [ + h('p', { attrs: { id: 'parent' } }, [this.$t('foo.bar')]), + h('child1'), + h('child2') + ]) + }, + locales: parentLocales, + components: { + child1: { + render (h) { + return h('div', [ + h('p', { attrs: { id: 'child1' } }, [this.$t('foo.bar')]), + h('child3') + ]) }, - child2: { - render (h) { - return h('div', [ - h('p', { attrs: { id: 'child2' } }, [this.$t('foo.bar')]) - ]) - }, - locales: child2Locales - } - } - }) - } else { - vm = new Vue({ - template: `
-

{{ $t("foo.bar") }}

- - -
`, - locales: parentLocales, - components: { - child1: { - template: `
-

{{ $t("foo.bar") }}

- -
`, - locales: child1Locales, - components: { - child3: { - template: `
-

{{ $t("foo.bar") }}

-
`, - locales: child3Locales - } + locales: child1Locales, + components: { + child3: { + render (h) { + return h('div', [ + h('p', { attrs: { id: 'child3' } }, [this.$t('foo.bar')]) + ]) + }, + locales: child3Locales } - }, - child2: { - template: `
-

{{ $t("foo.bar") }}

-
`, - locales: child2Locales } + }, + child2: { + render (h) { + return h('div', [ + h('p', { attrs: { id: 'child2' } }, [this.$t('foo.bar')]) + ]) + }, + locales: child2Locales } - }) - } + } + }) vm.$mount(el) const parent = vm.$el.querySelector('#parent')