83 lines
2.7 KiB
JavaScript
83 lines
2.7 KiB
JavaScript
// Metro module 1292 (f1293).
|
|
import * as _slicedToArray from "./_slicedToArray";
|
|
import * as _classCallCheck from "./_classCallCheck";
|
|
import * as __createClass from "./_createClass";
|
|
import { DEFAULT_FORMAT_CONFIG } from "./Module1276";
|
|
import { makeDataFormatters } from "./Module1275";
|
|
import * as _isRichTextTag from "./isRichTextTag";
|
|
let env1064 = {};
|
|
export const DEFAULT_LOCALE = "en-US";
|
|
const IntlManager = function IntlManager({ initialLocale = exports.DEFAULT_LOCALE, defaultLocale = exports.DEFAULT_LOCALE, formatConfig = DEFAULT_FORMAT_CONFIG, forceLookupMatcher = false }) {
|
|
_classCallCheck(this, IntlManager);
|
|
this.onLocaleChange = (a0) => {
|
|
this._localeSubscriptions.add(a0);
|
|
return () => this._localeSubscriptions.delete(a0);
|
|
};
|
|
this.currentLocale = initialLocale;
|
|
this.defaultLocale = defaultLocale;
|
|
this.formatConfig = formatConfig;
|
|
this._forceLookupMatcher = forceLookupMatcher;
|
|
this.data = (0, makeDataFormatters)([this.currentLocale, this.defaultLocale], this.formatConfig, this._forceLookupMatcher);
|
|
this._localeSubscriptions = new Set();
|
|
};
|
|
exports.IntlManager = __createClass(IntlManager, [{
|
|
key: "withFormatters",
|
|
value: function withFormatters(a0) {
|
|
for (const item of Object.entries(a0)) {
|
|
const r29 = _slicedToArray(item, 2);
|
|
this[r29[0]] = this.makeFormatFunction(r29[1]);
|
|
}
|
|
return this;
|
|
}
|
|
}, {
|
|
key: "makeFormatFunction",
|
|
value: function makeFormatFunction({ format, builder }) {
|
|
return (a0, a1) => a0 != null ? this(a0(this.currentLocale), a1, builder) : null;
|
|
}
|
|
}, {
|
|
key: "setLocale",
|
|
value: function setLocale(a0) {
|
|
this.currentLocale = a0;
|
|
this.data = (0, makeDataFormatters)([this.currentLocale, this.defaultLocale], this.formatConfig, this._forceLookupMatcher);
|
|
this.emitLocaleChange(a0);
|
|
}
|
|
}, {
|
|
key: "emitLocaleChange",
|
|
value: function emitLocaleChange(a0) {
|
|
for (const _localeSubscription of this._localeSubscriptions) {
|
|
_localeSubscription(a0);
|
|
}
|
|
}
|
|
}, {
|
|
key: "string",
|
|
value: function string(a0) {
|
|
return a0 == null ? "" : a0(this.currentLocale).reserialize();
|
|
}
|
|
}, {
|
|
key: "reserialize",
|
|
value: function reserialize(a0) {
|
|
if (a0 == null) {
|
|
return "";
|
|
}
|
|
const r3 = a0(this.currentLocale);
|
|
let r6 = r3;
|
|
if (typeof r6 !== "string") {
|
|
r6 = r3.reserialize();
|
|
}
|
|
return r6;
|
|
}
|
|
}, {
|
|
key: "bindFormatValues",
|
|
value: function bindFormatValues(a0, a1, a2) {
|
|
return (0, _isRichTextTag.bindFormatValues)({
|
|
Builder: a0,
|
|
nodes: a1.ast,
|
|
locales: [this.currentLocale, this.defaultLocale],
|
|
dataFormatters: this.data,
|
|
formatConfig: this.formatConfig,
|
|
values: a2,
|
|
keyPrefix: ""
|
|
});
|
|
}
|
|
}]);
|