1
0
Fork 0
mirror of https://github.com/seanmorley15/AdventureLog.git synced 2025-07-21 13:59:36 +02:00

localization v1

This commit is contained in:
Sean Morley 2024-10-26 23:03:35 -04:00
parent 6f8864a13d
commit 6cf62cfb82
12 changed files with 661 additions and 64 deletions

View file

@ -107,4 +107,20 @@ export const themeHook: Handle = async ({ event, resolve }) => {
return await resolve(event);
};
export const handle = sequence(authHook, themeHook);
// hook to get the langauge cookie and set the locale
export const i18nHook: Handle = async ({ event, resolve }) => {
let lang = event.cookies.get('lang');
if (!lang) {
lang = ''; // Set default locale
event.cookies.set('lang', lang, {
httpOnly: true,
sameSite: 'lax',
expires: new Date(Date.now() + 365 * 24 * 60 * 60 * 1000), // 1 year
path: '/'
});
}
event.locals.locale = lang; // Store the locale in locals
return await resolve(event);
};
export const handle = sequence(authHook, themeHook, i18nHook);