LocaleReceiver.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import _extends from 'babel-runtime/helpers/extends';
  2. import PropTypes from '../_util/vue-types';
  3. import defaultLocaleData from './default';
  4. export default {
  5. name: 'LocaleReceiver',
  6. props: {
  7. componentName: PropTypes.string.def('global'),
  8. defaultLocale: PropTypes.oneOfType([PropTypes.object, PropTypes.func]),
  9. children: PropTypes.func
  10. },
  11. inject: {
  12. localeData: { 'default': function _default() {
  13. return {};
  14. } }
  15. },
  16. methods: {
  17. getLocale: function getLocale() {
  18. var componentName = this.componentName,
  19. defaultLocale = this.defaultLocale;
  20. var locale = defaultLocale || defaultLocaleData[componentName || 'global'];
  21. var antLocale = this.localeData.antLocale;
  22. var localeFromContext = componentName && antLocale ? antLocale[componentName] : {};
  23. return _extends({}, typeof locale === 'function' ? locale() : locale, localeFromContext || {});
  24. },
  25. getLocaleCode: function getLocaleCode() {
  26. var antLocale = this.localeData.antLocale;
  27. var localeCode = antLocale && antLocale.locale;
  28. // Had use LocaleProvide but didn't set locale
  29. if (antLocale && antLocale.exist && !localeCode) {
  30. return defaultLocaleData.locale;
  31. }
  32. return localeCode;
  33. }
  34. },
  35. render: function render() {
  36. var $scopedSlots = this.$scopedSlots;
  37. var children = this.children || $scopedSlots['default'];
  38. var antLocale = this.localeData.antLocale;
  39. return children(this.getLocale(), this.getLocaleCode(), antLocale);
  40. }
  41. };