Skip to content

Commit

Permalink
Merge pull request #626 from dzcode-io/fix/language-switch
Browse files Browse the repository at this point in the history
Fix switching languages at root
  • Loading branch information
omdxp authored Dec 31, 2024
2 parents 99217d5 + eb7a694 commit 86a8cca
Showing 1 changed file with 2 additions and 6 deletions.
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

0 comments on commit 86a8cca

Please sign in to comment.