latest dev + i18n

This commit is contained in:
_Bastler
2022-01-27 13:03:59 +01:00
parent e3b58a0d56
commit 7e987ad470
12 changed files with 70 additions and 34 deletions
+1 -1
View File
@@ -28,7 +28,7 @@ const de_DE: Translation = {
menu,
report,
warning,
emiji,
emoji,
};
export default de_DE;
+1
View File
@@ -114,6 +114,7 @@ const menu: NonNullable<Translation["menu"]> = {
},
sub: {
profile: "Profil",
worlds: "Welt",
settings: "Einstellungen",
invite: "Einladung",
credit: "Über die Karte",
+1
View File
@@ -113,6 +113,7 @@ const menu: BaseTranslation = {
},
sub: {
profile: "Profile",
worlds: "Worlds",
settings: "Settings",
invite: "Invite",
credit: "Credit",
+19 -1
View File
@@ -1,8 +1,9 @@
import { detectLocale, navigatorDetector, initLocalStorageDetector } from "typesafe-i18n/detectors";
import { FALLBACK_LOCALE } from "../Enum/EnvironmentVariable";
import { initI18n, setLocale } from "./i18n-svelte";
import { initI18n, setLocale, locale } from "./i18n-svelte";
import type { Locales, Translation } from "./i18n-types";
import { baseLocale, getTranslationForLocale, locales } from "./i18n-util";
import { get } from "svelte/store";
const fallbackLocale = FALLBACK_LOCALE || baseLocale;
const localStorageProperty = "language";
@@ -50,3 +51,20 @@ function getDisplayableLocales() {
}
export const displayableLocales = getDisplayableLocales();
export const i18nJson = (text: string): string => {
if (text.trim().startsWith("{")) {
try {
const textObject = JSON.parse(text);
if (textObject[get(locale)]) {
return textObject[get(locale)];
} else if (Object.keys(textObject).length > 0) {
// fallback to first value
return textObject[Object.keys(textObject)[0]];
}
} catch (err) {
//
}
}
return text;
};