Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix te() that always uses this.locale, even when locale supplied #147

Merged
merged 1 commit into from
Apr 19, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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