i18n
This commit is contained in:
parent
a50cbd3521
commit
8647199625
@ -1,9 +1,10 @@
|
||||
import { detectLocale, navigatorDetector, initLocalStorageDetector } from "typesafe-i18n/detectors";
|
||||
import { FALLBACK_LOCALE } from "../Enum/EnvironmentVariable";
|
||||
import { setLocale } from "./i18n-svelte";
|
||||
import { setLocale, locale } from "./i18n-svelte";
|
||||
import type { Locales } from "./i18n-types";
|
||||
import { baseLocale, locales } from "./i18n-util";
|
||||
import { loadLocaleAsync } from "./i18n-util.async";
|
||||
import { get } from "svelte/store";
|
||||
|
||||
const fallbackLocale = (FALLBACK_LOCALE || baseLocale) as Locales;
|
||||
const localStorageProperty = "language";
|
||||
@ -42,3 +43,20 @@ export const displayableLocales: { id: Locales; language: string; region: string
|
||||
region: new Intl.DisplayNames(locale, { type: "region" }).of(region),
|
||||
};
|
||||
});
|
||||
|
||||
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;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user