Skip to content

Commit

Permalink
fix: Server hooks regex
Browse files Browse the repository at this point in the history
  • Loading branch information
kiosion committed Oct 3, 2023
1 parent 0309a03 commit 783ba4d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 2 additions & 2 deletions svelte-app/src/hooks.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ export const handle = (async ({ event, resolve }) => {
};

const lang = event.request.url.match(
new RegExp(`^.*(?:(?:.[a-z]{3})|(?:[a-z]+:[0-9]{4}))/(${APP_LANGS.join('|')})/?`)
new RegExp(`^(?:https?://)?[^/]+/(${APP_LANGS.join('|')})/?`)
),
settings = event.cookies.get(LOCAL_SETTINGS_KEY);

if (lang) {
if (lang?.[1] && APP_LANGS.includes(lang[1])) {
transforms.push((html) =>
html.replace(/<html lang="en">/, `<html lang="${lang[1]}">`)
);
Expand Down
2 changes: 2 additions & 0 deletions svelte-app/src/routes/+layout.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import { classList } from 'svelte-body';
import { useMediaQuery } from 'svelte-breakpoints';
import { browser } from '$app/environment';
import { navigating, page } from '$app/stores';
import { isDesktop } from '$helpers/responsive';
import { check as checkTranslations, currentLang, isLocalized, t } from '$i18n';
Expand Down Expand Up @@ -91,6 +92,7 @@
? $page?.params?.lang
: DEFAULT_APP_LANG
);
$: browser && (document.documentElement.lang = $currentLang);
</script>

<svelte:body
Expand Down

0 comments on commit 783ba4d

Please sign in to comment.