Skip to content

Commit

Permalink
[ADDED] i18n language changes for default lang (#1067)
Browse files Browse the repository at this point in the history
Signed-off-by: Zeeshan Mehboob <[email protected]>
  • Loading branch information
zesu22 authored Dec 23, 2024
1 parent b6a7b32 commit 6d06a3d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
23 changes: 16 additions & 7 deletions oidc-ui/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,28 +78,37 @@ function App() {

//1. Check for ui locales param. Highest priority.
//This will override the language detectors selected language
let supportedLanguages = loadLang.languages_2Letters;
let { languages_2Letters: supportedLanguages, langCodeMapping } = loadLang;
let searchUrlParams = new URLSearchParams(window.location.search);
let uiLocales = searchUrlParams.get("ui_locales");
if (uiLocales) {
let languages = uiLocales.split(" ");
for (let idx in languages) {
if (supportedLanguages[languages[idx]]) {
i18n.changeLanguage(languages[idx]);
} else {
i18n.changeLanguage(window._env_.DEFAULT_LANG);
return;
}
}

// if language code not found in 2 letter codes, then check mapped language codes
let langCodeMapping = loadLang.langCodeMapping;
for (let idx in languages) {
if (langCodeMapping[languages[idx]]) {
i18n.changeLanguage(langCodeMapping[languages[idx]]);
} else {
i18n.changeLanguage(window._env_.DEFAULT_LANG);
return;
}
}

let defaultLang = window._env_.DEFAULT_LANG;
// checking default language in 2 letter language code
if (defaultLang in supportedLanguages) {
i18n.changeLanguage(defaultLang)
return
}
// checking default language in 3 letter language code
if (defaultLang in langCodeMapping) {
i18n.changeLanguage(langCodeMapping[defaultLang])
return
}
}

//2. Check for cookie
Expand All @@ -117,7 +126,7 @@ function App() {
case states.LOADING:
el = (
<div className="h-screen flex justify-center content-center">
<LoadingIndicator size="medium" message={"loading_msg"} className="align-loading-center"/>
<LoadingIndicator size="medium" message={"loading_msg"} className="align-loading-center" />
</div>
);
break;
Expand Down
1 change: 0 additions & 1 deletion oidc-ui/src/components/NavHeader.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ export default function NavHeader({ langOptions, i18nKeyPrefix = "header" }) {
}

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

Expand Down

0 comments on commit 6d06a3d

Please sign in to comment.