|
1 | 1 | /* @flow */ |
2 | 2 |
|
3 | 3 | export default function extend (Vue: any): void { |
4 | | - Vue.prototype.$t = function (key: Path, ...values: any): TranslateResult { |
5 | | - const i18n = this.$i18n |
6 | | - return i18n._t(key, i18n.locale, i18n._getMessages(), this, ...values) |
7 | | - } |
8 | | - |
9 | | - Vue.prototype.$tc = function (key: Path, choice?: number, ...values: any): TranslateResult { |
10 | | - const i18n = this.$i18n |
11 | | - return i18n._tc(key, i18n.locale, i18n._getMessages(), this, choice, ...values) |
12 | | - } |
13 | | - |
14 | | - Vue.prototype.$te = function (key: Path, locale?: Locale): boolean { |
15 | | - const i18n = this.$i18n |
16 | | - return i18n._te(key, i18n.locale, i18n._getMessages(), locale) |
17 | | - } |
18 | | - |
19 | | - Vue.prototype.$d = function (value: number | Date, ...args: any): DateTimeFormatResult { |
20 | | - return this.$i18n.d(value, ...args) |
21 | | - } |
22 | | - |
23 | | - Vue.prototype.$n = function (value: number, ...args: any): NumberFormatResult { |
24 | | - return this.$i18n.n(value, ...args) |
25 | | - } |
| 4 | + // $FlowFixMe |
| 5 | + Object.defineProperty(Vue.prototype, '$t', { |
| 6 | + get () { |
| 7 | + return (key: Path, ...values: any): TranslateResult => { |
| 8 | + const i18n = this.$i18n |
| 9 | + return i18n._t(key, i18n.locale, i18n._getMessages(), this, ...values) |
| 10 | + } |
| 11 | + } |
| 12 | + }) |
| 13 | + // $FlowFixMe |
| 14 | + Object.defineProperty(Vue.prototype, '$tc', { |
| 15 | + get () { |
| 16 | + return (key: Path, choice?: number, ...values: any): TranslateResult => { |
| 17 | + const i18n = this.$i18n |
| 18 | + return i18n._tc(key, i18n.locale, i18n._getMessages(), this, choice, ...values) |
| 19 | + } |
| 20 | + } |
| 21 | + }) |
| 22 | + // $FlowFixMe |
| 23 | + Object.defineProperty(Vue.prototype, '$te', { |
| 24 | + get () { |
| 25 | + return (key: Path, locale?: Locale): boolean => { |
| 26 | + const i18n = this.$i18n |
| 27 | + return i18n._te(key, i18n.locale, i18n._getMessages(), locale) |
| 28 | + } |
| 29 | + } |
| 30 | + }) |
| 31 | + // $FlowFixMe |
| 32 | + Object.defineProperty(Vue.prototype, '$d', { |
| 33 | + get () { |
| 34 | + return (value: number | Date, ...args: any): DateTimeFormatResult => { |
| 35 | + return this.$i18n.d(value, ...args) |
| 36 | + } |
| 37 | + } |
| 38 | + }) |
| 39 | + // $FlowFixMe |
| 40 | + Object.defineProperty(Vue.prototype, '$n', { |
| 41 | + get () { |
| 42 | + return (value: number, ...args: any): NumberFormatResult => { |
| 43 | + return this.$i18n.n(value, ...args) |
| 44 | + } |
| 45 | + } |
| 46 | + }) |
26 | 47 | } |
0 commit comments