From d961a61ba0f19cbb9c1782f308259e72dfb08f7f Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Thu, 5 Jan 2023 17:20:44 -0800 Subject: support server side translations --- src/lib/translations/index.js | 2 +- src/routes/+layout.js | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 src/routes/+layout.js (limited to 'src') diff --git a/src/lib/translations/index.js b/src/lib/translations/index.js index 7b909711..9c798530 100644 --- a/src/lib/translations/index.js +++ b/src/lib/translations/index.js @@ -50,4 +50,4 @@ const config = { ] }; -export const { t, l, locales, locale } = new i18n(config); +export const { t, loading, locales, locale, loadTranslations } = new i18n(config); diff --git a/src/routes/+layout.js b/src/routes/+layout.js new file mode 100644 index 00000000..add74f87 --- /dev/null +++ b/src/routes/+layout.js @@ -0,0 +1,8 @@ +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 {}; +}; -- cgit v1.2.3