Skip to content

Commit

Permalink
🐛 bug(missing): fix vm argument passing
Browse files Browse the repository at this point in the history
closes #453
  • Loading branch information
kazupon committed Nov 6, 2018
1 parent 639453c commit dc48099
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 8 deletions.
14 changes: 7 additions & 7 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export default class VueI18n {

_vm: any
_formatter: Formatter
_root: ?I18n
_root: any
_sync: boolean
_fallbackRoot: boolean
_missing: ?MissingHandler
Expand Down Expand Up @@ -135,7 +135,7 @@ export default class VueI18n {
/* istanbul ignore if */
if (!this._sync || !this._root) { return null }
const target: any = this._vm
return this._root.vm.$watch('locale', (val) => {
return this._root.$i18n.vm.$watch('locale', (val) => {
target.$set(target, 'locale', val)
target.$forceUpdate()
}, { immediate: true })
Expand Down Expand Up @@ -287,7 +287,7 @@ export default class VueI18n {
}
/* istanbul ignore if */
if (!this._root) { throw Error('unexpected error') }
const root: any = this._root
const root: any = this._root.$i18n
translated = root._translate(
root._getMessages(), root.locale, root.fallbackLocale,
linkPlaceholder, host, interpolateMode, values
Expand Down Expand Up @@ -354,7 +354,7 @@ export default class VueI18n {
}
/* istanbul ignore if */
if (!this._root) { throw Error('unexpected error') }
return this._root.t(key, ...values)
return this._root.$t(key, ...values)
} else {
return this._warnDefault(locale, key, ret, host, values)
}
Expand All @@ -372,7 +372,7 @@ export default class VueI18n {
warn(`Fall back to interpolate the keypath '${key}' with root locale.`)
}
if (!this._root) { throw Error('unexpected error') }
return this._root.i(key, locale, values)
return this._root.$i18n.i(key, locale, values)
} else {
return this._warnDefault(locale, key, ret, host, [values])
}
Expand Down Expand Up @@ -526,7 +526,7 @@ export default class VueI18n {
}
/* istanbul ignore if */
if (!this._root) { throw Error('unexpected error') }
return this._root.d(value, key, locale)
return this._root.$i18n.d(value, key, locale)
} else {
return ret || ''
}
Expand Down Expand Up @@ -633,7 +633,7 @@ export default class VueI18n {
}
/* istanbul ignore if */
if (!this._root) { throw Error('unexpected error') }
return this._root.n(value, Object.assign({}, { key, locale }, options))
return this._root.$i18n.n(value, Object.assign({}, { key, locale }, options))
} else {
return ret || ''
}
Expand Down
2 changes: 1 addition & 1 deletion src/mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export default {
} else if (isPlainObject(options.i18n)) {
// component local i18n
if (this.$root && this.$root.$i18n && this.$root.$i18n instanceof VueI18n) {
options.i18n.root = this.$root.$i18n
options.i18n.root = this.$root
options.i18n.formatter = this.$root.$i18n.formatter
options.i18n.fallbackLocale = this.$root.$i18n.fallbackLocale
options.i18n.silentTranslationWarn = this.$root.$i18n.silentTranslationWarn
Expand Down
34 changes: 34 additions & 0 deletions test/unit/issues.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -433,4 +433,38 @@ describe('issues', () => {
assert(vm.$tc('car', 21), '21 машина')
})
})

describe('#453', () => {
it('should be handled root vm instance', done => {
const vm = new Vue({
i18n: new VueI18n({
locale: 'en',
missing: (locale, key, instance) => {
assert.equal('ja', locale)
assert.equal('foo.bar', key)
assert(vm === instance)
done()
}
}),
components: {
child: {
i18n: {
locale: 'ja'
},
render (h) {
return h('p', ['hello child'])
}
}
},
render (h) {
return h('div', [
h('child', { ref: 'child' })
])
}
}).$mount()
vm.$nextTick(() => {
vm.$refs.child.$i18n.t('foo.bar', 'ja')
})
})
})
})

0 comments on commit dc48099

Please sign in to comment.