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 = '{{ $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") }}
{{ $t("foo.bar") }}
-{{ $t("foo.bar") }}
-{{ $t("foo.bar") }}
-{{ $t("foo.bar") }}
-