import { writable, derived, type Writable } from "svelte/store"; export const language: Writable = writable('de'); const translations: Record> = { de: { 'gallery': 'Galerie', 'album': 'Album', 'albums': 'Alben', 'photo': 'Foto', 'photos': 'Fotos', 'video': 'Video', 'videos': 'Videos', 'back': 'Zurück', 'small': 'Klein', 'medium': 'Mittel', 'large': 'Groß', 'open': 'Öffnen', 'download': 'Herunterladen', 'download-all': 'Alle herunterladen', }, en: { 'gallery': 'Gallery', 'album': 'Album', 'albums': 'Albums', 'photo': 'Photo', 'photos': 'Photos', 'video': 'Video', 'videos': 'Videos', 'back': 'Back', 'small': 'Small', 'medium': 'Medium', 'large': 'Large', 'open': 'Open', 'download': 'Download', 'download-all': 'Download all', } }; export const str = derived(language, $language => { function translate(key: string, ...args: any[]) { const str = translations[$language][key]; if (str === undefined) return key; return str.replace(/\{(\d+)\}/g, (_, i) => args[i]); } return translate; }); export const strf = derived(language, $language => { function translate(translations: Translation | string, ...args: any[]) { if (translations === undefined) return undefined; if (typeof translations === 'string') return translations; const str = translations[$language]; if (str === undefined) return translations.de; return str.replace(/\{(\w+)\}/g, (_, i) => args[i]); } return translate; });