UNPKG

1.06 kBJavaScriptView Raw
1/* @flow */
2
3export default function extend (Vue: any): void {
4 if (!Vue.prototype.hasOwnProperty('$i18n')) {
5 // $FlowFixMe
6 Object.defineProperty(Vue.prototype, '$i18n', {
7 get () { return this._i18n }
8 })
9 }
10
11 Vue.prototype.$t = function (key: Path, ...values: any): TranslateResult {
12 const i18n = this.$i18n
13 return i18n._t(key, i18n.locale, i18n._getMessages(), this, ...values)
14 }
15
16 Vue.prototype.$tc = function (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 Vue.prototype.$te = function (key: Path, locale?: Locale): boolean {
22 const i18n = this.$i18n
23 return i18n._te(key, i18n.locale, i18n._getMessages(), locale)
24 }
25
26 Vue.prototype.$d = function (value: number | Date, ...args: any): DateTimeFormatResult {
27 return this.$i18n.d(value, ...args)
28 }
29
30 Vue.prototype.$n = function (value: number, ...args: any): NumberFormatResult {
31 return this.$i18n.n(value, ...args)
32 }
33}