Erweiterungen

This commit is contained in:
2026-02-20 09:14:36 +01:00
parent 1c9c1c67e1
commit a4c3c67f8a
30 changed files with 821 additions and 647 deletions

View File

@@ -9,8 +9,8 @@ const COOKIE_MAX_AGE_DAYS = 365; // Cookie gültig für 1 Jahr
* @param languageCode - The language code (e.g., 'de', 'en', 'fr', 'es')
*/
export function setLanguageCookie(languageCode: string): void {
const maxAge = COOKIE_MAX_AGE_DAYS * 24 * 60 * 60; // Convert days to seconds
document.cookie = `${LANGUAGE_COOKIE_NAME}=${languageCode};path=/;max-age=${maxAge};SameSite=Lax`;
const maxAge = COOKIE_MAX_AGE_DAYS * 24 * 60 * 60; // Convert days to seconds
document.cookie = `${LANGUAGE_COOKIE_NAME}=${languageCode};path=/;max-age=${maxAge};SameSite=Lax`;
}
/**
@@ -18,39 +18,39 @@ export function setLanguageCookie(languageCode: string): void {
* @returns The language code or null if not found
*/
export function getLanguageCookie(): string | null {
const cookies = document.cookie.split(';');
for (const cookie of cookies) {
const [name, value] = cookie.trim().split('=');
if (name === LANGUAGE_COOKIE_NAME) {
return decodeURIComponent(value);
}
const cookies = document.cookie.split(';');
for (const cookie of cookies) {
const [name, value] = cookie.trim().split('=');
if (name === LANGUAGE_COOKIE_NAME) {
return decodeURIComponent(value);
}
return null;
}
return null;
}
/**
* Clears the language cookie
*/
export function clearLanguageCookie(): void {
document.cookie = `${LANGUAGE_COOKIE_NAME}=;path=/;max-age=0;SameSite=Lax`;
document.cookie = `${LANGUAGE_COOKIE_NAME}=;path=/;max-age=0;SameSite=Lax`;
}
/**
* Maps Language enum values to locale strings
*/
export const languageToLocale: Record<string, string> = {
'DE': 'de',
'EN': 'en',
'FR': 'fr',
'ES': 'es'
DE: 'de',
EN: 'en',
FR: 'fr',
ES: 'es',
};
/**
* Maps locale strings to Language enum values
*/
export const localeToLanguage: Record<string, string> = {
'de': 'DE',
'en': 'EN',
'fr': 'FR',
'es': 'ES'
};
de: 'DE',
en: 'EN',
fr: 'FR',
es: 'ES',
};