301 lines
9.0 KiB
JavaScript
301 lines
9.0 KiB
JavaScript
// Metro module 1294 (f1295).
|
|
import * as _classCallCheck from "./_classCallCheck";
|
|
import * as __createClass from "./_createClass";
|
|
import { InternalIntlMessage } from "./serializeAst";
|
|
function $mk117665($env) {
|
|
return function(a0) {
|
|
a0($env[0]);
|
|
};
|
|
}
|
|
let c1068_5, c1068_6, c1068_7;
|
|
let env1068 = {};
|
|
const r15 = (this ? this.__awaiter : this) || function(c12954_0, c12954_1, a2, c12954_3) {
|
|
let r2 = a2;
|
|
let Promise2 = a2;
|
|
if (!a2) {
|
|
Promise2 = Promise;
|
|
r2 = Promise2;
|
|
}
|
|
return new r2(function(a0, c24378_1) {
|
|
let rejected2, step2;
|
|
let c24378_0 = a0;
|
|
const fulfilled2 = function fulfilled(a0) {
|
|
try {
|
|
step2(c12954_3.next(a0));
|
|
} catch ($e) {
|
|
c24378_1($e);
|
|
}
|
|
};
|
|
rejected2 = function rejected(a0) {
|
|
try {
|
|
step2(c12954_3.throw(a0));
|
|
} catch ($e) {
|
|
c24378_1($e);
|
|
}
|
|
};
|
|
step2 = function step(a0) {
|
|
if (a0.done) {
|
|
c24378_0(a0.value);
|
|
} else {
|
|
let env28868;
|
|
let value = a0.value;
|
|
const r10 = env28868 = {};
|
|
env28868[0] = value;
|
|
if (!(value instanceof Promise2)) {
|
|
value = new Promise2($mk117665(r10));
|
|
}
|
|
value.then(fulfilled2, rejected2);
|
|
}
|
|
};
|
|
const r16 = c12954_3.apply(c12954_0, c12954_1 || []);
|
|
c12954_3 = r16;
|
|
const r18 = r16.next();
|
|
const { done, value } = r18;
|
|
if (done) {
|
|
a0(value);
|
|
} else {
|
|
let env24379;
|
|
const r21 = env24379 = {};
|
|
env24379[0] = value;
|
|
(value instanceof Promise2 ? value : new Promise2($mk117665(r21))).then(fulfilled2, rejected2);
|
|
}
|
|
});
|
|
};
|
|
let MessageLoader;
|
|
c1068_5 = r15;
|
|
export async function loadAllMessagesInLocale(c12955_0) {
|
|
await Promise.all(c1068_7.map((item) => item._loadLocale(c12955_0)));
|
|
}
|
|
export async function waitForAllDefaultIntlMessagesLoaded() {
|
|
await Promise.all(c1068_7.map((item) => item.waitForDefaultLocale()));
|
|
}
|
|
export function createLoader(a0, a1) {
|
|
const r8 = new c1068_6(a0, a1);
|
|
c1068_7.push(r8);
|
|
return r8;
|
|
}
|
|
MessageLoader = function MessageLoader(a0, a1) {
|
|
let c24382_1;
|
|
const _this = this;
|
|
_classCallCheck(this, MessageLoader);
|
|
this.messages = {};
|
|
this.localeImportMap = a0;
|
|
this.supportedLocales = Object.keys(a0);
|
|
this.defaultLocale = a1;
|
|
this._localeLoadingPromises = {};
|
|
this._parseCache = {};
|
|
this._subscribers = new Set();
|
|
this.fallbackMessage = new InternalIntlMessage([], this.defaultLocale);
|
|
if (module.hot) {
|
|
const _loop = function _loop(c28869_0) {
|
|
module.hot.accept(c24382_1, async () => {
|
|
const _this8 = this;
|
|
const _this9 = _this8;
|
|
await _this8._loadLocale(c28869_0);
|
|
_this9._parseCache = {};
|
|
});
|
|
};
|
|
for (const item of Object.entries(a0)) {
|
|
let r58;
|
|
[r58, c24382_1] = item;
|
|
_loop(r58);
|
|
}
|
|
}
|
|
};
|
|
c1068_6 = __createClass(MessageLoader, [{
|
|
key: "withDebugValues",
|
|
value: function withDebugValues(a0, a1) {
|
|
this._debugKeyMap = a0;
|
|
this._localeFileMap = a1;
|
|
}
|
|
}, {
|
|
key: "fallbackWith",
|
|
value: function fallbackWith(a0) {
|
|
let r1 = this;
|
|
while (r1 != null) {
|
|
const _parentLoader = r1._parentLoader;
|
|
if (_parentLoader === this) {
|
|
throw new Error("Setting `fallbackWith` on MessageLoader created a circular chain that would never resolve");
|
|
}
|
|
r1 = _parentLoader;
|
|
}
|
|
this.fallbackLoader = a0;
|
|
a0._parentLoader = this;
|
|
}
|
|
}, {
|
|
key: "get",
|
|
value: function get(a0, a1) {
|
|
const messageValue = this.getMessageValue(a0, a1);
|
|
if (messageValue != null) {
|
|
return messageValue;
|
|
}
|
|
if (this.isLocaleLoading(a1) && !this.isLocaleLoaded(this.defaultLocale)) {
|
|
return this.fallbackMessage;
|
|
}
|
|
const messageValue2 = this.getMessageValue(a0, this.defaultLocale);
|
|
if (messageValue2 != null) {
|
|
return messageValue2;
|
|
}
|
|
const fallbackLoader = this.fallbackLoader;
|
|
const r29 = fallbackLoader !== null ? fallbackLoader !== void 0 ? fallbackLoader.get(a0, a1) : void 0 : void 0;
|
|
if (r29 != null) {
|
|
return r29;
|
|
}
|
|
console.warn(`Requested message ${this._debugKeyMap != null ? `"${this._debugKeyMap[a0]}" (${a0})` : a0} does not have a value in the requested locale ${this._localeFileMap != null ? `${a1} (${this._localeFileMap[a1]})` : a1} nor the default locale ${this._localeFileMap != null ? `${this.defaultLocale} (${this._localeFileMap[this.defaultLocale]})` : this.defaultLocale}`);
|
|
return this.fallbackMessage;
|
|
}
|
|
}, {
|
|
key: "getMessageValue",
|
|
value: function getMessageValue(a0, a1) {
|
|
const r3 = this._parseCache[a1];
|
|
const r13 = r3 !== null ? r3 !== void 0 ? r3[a0] : void 0 : void 0;
|
|
if (r13) {
|
|
return r13;
|
|
}
|
|
if (this.messages[a1] != null) {
|
|
const r7 = this.messages[a1][a0];
|
|
if (r7 != null) {
|
|
const internalIntlMessage = new InternalIntlMessage(r7, a1);
|
|
const _parseCache = this._parseCache;
|
|
let r30 = _parseCache[a1];
|
|
if (!(r30 !== null && r30 !== void 0)) {
|
|
const r31 = {};
|
|
_parseCache[a1] = r31;
|
|
r30 = r31;
|
|
}
|
|
r30[a0] = internalIntlMessage;
|
|
return internalIntlMessage;
|
|
}
|
|
} else if (this.supportedLocales.includes(a1)) {
|
|
this._loadLocale(a1);
|
|
}
|
|
}
|
|
}, {
|
|
key: "_loadLocale",
|
|
value: async function _loadLocale(c24383_0) {
|
|
let c28870_1, messages, _this3, c28870_4;
|
|
const _this2 = this;
|
|
L33: {
|
|
L32: {
|
|
_this3 = _this2;
|
|
c28870_4 = void 0;
|
|
if (_this2.messages[c24383_0] != null) {
|
|
break L33;
|
|
}
|
|
const r36 = _this2._localeLoadingPromises[c24383_0];
|
|
if ((r36 !== null ? r36 !== void 0 ? r36.current : void 0 : void 0) == null) {
|
|
if (_this2.localeImportMap[c24383_0] != null) {
|
|
const current = _this2.localeImportMap[c24383_0]();
|
|
const r64 = _this2._localeLoadingPromises[c24383_0];
|
|
const r65 = r64 !== null ? r64 !== void 0 ? r64.initialized : void 0 : void 0;
|
|
_this2._localeLoadingPromises[c24383_0] = {
|
|
initialized: r65 !== null && r65 !== void 0 && r65,
|
|
current
|
|
};
|
|
messages = _this2.messages;
|
|
c28870_1 = c24383_0;
|
|
messages[c28870_1] = (await current).default;
|
|
_this3._localeLoadingPromises[c24383_0] = {
|
|
initialized: true,
|
|
current: void 0
|
|
};
|
|
_this3.emitChange();
|
|
break L32;
|
|
}
|
|
if (_this2.supportedLocales.includes(c24383_0)) {
|
|
throw new Error(`Requested to load locale ${c24383_0}, which should be supported, but no source for translation data was provided.`);
|
|
}
|
|
break L33;
|
|
}
|
|
const r43 = _this2._localeLoadingPromises[c24383_0];
|
|
await (r43 !== null ? r43 !== void 0 ? r43.current : void 0 : void 0);
|
|
return void 0;
|
|
}
|
|
return void 0;
|
|
}
|
|
}
|
|
}, {
|
|
key: "emitChange",
|
|
value: function emitChange() {
|
|
for (const item of this._subscribers.values()) {
|
|
item();
|
|
}
|
|
}
|
|
}, {
|
|
key: "onChange",
|
|
value: function onChange(a0) {
|
|
this._subscribers.add(a0);
|
|
return () => this._subscribers.delete(a0);
|
|
}
|
|
}, {
|
|
key: "isLocaleLoading",
|
|
value: function isLocaleLoading(a0) {
|
|
const r5 = this._localeLoadingPromises[a0];
|
|
return (r5 !== null ? r5 !== void 0 ? r5.current : void 0 : void 0) != null;
|
|
}
|
|
}, {
|
|
key: "isLocaleLoaded",
|
|
value: function isLocaleLoaded(a0, r5 = false) {
|
|
const r8 = this._localeLoadingPromises[a0];
|
|
return r8 != null && r8.initialized != 0 && (r5 ? r8.current == null : !r5);
|
|
}
|
|
}, {
|
|
key: "waitForLocaleLoaded",
|
|
value: function waitForLocaleLoaded(a0) {
|
|
return c1068_5(this, arguments, void 0, function*(c28871_1) {
|
|
let r57;
|
|
let _this5;
|
|
const _this4 = this;
|
|
let c28871_2 = arguments[1];
|
|
let c31232_1, c31232_0, c31232_2;
|
|
L21: {
|
|
L20: {
|
|
_this5 = _this4;
|
|
c31232_1 = void 0;
|
|
c31232_0 = c28871_1;
|
|
if (c28871_2 !== void 0) {
|
|
c31232_1 = c28871_2;
|
|
c31232_2 = void 0;
|
|
} else {
|
|
c31232_1 = false;
|
|
c31232_2 = void 0;
|
|
}
|
|
yield void 0;
|
|
c31232_2 = _this5._localeLoadingPromises[c31232_0];
|
|
if (c31232_2 == null) {
|
|
r57 = _this5._loadLocale(c31232_0);
|
|
break L21;
|
|
}
|
|
if (c31232_2.initialized && !c31232_1) {
|
|
break L20;
|
|
}
|
|
yield c31232_2.current;
|
|
return void 0;
|
|
}
|
|
return void 0;
|
|
}
|
|
return r57;
|
|
});
|
|
}
|
|
}, {
|
|
key: "waitForDefaultLocale",
|
|
value: function waitForDefaultLocale() {
|
|
return c1068_5(this, arguments, void 0, function*() {
|
|
const _this6 = this;
|
|
let c28872_1 = arguments[0];
|
|
let c31233_0;
|
|
const _this7 = _this6;
|
|
c31233_0 = void 0;
|
|
if (c28872_1 !== void 0) {
|
|
c31233_0 = c28872_1;
|
|
} else {
|
|
c31233_0 = false;
|
|
}
|
|
yield void 0;
|
|
return _this7.waitForLocaleLoaded(_this7.defaultLocale, c31233_0);
|
|
});
|
|
}
|
|
}]);
|
|
export { c1068_6 as MessageLoader };
|
|
c1068_7 = [];
|