Something went wrong. Try again.
A downstream fork of Tranquil PDS for use in margin.cafe
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061import { _, getLocaleFromNavigator, init, locale, register } from "svelte-i18n";
const LOCALE_STORAGE_KEY = "tranquil-pds-locale";
const SUPPORTED_LOCALES = ["en", "zh", "ja", "ko", "sv", "fi", "fr"] as const;export type SupportedLocale = typeof SUPPORTED_LOCALES[number];
export const localeNames: Record<SupportedLocale, string> = { en: "English", zh: "中文", ja: "日本語", ko: "한국어", sv: "Svenska", fi: "Suomi", fr: "Français",};
register("en", () => import("../locales/en.json"));register("zh", () => import("../locales/zh.json"));register("ja", () => import("../locales/ja.json"));register("ko", () => import("../locales/ko.json"));register("sv", () => import("../locales/sv.json"));register("fi", () => import("../locales/fi.json"));register("fr", () => import("../locales/fr.json"));
function getInitialLocale(): string { const stored = localStorage.getItem(LOCALE_STORAGE_KEY); if (stored && SUPPORTED_LOCALES.includes(stored as SupportedLocale)) { return stored; }
const browserLocale = getLocaleFromNavigator(); if (browserLocale) { const lang = browserLocale.split("-")[0]; if (SUPPORTED_LOCALES.includes(lang as SupportedLocale)) { return lang; } }
return "en";}
export function initI18n() { init({ fallbackLocale: "en", initialLocale: getInitialLocale(), });}
export function setLocale(newLocale: SupportedLocale) { locale.set(newLocale); localStorage.setItem(LOCALE_STORAGE_KEY, newLocale); document.documentElement.lang = newLocale;}
export function getSupportedLocales(): SupportedLocale[] { return [...SUPPORTED_LOCALES];}
export { _, locale };