choerodon-ui
Version:
An enterprise-class UI design language and React-based implementation
70 lines (55 loc) • 1.99 kB
JavaScript
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
import _createClass from "@babel/runtime/helpers/createClass";
import { __decorate } from "tslib";
import { action, get as _get, observable, runInAction } from 'mobx';
import moment from 'moment';
import defaultLocale from './locale';
import defaultSupports from './supports';
import normalizeLanguage from '../_util/normalizeLanguage';
function setMomentLocale(locale) {
moment.locale(normalizeLanguage(locale ? locale.lang : defaultLocale.lang));
}
export var LocaleContext =
/*#__PURE__*/
function () {
function LocaleContext() {
var _this = this;
_classCallCheck(this, LocaleContext);
runInAction(function () {
_this.locale = defaultLocale;
_this.supports = defaultSupports;
});
}
_createClass(LocaleContext, [{
key: "setLocale",
value: function setLocale(locale) {
setMomentLocale(locale);
this.locale = locale;
}
}, {
key: "setNumberFormatLanguage",
value: function setNumberFormatLanguage(numberFormatLanguage) {
this.numberFormatLanguage = numberFormatLanguage;
}
}, {
key: "setSupports",
value: function setSupports(supports) {
this.supports = supports;
}
}, {
key: "get",
value: function get(component, key) {
var cmp = _get(this.locale, component);
return cmp && _get(cmp, key) || "".concat(component, ".").concat(key);
}
}]);
return LocaleContext;
}();
__decorate([observable], LocaleContext.prototype, "locale", void 0);
__decorate([observable], LocaleContext.prototype, "numberFormatLanguage", void 0);
__decorate([observable], LocaleContext.prototype, "supports", void 0);
__decorate([action], LocaleContext.prototype, "setLocale", null);
__decorate([action], LocaleContext.prototype, "setNumberFormatLanguage", null);
__decorate([action], LocaleContext.prototype, "setSupports", null);
export default new LocaleContext();
//# sourceMappingURL=LocaleContext.js.map