2020-08-01 03:43:15 +02:00
|
|
|
"use strict";
|
|
|
|
|
2021-04-10 03:11:59 +02:00
|
|
|
const {createIntl, createIntlCache} = require("@formatjs/intl");
|
|
|
|
const _ = require("lodash");
|
|
|
|
|
|
|
|
const cache = createIntlCache();
|
|
|
|
|
|
|
|
exports.intl = createIntl(
|
|
|
|
{
|
|
|
|
locale: "en",
|
|
|
|
defaultLocale: "en",
|
|
|
|
defaultRichTextElements: Object.fromEntries(
|
|
|
|
["b", "code", "em", "i", "kbd", "p", "strong"].map((tag) => [
|
|
|
|
tag,
|
|
|
|
(content_html) => `<${tag}>${content_html}</${tag}>`,
|
|
|
|
]),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
cache,
|
|
|
|
);
|
|
|
|
|
|
|
|
exports.$t = (descriptor, values) =>
|
|
|
|
"translated: " +
|
|
|
|
exports.intl.formatMessage(
|
|
|
|
{
|
|
|
|
...descriptor,
|
|
|
|
id: `${descriptor.defaultMessage}#${descriptor.description}`,
|
|
|
|
},
|
|
|
|
values,
|
|
|
|
);
|
|
|
|
|
|
|
|
const default_html_elements = Object.fromEntries(
|
|
|
|
["b", "code", "em", "i", "kbd", "p", "strong"].map((tag) => [
|
|
|
|
tag,
|
|
|
|
(content_html) => `<${tag}>${content_html}</${tag}>`,
|
|
|
|
]),
|
|
|
|
);
|
|
|
|
|
|
|
|
exports.$t_html = (descriptor, values) =>
|
|
|
|
"translated HTML: " +
|
|
|
|
exports.intl.formatMessage(
|
|
|
|
{
|
|
|
|
...descriptor,
|
|
|
|
id: `${descriptor.defaultMessage}#${descriptor.description}`,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
...default_html_elements,
|
|
|
|
...Object.fromEntries(
|
|
|
|
Object.entries(values ?? {}).map(([key, value]) => [
|
|
|
|
key,
|
|
|
|
typeof value === "function" ? value : _.escape(value),
|
|
|
|
]),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
);
|