diff --git a/src/extend.js b/src/extend.js index 0db2ccc1d..8bba945ae 100644 --- a/src/extend.js +++ b/src/extend.js @@ -3,17 +3,17 @@ export default function extend (Vue: any): void { Vue.prototype.$t = function (key: Path, ...values: any): TranslateResult { const i18n = this.$i18n - return i18n._t(key, i18n.locale, i18n.messages, this, ...values) + return i18n._t(key, i18n.locale, i18n._getMessages(), this, ...values) } Vue.prototype.$tc = function (key: Path, choice?: number, ...values: any): TranslateResult { const i18n = this.$i18n - return i18n._tc(key, i18n.locale, i18n.messages, this, choice, ...values) + return i18n._tc(key, i18n.locale, i18n._getMessages(), this, choice, ...values) } 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._getMessages(), locale) } Vue.prototype.$d = function (value: number | Date, ...args: any): DateTimeFormatResult { diff --git a/src/index.js b/src/index.js index 2760b7102..826c91ad6 100644 --- a/src/index.js +++ b/src/index.js @@ -102,9 +102,9 @@ export default class VueI18n { get vm (): any { return this._vm } - get messages (): LocaleMessages { return looseClone(this._vm.messages) } - get dateTimeFormats (): DateTimeFormats { return looseClone(this._vm.dateTimeFormats) } - get numberFormats (): NumberFormats { return looseClone(this._vm.numberFormats) } + get messages (): LocaleMessages { return looseClone(this._getMessages()) } + get dateTimeFormats (): DateTimeFormats { return looseClone(this._getDateTimeFormats()) } + get numberFormats (): NumberFormats { return looseClone(this._getNumberFormats()) } get locale (): Locale { return this._vm.locale } set locale (locale: Locale): void { @@ -125,6 +125,10 @@ export default class VueI18n { get silentTranslationWarn (): boolean { return this._silentTranslationWarn } set silentTranslationWarn (silent: boolean): void { this._silentTranslationWarn = silent } + _getMessages (): LocaleMessages { return this._vm.messages } + _getDateTimeFormats (): DateTimeFormats { return this._vm.dateTimeFormats } + _getNumberFormats (): NumberFormats { return this._vm.numberFormats } + _warnDefault (locale: Locale, key: Path, result: ?any, vm: ?any): ?string { if (!isNull(result)) { return result } if (this.missing) { @@ -250,7 +254,7 @@ export default class VueI18n { } t (key: Path, ...values: any): TranslateResult { - return this._t(key, this.locale, this.messages, null, ...values) + return this._t(key, this.locale, this._getMessages(), null, ...values) } _i (key: Path, locale: Locale, messages: LocaleMessages, host: any, ...values: any): any { @@ -282,7 +286,7 @@ export default class VueI18n { params.push(values[i]) } - return this._i(key, locale, this.messages, null, ...params) + return this._i(key, locale, this._getMessages(), null, ...params) } _tc ( @@ -301,7 +305,7 @@ export default class VueI18n { } tc (key: Path, choice?: number, ...values: any): TranslateResult { - return this._tc(key, this.locale, this.messages, null, choice, ...values) + return this._tc(key, this.locale, this._getMessages(), null, choice, ...values) } _te (key: Path, locale: Locale, messages: LocaleMessages, ...args: any): boolean { @@ -310,7 +314,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._getMessages(), locale) } getLocaleMessage (locale: Locale): LocaleMessageObject { @@ -344,7 +348,7 @@ export default class VueI18n { } let ret = '' - const dateTimeFormats = this.dateTimeFormats + const dateTimeFormats = this._getDateTimeFormats() if (key) { let locale: Locale = _locale if (isNull(dateTimeFormats[_locale][key])) { @@ -413,7 +417,7 @@ export default class VueI18n { } let ret = '' - const numberFormats = this.numberFormats + const numberFormats = this._getNumberFormats() if (key) { let locale: Locale = _locale if (isNull(numberFormats[_locale][key])) {