Skip to content

Commit

Permalink
🐛 bug(te): Fix te() that always uses this.locale, even when `loca…
Browse files Browse the repository at this point in the history
…le` supplied (#147) by @aicest
  • Loading branch information
aicest authored and kazupon committed Apr 19, 2017
1 parent 226f6c4 commit bf15eeb
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/extend.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
9 changes: 9 additions & 0 deletions test/unit/basic.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
})
})

Expand Down Expand Up @@ -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)
})
})
})

Expand Down

0 comments on commit bf15eeb

Please sign in to comment.