diff --git a/src/LanguageSelector/index.jsx b/src/LanguageSelector/index.jsx index 0ef32080b..5c000c60d 100644 --- a/src/LanguageSelector/index.jsx +++ b/src/LanguageSelector/index.jsx @@ -25,8 +25,14 @@ const onLanguageSelected = async (username, selectedLanguageCode) => { }; const LanguageSelector = ({ - intl, options, authenticatedUser, ...props + intl, options, authenticatedUser, compact, ...props }) => { + + const languageLabel = (languageCode) => { + const option = options.find( ({ value, label }) => value === languageCode ) + return option ? option.label : null + } + const handleChange = (languageCode, event) => { const previousSiteLanguage = getLocale(); console.debug(previousSiteLanguage, languageCode, authenticatedUser); @@ -34,21 +40,43 @@ const LanguageSelector = ({ if (previousSiteLanguage !== languageCode) { onLanguageSelected(authenticatedUser?.username, languageCode); } + + event.target.parentElement.parentElement.querySelector(".languageLabel").innerHTML = languageLabel(languageCode); }; + const currentLangLabel = languageLabel(intl.locale) + const showLabel = !Boolean(compact || false); + return ( - - - - - - {options.map(({ value, label }) => ( - - {label} - - ))} - - + <> + + + + {showLabel && ( + currentLangLabel ? ( + + {currentLangLabel} + + ) : ( + + + + ) + )} + + + {options.map(({ value, label }) => ( + + {label} + + ))} + + + ); }; @@ -57,6 +85,7 @@ LanguageSelector.propTypes = { username: PropTypes.string, }).isRequired, intl: intlShape.isRequired, + compact: PropTypes.bool, options: PropTypes.arrayOf(PropTypes.shape({ value: PropTypes.string, label: PropTypes.string, diff --git a/src/learning-header/LearningHeader.jsx b/src/learning-header/LearningHeader.jsx index ff9445a86..64faea642 100644 --- a/src/learning-header/LearningHeader.jsx +++ b/src/learning-header/LearningHeader.jsx @@ -82,10 +82,20 @@ const LearningHeader = ({ {getConfig().ENABLE_HEADER_LANG_SELECTOR && (
- + + + + + +
)} {showUserDropdown && authenticatedUser && (