LocaleReceiver.js 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. 'use strict';
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. var _extends2 = require('babel-runtime/helpers/extends');
  6. var _extends3 = _interopRequireDefault(_extends2);
  7. var _vueTypes = require('../_util/vue-types');
  8. var _vueTypes2 = _interopRequireDefault(_vueTypes);
  9. var _default2 = require('./default');
  10. var _default3 = _interopRequireDefault(_default2);
  11. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
  12. exports['default'] = {
  13. name: 'LocaleReceiver',
  14. props: {
  15. componentName: _vueTypes2['default'].string.def('global'),
  16. defaultLocale: _vueTypes2['default'].oneOfType([_vueTypes2['default'].object, _vueTypes2['default'].func]),
  17. children: _vueTypes2['default'].func
  18. },
  19. inject: {
  20. localeData: { 'default': function _default() {
  21. return {};
  22. } }
  23. },
  24. methods: {
  25. getLocale: function getLocale() {
  26. var componentName = this.componentName,
  27. defaultLocale = this.defaultLocale;
  28. var locale = defaultLocale || _default3['default'][componentName || 'global'];
  29. var antLocale = this.localeData.antLocale;
  30. var localeFromContext = componentName && antLocale ? antLocale[componentName] : {};
  31. return (0, _extends3['default'])({}, typeof locale === 'function' ? locale() : locale, localeFromContext || {});
  32. },
  33. getLocaleCode: function getLocaleCode() {
  34. var antLocale = this.localeData.antLocale;
  35. var localeCode = antLocale && antLocale.locale;
  36. // Had use LocaleProvide but didn't set locale
  37. if (antLocale && antLocale.exist && !localeCode) {
  38. return _default3['default'].locale;
  39. }
  40. return localeCode;
  41. }
  42. },
  43. render: function render() {
  44. var $scopedSlots = this.$scopedSlots;
  45. var children = this.children || $scopedSlots['default'];
  46. var antLocale = this.localeData.antLocale;
  47. return children(this.getLocale(), this.getLocaleCode(), antLocale);
  48. }
  49. };