initial production version

This commit is contained in:
rasmusq
2025-11-25 16:08:50 +01:00
parent 44ce6e38dd
commit 0144e8df1a
108 changed files with 5502 additions and 1780 deletions
+63
View File
@@ -0,0 +1,63 @@
import { translations, type LanguageCode } from '$lib/i18n/translations';
import type { Translation } from '$lib/i18n/translations/en';
const LANGUAGE_KEY = 'preferred-language';
function getStoredLanguage(): LanguageCode {
if (typeof window === 'undefined') return 'en';
const stored = localStorage.getItem(LANGUAGE_KEY);
if (stored && (stored === 'en' || stored === 'da')) {
return stored as LanguageCode;
}
// Try to detect from browser
const browserLang = navigator.language.toLowerCase();
if (browserLang.startsWith('da')) {
return 'da';
}
return 'en';
}
class LanguageStore {
private _current = $state<LanguageCode>(getStoredLanguage());
get current(): LanguageCode {
return this._current;
}
set current(value: LanguageCode) {
this._current = value;
if (typeof window !== 'undefined') {
localStorage.setItem(LANGUAGE_KEY, value);
}
}
get t(): Translation {
return translations[this._current];
}
setLanguage(lang: LanguageCode) {
this.current = lang;
}
}
export const languageStore = new LanguageStore();
// Helper function to get nested translation value
export function t(path: string): string {
const keys = path.split('.');
let value: any = languageStore.t;
for (const key of keys) {
if (value && typeof value === 'object' && key in value) {
value = value[key];
} else {
console.warn(`Translation key not found: ${path}`);
return path;
}
}
return typeof value === 'string' ? value : path;
}