diff options
Diffstat (limited to 'src/routes')
| -rw-r--r-- | src/routes/+layout.js | 8 | ||||
| -rw-r--r-- | src/routes/+layout.server.js | 17 |
2 files changed, 17 insertions, 8 deletions
diff --git a/src/routes/+layout.js b/src/routes/+layout.js deleted file mode 100644 index add74f87..00000000 --- a/src/routes/+layout.js +++ /dev/null @@ -1,8 +0,0 @@ -import { loadTranslations, locale } from '$lib/translations'; -export const load = async ({ url }) => { - const { pathname } = url; - const defaultLocale = 'en'; // get from cookie, user session, ... - const initLocale = locale.get() || defaultLocale; // set default if no locale already set - await loadTranslations(initLocale, pathname); // keep this just before the `return` - return {}; -}; diff --git a/src/routes/+layout.server.js b/src/routes/+layout.server.js new file mode 100644 index 00000000..5359d022 --- /dev/null +++ b/src/routes/+layout.server.js @@ -0,0 +1,17 @@ +import { auth, get } from "$lib/utils"; +import { loadTranslations, locale } from '$lib/translations'; +export const load = async ({ cookies, url }) => { + let user; + let token = cookies.get('token'); + if (token) { + try { + user = await get('/me', auth(cookies)); + } catch (e) {} + } + + const { pathname } = url; + const defaultLocale = user?.language || 'en'; // get from cookie, user session, ... + const initLocale = locale.get() || defaultLocale; // set default if no locale already set + await loadTranslations(initLocale, pathname); // keep this just before the `return` + return {}; +}; |
