Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix switching languages at root #626

Merged
merged 1 commit into from
Dec 31, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions web/src/redux/actions/settings.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
import { captureException } from "@sentry/react";
import { Language, Languages } from "src/components/locale/languages";

export const changeLanguage = async (languageCode: Language["code"]): Promise<void> => {
// case 1: url has no language code, eg: /about / or root
// case 2: url has language code, eg: /en/about /ar/ or /ar
// case 3: url has language code, but not in the list of supported languages, eg: /es/about /es/ or /es

export const changeLanguage = (languageCode: Language["code"]) => {
let newPath = window.location.pathname;
const language = Languages.find(({ code }) => code === languageCode);
if (!language) {
Expand All @@ -25,7 +21,7 @@ export const changeLanguage = async (languageCode: Language["code"]): Promise<vo

// remove code from url if it's the default language
if (language.code === Languages[0].code) {
newPath = newPath.replace(`/${language.code}`, "");
newPath = newPath.replace(`/${language.code}`, "") || "/";
}

window.location.href = newPath;
Expand Down
Loading