1 | function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
2 |
|
3 | function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
4 |
|
5 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
6 |
|
7 | function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
8 |
|
9 | function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
10 |
|
11 | function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
|
12 |
|
13 | function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
14 |
|
15 | function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
16 |
|
17 | function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
18 |
|
19 | function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
20 |
|
21 | import * as React from 'react';
|
22 | import * as PropTypes from 'prop-types';
|
23 | import defaultLocaleData from './default';
|
24 |
|
25 | var LocaleReceiver =
|
26 |
|
27 | function (_React$Component) {
|
28 | _inherits(LocaleReceiver, _React$Component);
|
29 |
|
30 | function LocaleReceiver() {
|
31 | _classCallCheck(this, LocaleReceiver);
|
32 |
|
33 | return _possibleConstructorReturn(this, _getPrototypeOf(LocaleReceiver).apply(this, arguments));
|
34 | }
|
35 |
|
36 | _createClass(LocaleReceiver, [{
|
37 | key: "getLocale",
|
38 | value: function getLocale() {
|
39 | var _this$props = this.props,
|
40 | componentName = _this$props.componentName,
|
41 | defaultLocale = _this$props.defaultLocale;
|
42 | var locale = defaultLocale || defaultLocaleData[componentName || 'global'];
|
43 | var antLocale = this.context.antLocale;
|
44 | var localeFromContext = componentName && antLocale ? antLocale[componentName] : {};
|
45 | return _extends(_extends({}, typeof locale === 'function' ? locale() : locale), localeFromContext || {});
|
46 | }
|
47 | }, {
|
48 | key: "getLocaleCode",
|
49 | value: function getLocaleCode() {
|
50 | var antLocale = this.context.antLocale;
|
51 | var localeCode = antLocale && antLocale.locale;
|
52 |
|
53 | if (antLocale && antLocale.exist && !localeCode) {
|
54 | return defaultLocaleData.locale;
|
55 | }
|
56 |
|
57 | return localeCode;
|
58 | }
|
59 | }, {
|
60 | key: "render",
|
61 | value: function render() {
|
62 | return this.props.children(this.getLocale(), this.getLocaleCode(), this.context.antLocale);
|
63 | }
|
64 | }]);
|
65 |
|
66 | return LocaleReceiver;
|
67 | }(React.Component);
|
68 |
|
69 | export { LocaleReceiver as default };
|
70 | LocaleReceiver.defaultProps = {
|
71 | componentName: 'global'
|
72 | };
|
73 | LocaleReceiver.contextTypes = {
|
74 | antLocale: PropTypes.object
|
75 | };
|
76 |
|