decord/source/16053_MessageFormat.js

223 lines
7 KiB
JavaScript
Raw Normal View History

2026-07-29 08:29:29 +00:00
// Module ID: 16053
// Function ID: 16054
2026-07-20 16:05:17 +00:00
// Name: MessageFormat
2026-07-29 08:29:29 +00:00
// Dependencies: [16054, 16056, 16058, 16055]
2026-07-23 10:11:24 +00:00
2026-07-29 08:29:29 +00:00
// Module 16053 (MessageFormat)
2026-07-23 10:11:24 +00:00
import extend from "extend";
import extend from "extend";
import extend from "extend";
import extend from "extend";
import extend from "extend";
import extend from "extend";
2026-07-20 16:05:17 +00:00
class MessageFormat {
constructor(arg0, arg1, arg2) {
__parseResult = global;
2026-07-29 08:29:29 +00:00
if (typeof global !== "init") {
tmp3 = MessageFormat;
2026-07-20 16:05:17 +00:00
__parseResult = MessageFormat.__parse(global);
}
if (__parseResult) {
str = "messageFormatPattern";
if ("messageFormatPattern" === __parseResult.type) {
2026-07-29 08:29:29 +00:00
self = this;
tmp4 = require;
2026-07-20 16:05:17 +00:00
tmp5 = importDefault;
2026-07-29 08:29:29 +00:00
tmp6 = MessageFormat;
_mergeFormatsResult = this._mergeFormats(MessageFormat.formats, importDefault);
tmp8 = _compilePattern;
tmp9 = self;
2026-07-23 10:11:24 +00:00
obj = require("extend");
2026-07-29 08:29:29 +00:00
obj = { value: null };
obj[0] = this._resolveLocale(require);
2026-07-20 16:05:17 +00:00
str2 = "_locale";
2026-07-29 08:29:29 +00:00
definePropertyResult = obj.defineProperty(this, "_locale", obj);
self2 = this;
2026-07-20 16:05:17 +00:00
tmp11 = __parseResult;
tmp12 = require;
tmp13 = _mergeFormatsResult;
2026-07-29 08:29:29 +00:00
_compilePattern = this._compilePattern(__parseResult, require, _mergeFormatsResult, this._findPluralRuleFunction(this._locale));
self = this;
this.format = (arg0) => self._format(closure_0, arg0);
2026-07-20 16:05:17 +00:00
return;
}
}
typeError = new TypeError("A message must be provided as a String or AST.");
throw typeError;
}
resolvedOptions() {
obj = { locale: this._locale };
return obj;
}
_compilePattern(arg0, arg1, arg2, arg3) {
2026-07-23 10:11:24 +00:00
_default = new require("StringFormat").default(require, importDefault, importAll);
2026-07-20 16:05:17 +00:00
return _default.compile(global);
}
_findPluralRuleFunction(arg0) {
__localeData__ = MessageFormat.__localeData__;
2026-07-29 08:29:29 +00:00
tmp = __localeData__[global.toLowerCase(global)];
if (tmp) {
tmp2 = tmp;
while (!tmp.pluralRuleFunction) {
parentLocale = tmp.parentLocale;
2026-07-20 16:05:17 +00:00
if (parentLocale) {
str = tmp.parentLocale;
parentLocale = __localeData__[str.toLowerCase(str)];
}
2026-07-29 08:29:29 +00:00
tmp = parentLocale;
2026-07-20 16:05:17 +00:00
}
2026-07-29 08:29:29 +00:00
return tmp.pluralRuleFunction;
2026-07-20 16:05:17 +00:00
}
error = new Error("Locale data added to IntlMessageFormat is missing a `pluralRuleFunction` for :" + global);
throw error;
}
_format(arg0, arg1) {
self = this;
length = global.length;
num = 0;
str = "";
str2 = "";
if (0 < length) {
while (true) {
obj = global[num];
2026-07-29 08:29:29 +00:00
tmp = str;
tmp2 = num;
if (typeof obj === "init") {
2026-07-20 16:05:17 +00:00
id = obj.id;
if (!require) {
break;
} else {
2026-07-29 08:29:29 +00:00
tmp3 = closure_0;
tmp4 = closure_1;
2026-07-23 10:11:24 +00:00
hop = require("extend").hop;
2026-07-29 08:29:29 +00:00
call = hop.call;
if (!(typeof call === "unknown" ? hop(id) : call(require, id))) {
2026-07-20 16:05:17 +00:00
break;
} else {
2026-07-29 08:29:29 +00:00
tmp10 = require[id];
2026-07-20 16:05:17 +00:00
if (obj.options) {
2026-07-29 08:29:29 +00:00
text = `${tmp12(obj.getOption(tmp10), require)}`;
2026-07-20 16:05:17 +00:00
} else {
2026-07-29 08:29:29 +00:00
text = `${obj.format(tmp10)}`;
2026-07-20 16:05:17 +00:00
}
}
}
} else {
text = str + obj;
}
num = num + 1;
str = text;
str2 = text;
}
2026-07-29 08:29:29 +00:00
tmp5 = globalThis;
2026-07-20 16:05:17 +00:00
_Error = Error;
str3 = "A value must be provided for: ";
tmp6 = new.target;
2026-07-29 08:29:29 +00:00
tmp7 = new.target;
2026-07-20 16:05:17 +00:00
error = new Error("A value must be provided for: " + id);
2026-07-29 08:29:29 +00:00
tmp9 = error;
2026-07-20 16:05:17 +00:00
throw error;
}
return str2;
}
_mergeFormats(arg0, arg1) {
obj = {};
2026-07-29 08:29:29 +00:00
for (const key10006 in arg0) {
tmp7 = key10006;
tmp8 = closure_0;
tmp9 = closure_1;
2026-07-23 10:11:24 +00:00
hop2 = require("extend").hop;
2026-07-29 08:29:29 +00:00
call2 = hop2.call;
if (typeof call2 === "unknown") {
hop2Result = hop2(key10006);
} else {
hop2Result = call2(arg0, key10006);
}
if (!hop2Result) {
2026-07-20 16:05:17 +00:00
continue;
} else {
2026-07-29 08:29:29 +00:00
tmp8Result = require("extend");
objCreateResult = tmp8Result.objCreate(arg0[key10006]);
obj[key10006] = objCreateResult;
tmp3 = arg1;
2026-07-20 16:05:17 +00:00
if (!arg1) {
2026-07-29 08:29:29 +00:00
if (!arg1) {
continue;
} else {
tmp8Result1 = require("extend");
extendResult = tmp8Result1.extend(objCreateResult, arg1[key10006]);
continue;
}
2026-07-20 16:05:17 +00:00
continue;
} else {
2026-07-29 08:29:29 +00:00
hop = require("extend").hop;
call = hop.call;
if (typeof call === "unknown") {
hopResult = hop(key10006);
} else {
hopResult = call(arg1, key10006);
}
tmp5 = hopResult;
2026-07-20 16:05:17 +00:00
}
}
continue;
}
return obj;
}
_resolveLocale(arg0) {
items1 = global;
2026-07-29 08:29:29 +00:00
if (typeof global !== "init") {
2026-07-20 16:05:17 +00:00
items = [];
items[0] = global;
items1 = items;
}
if (!items1) {
items1 = [];
}
combined = items1.concat(MessageFormat.defaultLocale);
length = combined.length;
num = 0;
if (0 < length) {
while (true) {
str = combined[num];
str2 = str.toLowerCase();
parts = str2.split("-");
2026-07-29 08:29:29 +00:00
tmp2 = num;
2026-07-20 16:05:17 +00:00
if (parts.length) {
2026-07-29 08:29:29 +00:00
tmp3 = tmp[parts.join(parts, "-")];
while (!tmp3) {
2026-07-20 16:05:17 +00:00
arr = parts.pop();
continue;
}
2026-07-29 08:29:29 +00:00
return tmp3.locale;
2026-07-20 16:05:17 +00:00
}
num = num + 1;
}
}
arr1 = combined.pop();
error = new Error("No locale data has been added to IntlMessageFormat for: " + combined.join(", ") + ", or the default locale: " + arr1);
throw error;
}
}
2026-07-23 10:11:24 +00:00
extend.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" } } } });
2026-07-29 08:29:29 +00:00
let obj = { value: null };
obj[0] = extend.objCreate(null);
2026-07-23 10:11:24 +00:00
extend.defineProperty(MessageFormat, "__localeData__", obj);
2026-07-20 16:05:17 +00:00
obj = {
value(locale) {
if (locale) {
if (locale.locale) {
MessageFormat.__localeData__[locale.locale.toLowerCase()] = locale;
}
}
const error = new Error("Locale data provided to IntlMessageFormat is missing a `locale` property");
throw error;
}
};
2026-07-23 10:11:24 +00:00
extend.defineProperty(MessageFormat, "__addLocaleData", obj);
extend.defineProperty(MessageFormat, "__parse", { value: require("SyntaxError").default.parse });
2026-07-29 08:29:29 +00:00
extend.defineProperty(MessageFormat, "defaultLocale", { enumerable: true, writable: true, value: "call" });
2026-07-20 16:05:17 +00:00
export default MessageFormat;