mirror of
https://github.com/wukko/cobalt.git
synced 2024-11-16 05:09:57 +00:00
d27bed7add
also cleaned up settings & device libs
39 lines
1.1 KiB
TypeScript
39 lines
1.1 KiB
TypeScript
export const prerender = true;
|
|
export const ssr = false;
|
|
|
|
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) {
|
|
const device = (await import('$lib/device')).device;
|
|
const settings = get((await import('$lib/settings')).default);
|
|
const deviceLanguage = device.prefers.language;
|
|
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 {};
|
|
}
|