From bf15eebcc47120ce68cb6713f3b5dc2bb29ff92f Mon Sep 17 00:00:00 2001 From: Kombu Date: Wed, 19 Apr 2017 10:49:00 +0800 Subject: [PATCH] :bug: bug(te): Fix `te()` that always uses `this.locale`, even when `locale` supplied (#147) by @aicest --- src/extend.js | 2 +- src/index.js | 2 +- test/unit/basic.test.js | 9 +++++++++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/extend.js b/src/extend.js index 750b6a165..2cf66e034 100644 --- a/src/extend.js +++ b/src/extend.js @@ -13,6 +13,6 @@ export default function extend (Vue: any): void { Vue.prototype.$te = function (key: Path, locale?: Locale): boolean { const i18n = this.$i18n - return i18n._te(key, i18n.locale, i18n.messages, [locale]) + return i18n._te(key, i18n.locale, i18n.messages, locale) } } diff --git a/src/index.js b/src/index.js index ea0342a87..0f574bc6e 100644 --- a/src/index.js +++ b/src/index.js @@ -242,7 +242,7 @@ export default class VueI18n { } te (key: Path, locale?: Locale): boolean { - return this._te(key, this.locale, this.messages, [locale]) + return this._te(key, this.locale, this.messages, locale) } getLocaleMessage (locale: Locale): LocaleMessage { diff --git a/test/unit/basic.test.js b/test/unit/basic.test.js index 9327307a8..0cbe75ec5 100644 --- a/test/unit/basic.test.js +++ b/test/unit/basic.test.js @@ -280,6 +280,10 @@ describe('basic', () => { it('should return false', () => { assert(i18n.te('message.hallo') === false) }) + + it('should return false with locale', () => { + assert(i18n.te('message.hello', 'xx') === false) + }) }) }) @@ -518,6 +522,11 @@ describe('basic', () => { const vm = new Vue({ i18n }) assert(vm.$te('message.hallo') === false) }) + + it('should return false with locale', () => { + const vm = new Vue({ i18n }) + assert(vm.$te('message.hello', 'xx') === false) + }) }) })