Skip to content

Commit

Permalink
fix: fix default redirect language bug
Browse files Browse the repository at this point in the history
Previously, the default language is also the automatic language
detection option. So if a user attempts to manually change their
language to the default language away from their browser's language, it
will immediately detect the language as their browser language and
redirect them.

Additionally, language cookies weren't updated, so changing the language
from the default language to another language wouldn't be remembered.

Fix this by calling setLocale as required; see
https://i18n.nuxtjs.org/docs/guide/lang-switcher
  • Loading branch information
steadygaze committed Aug 30, 2024
1 parent e2ba4aa commit b8a406b
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion components/LanguageSelect.vue
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@ import { watch } from "vue";
import { navigateTo } from "#app";
import { useI18n, useSwitchLocalePath } from "#imports";
const { locale, locales } = useI18n();
const { locale, locales, setLocale } = useI18n();
const switchLocalePath = useSwitchLocalePath();
watch(locale, (locale) => {
// Update saved language setting, or the default language will redirect back.
setLocale(locale);
// Trigger a page reload because translations doesn't load properly otherwise.
navigateTo(switchLocalePath(locale), { external: true });
});
Expand Down

0 comments on commit b8a406b

Please sign in to comment.