Skip to content

Commit

Permalink
fix: cannot work watchLocale on vue-i18n-bridge (#1411)
Browse files Browse the repository at this point in the history
  • Loading branch information
kazupon authored Nov 2, 2021
1 parent 584d02b commit ac276e2
Showing 1 changed file with 21 additions and 11 deletions.
32 changes: 21 additions & 11 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -267,17 +267,27 @@ export default class VueI18n {
}

watchLocale (composer?: any): ?Function {
/* istanbul ignore if */
if (!this._sync || !this._root) { return null }
const self = this
const target: any = this._vm
return this._root.$i18n.vm.$watch('locale', (val) => {
target.$set(target, 'locale', val)
if (self.__VUE_I18N_BRIDGE__ && composer) {
composer.locale.value = val
}
target.$forceUpdate()
}, { immediate: true })
if (!composer) {
/* istanbul ignore if */
if (!this._sync || !this._root) { return null }
const target: any = this._vm
return this._root.$i18n.vm.$watch('locale', (val) => {
target.$set(target, 'locale', val)
target.$forceUpdate()
}, { immediate: true })
} else {
// deal with vue-i18n-bridge
if (!this.__VUE_I18N_BRIDGE__) { return null }
const self = this
const target: any = this._vm
return this.vm.$watch('locale', (val) => {
target.$set(target, 'locale', val)
if (self.__VUE_I18N_BRIDGE__ && composer) {
composer.locale.value = val
}
target.$forceUpdate()
}, { immediate: true })
}
}

onComponentInstanceCreated (newI18n: I18n) {
Expand Down

0 comments on commit ac276e2

Please sign in to comment.