mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-03 21:43:21 +00:00 
			
		
		
		
	i18n: Initialize FormatJS.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
		
				
					committed by
					
						
						Tim Abbott
					
				
			
			
				
	
			
			
			
						parent
						
							6cf398f157
						
					
				
				
					commit
					4b4cea90a3
				
			@@ -1,10 +1,43 @@
 | 
			
		||||
// For documentation on i18n in Zulip, see:
 | 
			
		||||
// https://zulip.readthedocs.io/en/latest/translating/internationalization.html
 | 
			
		||||
 | 
			
		||||
import {createIntl, createIntlCache} from "@formatjs/intl";
 | 
			
		||||
import i18next from "i18next";
 | 
			
		||||
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),
 | 
			
		||||
            ]),
 | 
			
		||||
        ),
 | 
			
		||||
    });
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
i18next.init({
 | 
			
		||||
    lng: "lang",
 | 
			
		||||
    resources: {
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user