extend.js 1.0 KB

123456789101112131415161718192021222324252627282930313233
  1. /* @flow */
  2. export default function extend (Vue: any): void {
  3. if (!Vue.prototype.hasOwnProperty('$i18n')) {
  4. // $FlowFixMe
  5. Object.defineProperty(Vue.prototype, '$i18n', {
  6. get () { return this._i18n }
  7. })
  8. }
  9. Vue.prototype.$t = function (key: Path, ...values: any): TranslateResult {
  10. const i18n = this.$i18n
  11. return i18n._t(key, i18n.locale, i18n._getMessages(), this, ...values)
  12. }
  13. Vue.prototype.$tc = function (key: Path, choice?: number, ...values: any): TranslateResult {
  14. const i18n = this.$i18n
  15. return i18n._tc(key, i18n.locale, i18n._getMessages(), this, choice, ...values)
  16. }
  17. Vue.prototype.$te = function (key: Path, locale?: Locale): boolean {
  18. const i18n = this.$i18n
  19. return i18n._te(key, i18n.locale, i18n._getMessages(), locale)
  20. }
  21. Vue.prototype.$d = function (value: number | Date, ...args: any): DateTimeFormatResult {
  22. return this.$i18n.d(value, ...args)
  23. }
  24. Vue.prototype.$n = function (value: number, ...args: any): NumberFormatResult {
  25. return this.$i18n.n(value, ...args)
  26. }
  27. }