mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-05-03 10:00:07 -04:00
feat: Updates to Collaboration and RTL UX (#2994)
This commit is contained in:
parent
4085071347
commit
73cba59d2d
9 changed files with 55 additions and 28 deletions
39
src/i18n.ts
39
src/i18n.ts
|
@ -1,5 +1,6 @@
|
|||
import fallbackLangData from "./locales/en.json";
|
||||
import percentages from "./locales/percentages.json";
|
||||
import { ENV } from "./constants";
|
||||
|
||||
const COMPLETION_THRESHOLD = 85;
|
||||
|
||||
|
@ -55,6 +56,18 @@ export const languages: Language[] = allLanguages
|
|||
COMPLETION_THRESHOLD,
|
||||
);
|
||||
|
||||
const TEST_LANG_CODE = "__test__";
|
||||
if (process.env.NODE_ENV === ENV.DEVELOPMENT) {
|
||||
languages.unshift(
|
||||
{ code: TEST_LANG_CODE, label: "test language" },
|
||||
{
|
||||
code: `${TEST_LANG_CODE}.rtl`,
|
||||
label: "\u{202a}test language (rtl)\u{202c}",
|
||||
rtl: true,
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
let currentLang: Language = defaultLang;
|
||||
let currentLangData = {};
|
||||
|
||||
|
@ -63,18 +76,13 @@ export const setLanguage = async (lang: Language) => {
|
|||
document.documentElement.dir = currentLang.rtl ? "rtl" : "ltr";
|
||||
document.documentElement.lang = currentLang.code;
|
||||
|
||||
currentLangData = await import(
|
||||
/* webpackChunkName: "i18n-[request]" */ `./locales/${currentLang.code}.json`
|
||||
);
|
||||
};
|
||||
|
||||
export const setLanguageFirstTime = async (lang: Language) => {
|
||||
currentLang = lang;
|
||||
document.documentElement.dir = currentLang.rtl ? "rtl" : "ltr";
|
||||
|
||||
currentLangData = await import(
|
||||
/* webpackChunkName: "i18n-[request]" */ `./locales/${currentLang.code}.json`
|
||||
);
|
||||
if (lang.code.startsWith(TEST_LANG_CODE)) {
|
||||
currentLangData = {};
|
||||
} else {
|
||||
currentLangData = await import(
|
||||
/* webpackChunkName: "i18n-[request]" */ `./locales/${currentLang.code}.json`
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
export const getLanguage = () => currentLang;
|
||||
|
@ -94,6 +102,13 @@ const findPartsForData = (data: any, parts: string[]) => {
|
|||
};
|
||||
|
||||
export const t = (path: string, replacement?: { [key: string]: string }) => {
|
||||
if (currentLang.code.startsWith(TEST_LANG_CODE)) {
|
||||
const name = replacement
|
||||
? `${path}(${JSON.stringify(replacement).slice(1, -1)})`
|
||||
: path;
|
||||
return `\u{202a}[[${name}]]\u{202c}`;
|
||||
}
|
||||
|
||||
const parts = path.split(".");
|
||||
let translation =
|
||||
findPartsForData(currentLangData, parts) ||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue