aboutsummaryrefslogtreecommitdiffstats
path: root/src/routes
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2023-04-29 23:44:29 -0700
committerAdam Soltys <[email protected]>2023-04-29 23:44:29 -0700
commit1f79c6594d34c19dbf6052df64d5a55be7e9e2f6 (patch)
treeb739984e64eb082cb9541621ef05425a9938b70c /src/routes
parent92c70d8350dab3de8e786bdad1c0a8f991cd8dbc (diff)
downloadcoinos-ui-1f79c6594d34c19dbf6052df64d5a55be7e9e2f6.tar.gz
coinos-ui-1f79c6594d34c19dbf6052df64d5a55be7e9e2f6.zip
get user locale from db
Diffstat (limited to 'src/routes')
-rw-r--r--src/routes/+layout.js8
-rw-r--r--src/routes/+layout.server.js17
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 {};
+};