mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-05-03 10:00:07 -04:00
Prefer arrow functions and callbacks (#1210)
This commit is contained in:
parent
33fe223b5d
commit
c427aa3cce
64 changed files with 784 additions and 847 deletions
20
src/i18n.ts
20
src/i18n.ts
|
@ -43,20 +43,18 @@ export const languages = [
|
|||
let currentLanguage = languages[0];
|
||||
const fallbackLanguage = languages[0];
|
||||
|
||||
export function setLanguage(newLng: string | undefined) {
|
||||
export const setLanguage = (newLng: string | undefined) => {
|
||||
currentLanguage =
|
||||
languages.find((language) => language.lng === newLng) || fallbackLanguage;
|
||||
|
||||
document.documentElement.dir = currentLanguage.rtl ? "rtl" : "ltr";
|
||||
|
||||
languageDetector.cacheUserLanguage(currentLanguage.lng);
|
||||
}
|
||||
};
|
||||
|
||||
export function getLanguage() {
|
||||
return currentLanguage;
|
||||
}
|
||||
export const getLanguage = () => currentLanguage;
|
||||
|
||||
function findPartsForData(data: any, parts: string[]) {
|
||||
const findPartsForData = (data: any, parts: string[]) => {
|
||||
for (var i = 0; i < parts.length; ++i) {
|
||||
const part = parts[i];
|
||||
if (data[part] === undefined) {
|
||||
|
@ -68,9 +66,9 @@ function findPartsForData(data: any, parts: string[]) {
|
|||
return undefined;
|
||||
}
|
||||
return data;
|
||||
}
|
||||
};
|
||||
|
||||
export function t(path: string, replacement?: { [key: string]: string }) {
|
||||
export const t = (path: string, replacement?: { [key: string]: string }) => {
|
||||
const parts = path.split(".");
|
||||
let translation =
|
||||
findPartsForData(currentLanguage.data, parts) ||
|
||||
|
@ -85,14 +83,12 @@ export function t(path: string, replacement?: { [key: string]: string }) {
|
|||
}
|
||||
}
|
||||
return translation;
|
||||
}
|
||||
};
|
||||
|
||||
const languageDetector = new LanguageDetector();
|
||||
languageDetector.init({
|
||||
languageUtils: {
|
||||
formatLanguageCode: function (lng: string) {
|
||||
return lng;
|
||||
},
|
||||
formatLanguageCode: (lng: string) => lng,
|
||||
isWhitelisted: () => true,
|
||||
},
|
||||
checkWhitelist: false,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue