mirror of https://github.com/zulip/zulip.git
39 lines
1.0 KiB
JavaScript
39 lines
1.0 KiB
JavaScript
// For documentation on i18n in Zulip, see:
|
|
// https://zulip.readthedocs.io/en/latest/translating/internationalization.html
|
|
|
|
import {createIntl, createIntlCache} from "@formatjs/intl";
|
|
import _ from "lodash";
|
|
|
|
import {page_params} from "./page_params";
|
|
|
|
const cache = createIntlCache();
|
|
export const intl = createIntl(
|
|
{
|
|
locale: page_params.default_language,
|
|
defaultLocale: "en",
|
|
messages: page_params.translation_data,
|
|
},
|
|
cache,
|
|
);
|
|
|
|
export const $t = intl.formatMessage;
|
|
|
|
export const default_html_elements = Object.fromEntries(
|
|
["b", "code", "em", "i", "kbd", "p", "strong"].map((tag) => [
|
|
tag,
|
|
(content_html) => `<${tag}>${content_html}</${tag}>`,
|
|
]),
|
|
);
|
|
|
|
export function $t_html(descriptor, values) {
|
|
return intl.formatMessage(descriptor, {
|
|
...default_html_elements,
|
|
...Object.fromEntries(
|
|
Object.entries(values ?? {}).map(([key, value]) => [
|
|
key,
|
|
typeof value === "function" ? value : _.escape(value),
|
|
]),
|
|
),
|
|
});
|
|
}
|