Skip to content

Commit

Permalink
[ES-1989] Fixed the issue of rendering the DEFAULT_LANG when i18n lan…
Browse files Browse the repository at this point in the history
…guage doesn't exits in the esignet. (#1061)

Signed-off-by: GurukiranP <talk2gurukiran@gmail.com>
  • Loading branch information
gk-4VII authored Dec 19, 2024
1 parent 298c465 commit 1a3b0b5
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 31 deletions.
8 changes: 6 additions & 2 deletions oidc-ui/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ function App() {
for (let idx in languages) {
if (supportedLanguages[languages[idx]]) {
i18n.changeLanguage(languages[idx]);
return;
} else {
i18n.changeLanguage(window._env_.DEFAULT_LANG);
}
}

Expand All @@ -95,9 +96,12 @@ function App() {
for (let idx in languages) {
if (langCodeMapping[languages[idx]]) {
i18n.changeLanguage(langCodeMapping[languages[idx]]);
return;
} else {
i18n.changeLanguage(window._env_.DEFAULT_LANG);
}
}
} else {
return i18n.changeLanguage(window._env_.DEFAULT_LANG);
}

//2. Check for cookie
Expand Down
61 changes: 32 additions & 29 deletions oidc-ui/src/components/NavHeader.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ export default function NavHeader({ langOptions, i18nKeyPrefix = "header" }) {
const authorizeQueryParam = "authorize_query_param";
const ui_locales = "ui_locales";

// Decode the authorize query param
const decodedBase64 = Buffer.from(
authServices.getAuthorizeQueryParam(),
"base64"
).toString();

var urlSearchParams = new URLSearchParams(decodedBase64);

const changeLanguageHandler = (e) => {
i18n.changeLanguage(e.value);
};
Expand Down Expand Up @@ -49,43 +57,17 @@ export default function NavHeader({ langOptions, i18nKeyPrefix = "header" }) {
};

useEffect(() => {
if (!langOptions || langOptions.length === 0) {
return;
}

let lang = langOptions.find((option) => {
return option.value === i18n.language;
});

if (lang == null) {
const defaultLanguageCode = window._env_.DEFAULT_LANG;

// Find the language option that matches the extracted language code
const defaultLang = langOptions.find(
(option) => option.value === defaultLanguageCode
);
setSelectedLang(defaultLang);
} else {
setSelectedLang(lang);
}

//Gets fired when changeLanguage got called.
i18n.on("languageChanged", function (lng) {
let language = langOptions.find((option) => {
return option.value === lng;
});
setSelectedLang(language);

if (language) {
setSelectedLang(language);
}
// Setting up the current i18n language in the URL on every language change.

// Decode the authorize query param
const decodedBase64 = Buffer.from(
authServices.getAuthorizeQueryParam(),
"base64"
).toString();

var urlSearchParams = new URLSearchParams(decodedBase64);

// Convert the decoded string to JSON
var jsonObject = {};
urlSearchParams.forEach(function (value, key) {
Expand Down Expand Up @@ -113,6 +95,27 @@ export default function NavHeader({ langOptions, i18nKeyPrefix = "header" }) {
// Insert the new authorizeQueryParam to the local storage
localStorage.setItem(authorizeQueryParam, encodedBase64);
});

if (!langOptions || langOptions.length === 0) {
return;
}

let lang = langOptions.find((option) => {
const currentUILocale = urlSearchParams.get("ui_locales");
return option.value === i18n.language;
});

if (!lang) {
const defaultLanguageCode = window._env_.DEFAULT_LANG;

// Find the language option that matches the extracted language code
const defaultLang = langOptions.find(
(option) => option.value === defaultLanguageCode
);
setSelectedLang(defaultLang);
} else {
setSelectedLang(lang);
}
}, [langOptions]);

var dropdownItemClass =
Expand Down

0 comments on commit 1a3b0b5

Please sign in to comment.