194 lines
5.0 KiB
JavaScript
194 lines
5.0 KiB
JavaScript
// Metro module 16053 (f16054).
|
|
import { defineProperty, objCreate } from "./Module16054";
|
|
import * as _Module16056 from "./Module16056";
|
|
import * as _Compiler from "./Compiler";
|
|
import { hop, extend } from "./Module16055";
|
|
const MessageFormat = function MessageFormat(a0, a1, a2) {
|
|
const r7 = typeof a0 === "string" ? MessageFormat.__parse(a0) : a0;
|
|
if (r7 && r7.type === "messageFormatPattern") {
|
|
const r21 = this._mergeFormats(MessageFormat.formats, a2);
|
|
defineProperty(this, "_locale", {
|
|
value: this._resolveLocale(a1)
|
|
});
|
|
let c22773_0 = this._compilePattern(r7, a1, r21, this._findPluralRuleFunction(this._locale));
|
|
const _this = this;
|
|
this.format = function(a0) {
|
|
return _this._format(c22773_0, a0);
|
|
};
|
|
return void 0;
|
|
}
|
|
throw new TypeError("A message must be provided as a String or AST.");
|
|
};
|
|
export default MessageFormat;
|
|
defineProperty(MessageFormat, "formats", {
|
|
enumerable: true,
|
|
value: {
|
|
number: {
|
|
currency: {
|
|
style: "currency"
|
|
},
|
|
percent: {
|
|
style: "percent"
|
|
}
|
|
},
|
|
date: {
|
|
short: {
|
|
month: "numeric",
|
|
day: "numeric",
|
|
year: "2-digit"
|
|
},
|
|
medium: {
|
|
month: "short",
|
|
day: "numeric",
|
|
year: "numeric"
|
|
},
|
|
long: {
|
|
month: "long",
|
|
day: "numeric",
|
|
year: "numeric"
|
|
},
|
|
full: {
|
|
weekday: "long",
|
|
month: "long",
|
|
day: "numeric",
|
|
year: "numeric"
|
|
}
|
|
},
|
|
time: {
|
|
short: {
|
|
hour: "numeric",
|
|
minute: "numeric"
|
|
},
|
|
medium: {
|
|
hour: "numeric",
|
|
minute: "numeric",
|
|
second: "numeric"
|
|
},
|
|
long: {
|
|
hour: "numeric",
|
|
minute: "numeric",
|
|
second: "numeric",
|
|
timeZoneName: "short"
|
|
},
|
|
full: {
|
|
hour: "numeric",
|
|
minute: "numeric",
|
|
second: "numeric",
|
|
timeZoneName: "short"
|
|
}
|
|
}
|
|
}
|
|
});
|
|
defineProperty(MessageFormat, "__localeData__", {
|
|
value: objCreate(null)
|
|
});
|
|
defineProperty(MessageFormat, "__addLocaleData", {
|
|
value: function value(a0) {
|
|
if (a0 && a0.locale) {
|
|
MessageFormat.__localeData__[a0.locale.toLowerCase()] = a0;
|
|
return void 0;
|
|
}
|
|
throw new Error("Locale data provided to IntlMessageFormat is missing a `locale` property");
|
|
}
|
|
});
|
|
defineProperty(MessageFormat, "__parse", {
|
|
value: _Module16056.default.parse
|
|
});
|
|
defineProperty(MessageFormat, "defaultLocale", {
|
|
enumerable: true,
|
|
writable: true,
|
|
value: void 0
|
|
});
|
|
MessageFormat.prototype.resolvedOptions = function() {
|
|
return {
|
|
locale: this._locale
|
|
};
|
|
};
|
|
MessageFormat.prototype._compilePattern = function(a0, a1, a2, a3) {
|
|
return new _Compiler.default(a1, a2, a3).compile(a0);
|
|
};
|
|
MessageFormat.prototype._findPluralRuleFunction = function(a0) {
|
|
const __localeData__ = MessageFormat.__localeData__;
|
|
let r1 = __localeData__[a0.toLowerCase()];
|
|
while (r1) {
|
|
const pluralRuleFunction = r1.pluralRuleFunction;
|
|
const r12 = r1;
|
|
if (pluralRuleFunction) {
|
|
return r12.pluralRuleFunction;
|
|
}
|
|
r1 = r12.parentLocale && __localeData__[r12.parentLocale.toLowerCase()];
|
|
}
|
|
throw new Error("Locale data added to IntlMessageFormat is missing a `pluralRuleFunction` for :" + a0);
|
|
};
|
|
MessageFormat.prototype._format = function(a0, a1) {
|
|
let r1, r12;
|
|
const length = a0.length;
|
|
let r0 = 0;
|
|
const r4 = 0 < length;
|
|
let r6 = "";
|
|
let r5 = "";
|
|
if (r4) {
|
|
do {
|
|
L12: {
|
|
const r17 = a0[r0];
|
|
const r14 = r6;
|
|
r1 = r0;
|
|
if (typeof r17 !== "string") {
|
|
const id = r17.id;
|
|
if (a1 && hop.call(a1, id)) {
|
|
const r32 = a1[id];
|
|
if (r17.options) {
|
|
r12 = r14 + this._format(r17.getOption(r32), a1);
|
|
break L12;
|
|
}
|
|
r12 = r14 + r17.format(r32);
|
|
break L12;
|
|
}
|
|
throw new Error("A value must be provided for: " + id);
|
|
}
|
|
r12 = r14 + r17;
|
|
}
|
|
r0 = r1 + 1;
|
|
r6 = r12;
|
|
r5 = r6;
|
|
} while (r0 < length);
|
|
}
|
|
return r5;
|
|
};
|
|
MessageFormat.prototype._mergeFormats = function(a0, a1) {
|
|
const r3 = {};
|
|
for (const key in a0) {
|
|
if (hop.call(a0, key)) {
|
|
const r23 = objCreate(a0[key]);
|
|
r3[key] = r23;
|
|
if (a1 ? hop.call(a1, key) : a1) {
|
|
extend(r23, a1[key]);
|
|
}
|
|
}
|
|
}
|
|
return r3;
|
|
};
|
|
MessageFormat.prototype._resolveLocale = function(a0) {
|
|
const r9 = ((typeof a0 === "string" ? [a0] : a0) || []).concat(MessageFormat.defaultLocale);
|
|
const __localeData__ = MessageFormat.__localeData__;
|
|
const length = r9.length;
|
|
let r0 = 0;
|
|
while (r0 < length) {
|
|
const r10 = r9[r0].toLowerCase().split("-");
|
|
const length2 = r10.length;
|
|
const r1 = r0;
|
|
if (length2) {
|
|
do {
|
|
const r25 = __localeData__[r10.join("-")];
|
|
if (r25) {
|
|
return r25.locale;
|
|
}
|
|
r10.pop();
|
|
} while (r10.length);
|
|
}
|
|
r0 = r1 + 1;
|
|
}
|
|
const r30 = r9.pop();
|
|
throw new Error("No locale data has been added to IntlMessageFormat for: " + r9.join(", ") + ", or the default locale: " + r30);
|
|
};
|