Skip to content

Commit

Permalink
[ES-791] Fixed: User preferred/selected language is not retained duri…
Browse files Browse the repository at this point in the history
…ng redirection.

Signed-off-by: GurukiranP <[email protected]>
  • Loading branch information
gk-4VII committed Feb 28, 2024
1 parent 68b4b87 commit 5e180c1
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions signup-ui/src/components/language.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,40 @@ import { Icons } from "./ui/icons";

export const Language = () => {
const { i18n } = useTranslation();
const ui_locales = "ui_locales";

const handleLanguageChange = (language: string) => {
i18n.changeLanguage(language);

// Get the encoded string from the URL
const hashCode = window.location.hash.substring(1);

// Decode the string
const decodedBase64 = atob(hashCode)

var urlSearchParams = new URLSearchParams(decodedBase64);

// Convert the decoded string to JSON
var jsonObject: Record<string, string> = {};
urlSearchParams.forEach(function (value, key) {
jsonObject[key] = value;
// Assign the current i18n language to the ui_locales
if(key === ui_locales) {
jsonObject[key] = language
}
});

// Convert the JSON back to decoded string
Object.entries(jsonObject).forEach(([key, value]) => {
urlSearchParams.set(key, value);
});

// Encode the string
const encodedBase64 = btoa(urlSearchParams.toString());
const url = window.location.origin + window.location.pathname + "#" + encodedBase64

// Replace the current url with the modified url due to the language change
window.history.replaceState(null, "", url);
};

return (
Expand Down

0 comments on commit 5e180c1

Please sign in to comment.