Auto locale

This commit is contained in:
2024-09-28 00:18:35 +03:00
parent 9020d7bbef
commit 19c29b6fb2
4 changed files with 39 additions and 11 deletions

View File

@@ -0,0 +1,18 @@
import type {LayoutServerLoad} from './$types';
import {defaultLocale, locales} from "$lib/translations";
export const prerender = true;
export const load: LayoutServerLoad = async ({ request }) => {
const supportedLocales = locales.get().map((l) => l.toLowerCase());
let locale = `${`${request.headers.get('accept-language')}`.match(/[a-zA-Z]+?(?=[-_,;])/)}`.toLowerCase();
if (!supportedLocales.includes(locale)) {
locale = defaultLocale;
}
return {
i18n: { locale },
};
}