eslint: Outsmart formatjs/enforce-default-message.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg 2024-05-20 15:26:26 -07:00
parent caf6387514
commit 4019ccecbb
1 changed files with 17 additions and 18 deletions

View File

@ -20,15 +20,13 @@ exports.intl = createIntl(
cache,
);
exports.$t = (descriptor, values) =>
"translated: " +
exports.intl.formatMessage(
{
...descriptor,
exports.$t = (descriptor, values) => {
descriptor = {
id: `${descriptor.defaultMessage}#${descriptor.description}`,
},
values,
);
...descriptor,
};
return "translated: " + exports.intl.formatMessage(descriptor, values);
};
const default_html_elements = Object.fromEntries(
["b", "code", "em", "i", "kbd", "p", "strong"].map((tag) => [
@ -37,14 +35,14 @@ const default_html_elements = Object.fromEntries(
]),
);
exports.$t_html = (descriptor, values) =>
"translated HTML: " +
exports.intl.formatMessage(
{
...descriptor,
exports.$t_html = (descriptor, values) => {
descriptor = {
id: `${descriptor.defaultMessage}#${descriptor.description}`,
},
{
...descriptor,
};
return (
"translated HTML: " +
exports.intl.formatMessage(descriptor, {
...default_html_elements,
...Object.fromEntries(
Object.entries(values ?? {}).map(([key, value]) => [
@ -52,5 +50,6 @@ exports.$t_html = (descriptor, values) =>
typeof value === "function" ? value : _.escape(value),
]),
),
},
})
);
};