mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-05-03 10:00:07 -04:00
feat: Support LaTeX and AsciiMath via MathJax on stem.excalidraw.com
This commit is contained in:
parent
c8370b394c
commit
86f5c2ebcf
84 changed files with 8331 additions and 289 deletions
34
src/i18n.ts
34
src/i18n.ts
|
@ -82,6 +82,22 @@ if (process.env.NODE_ENV === ENV.DEVELOPMENT) {
|
|||
let currentLang: Language = defaultLang;
|
||||
let currentLangData = {};
|
||||
|
||||
const auxCurrentLangData = Array<Object>();
|
||||
const auxFallbackLangData = Array<Object>();
|
||||
const auxSetLanguageFuncs =
|
||||
Array<(langCode: string) => Promise<Object | undefined>>();
|
||||
|
||||
export const registerAuxLangData = (
|
||||
fallbackLangData: Object,
|
||||
setLanguageAux: (langCode: string) => Promise<Object | undefined>,
|
||||
) => {
|
||||
if (auxFallbackLangData.includes(fallbackLangData)) {
|
||||
return;
|
||||
}
|
||||
auxFallbackLangData.push(fallbackLangData);
|
||||
auxSetLanguageFuncs.push(setLanguageAux);
|
||||
};
|
||||
|
||||
export const setLanguage = async (lang: Language) => {
|
||||
currentLang = lang;
|
||||
document.documentElement.dir = currentLang.rtl ? "rtl" : "ltr";
|
||||
|
@ -94,6 +110,17 @@ export const setLanguage = async (lang: Language) => {
|
|||
currentLangData = await import(
|
||||
/* webpackChunkName: "locales/[request]" */ `./locales/${currentLang.code}.json`
|
||||
);
|
||||
// Empty the auxCurrentLangData array
|
||||
while (auxCurrentLangData.length > 0) {
|
||||
auxCurrentLangData.pop();
|
||||
}
|
||||
// Fill the auxCurrentLangData array with each locale file found in auxLangDataRoots for this language
|
||||
auxSetLanguageFuncs.forEach(async (setLanguageFn) => {
|
||||
const condData = await setLanguageFn(currentLang.code);
|
||||
if (condData) {
|
||||
auxCurrentLangData.push(condData);
|
||||
}
|
||||
});
|
||||
} catch (error: any) {
|
||||
console.error(`Failed to load language ${lang.code}:`, error.message);
|
||||
currentLangData = fallbackLangData;
|
||||
|
@ -132,6 +159,13 @@ export const t = (
|
|||
let translation =
|
||||
findPartsForData(currentLangData, parts) ||
|
||||
findPartsForData(fallbackLangData, parts);
|
||||
const auxData = Array<Object>().concat(
|
||||
auxCurrentLangData,
|
||||
auxFallbackLangData,
|
||||
);
|
||||
for (let i = 0; i < auxData.length; i++) {
|
||||
translation = translation || findPartsForData(auxData[i], parts);
|
||||
}
|
||||
if (translation === undefined) {
|
||||
throw new Error(`Can't find translation for ${path}`);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue