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

[ES-1989] Fixed the issue of rendering the DEFAULT_LANG when i18n language doesn't exist in the esignet. #1061

Merged
merged 1 commit into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
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: 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
Loading