Open samuelstroschein opened 1 month ago
I needed this too, so I created a custom helper function until theres an official function.
Hope this helps:
// helpers/switchLanguage.ts// helpers/switchLanguage.ts
import { goto } from '$app/navigation';
import { languageTag } from '$lib/paraglide/runtime';
import { get } from 'svelte/store';
import { page } from '$app/stores';
import { derived } from 'svelte/store';
// decodeURI for hebrew in url
export const langless_pathname = derived(page, ($page) =>
// removes /[language_code] from url and keeps the rest
decodeURI($page.url.pathname.replace('/' + languageTag(), '') || '/')
);
export function switchLanguage(lang: string, replaceState = false) {
goto(`/${lang}${get(langless_pathname)}`, { replaceState });
}
Context
Users are repeatedly asking why
setLanguageTag()
is not working.Proposal
Let
setLanguageTag()
set the language tag programmatically.Additional information
Related to #185 which should prevent knowledge transfer/variants behaving differently issues like these