2024-06-16 14:21:26 +01:00
|
|
|
export const prerender = true;
|
2024-06-19 18:04:09 +01:00
|
|
|
export const ssr = false;
|
2024-07-02 19:16:03 +01:00
|
|
|
|
|
|
|
import { browser } from '$app/environment';
|
|
|
|
|
|
|
|
import { get } from 'svelte/store';
|
|
|
|
import type { Load } from '@sveltejs/kit';
|
|
|
|
|
|
|
|
import languages from '$i18n/languages.json';
|
|
|
|
import { loadTranslations, defaultLocale } from '$lib/i18n/translations';
|
|
|
|
|
|
|
|
export const load: Load = async ({ url }) => {
|
|
|
|
const { pathname } = url;
|
|
|
|
|
|
|
|
let preferredLocale = defaultLocale;
|
|
|
|
|
|
|
|
if (browser) {
|
2024-07-03 14:05:14 +01:00
|
|
|
const device = (await import('$lib/device')).device;
|
2024-07-02 19:16:03 +01:00
|
|
|
const settings = get((await import('$lib/settings')).default);
|
2024-07-12 13:49:29 +01:00
|
|
|
const deviceLanguage = device.prefers.language;
|
2024-07-02 19:16:03 +01:00
|
|
|
const settingsLanguage = settings.appearance.language;
|
|
|
|
|
|
|
|
const isValid = (lang: string) => (
|
|
|
|
Object.keys(languages).includes(lang)
|
|
|
|
);
|
|
|
|
|
|
|
|
if (settings.appearance.autoLanguage) {
|
|
|
|
if (isValid(deviceLanguage)) {
|
|
|
|
preferredLocale = deviceLanguage;
|
|
|
|
}
|
|
|
|
} else if (isValid(settingsLanguage)) {
|
|
|
|
preferredLocale = settingsLanguage
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
await loadTranslations(preferredLocale, pathname);
|
|
|
|
return {};
|
|
|
|
}
|