initial stuff

This commit is contained in:
Henri
2025-11-21 08:15:07 +02:00
parent a38a367ac5
commit 8c18827dc5
33 changed files with 522 additions and 148 deletions

35
src/lib/i18n.js Normal file
View File

@@ -0,0 +1,35 @@
import { writable } from 'svelte/store';
// Load saved language or default to 'est'
const savedLang = typeof window !== 'undefined'
? localStorage.getItem('language') || 'est'
: 'est';
// Store for current language
export const currentLang = writable(savedLang);
// Store for translations
export const text = writable({});
// Load translations for a specific language
async function loadTranslations(lang) {
try {
const response = await fetch(`/locales/${lang}.json`);
const data = await response.json();
text.set(data);
} catch (error) {
console.error(`Failed to load translations for ${lang}:`, error);
}
}
// Initialize translations
loadTranslations(savedLang);
// Function to switch language
export function switchLang(lang) {
currentLang.set(lang);
loadTranslations(lang);
if (typeof window !== 'undefined') {
localStorage.setItem('language', lang);
}
}