2024-08-29 06:48:16 -04:00
|
|
|
import React from 'react'
|
|
|
|
import {
|
|
|
|
Dropdown,
|
|
|
|
DropdownItem,
|
|
|
|
DropdownMenu,
|
|
|
|
DropdownToggle,
|
|
|
|
} from './dropdown-menu'
|
|
|
|
import { useTranslation } from 'react-i18next'
|
|
|
|
import getMeta from '@/utils/meta'
|
|
|
|
import Icon from '@/shared/components/icon'
|
|
|
|
|
|
|
|
function LanguagePicker() {
|
|
|
|
const { t } = useTranslation()
|
|
|
|
|
|
|
|
const currentLangCode = getMeta('ol-i18n').currentLangCode
|
|
|
|
const translatedLanguages = getMeta('ol-footer').translatedLanguages
|
|
|
|
const subdomainLang = getMeta('ol-footer').subdomainLang
|
|
|
|
const currentUrlWithQueryParams = window.location.pathname
|
|
|
|
|
|
|
|
return (
|
2024-09-02 08:12:55 -04:00
|
|
|
<Dropdown drop="up">
|
2024-08-29 06:48:16 -04:00
|
|
|
<DropdownToggle
|
|
|
|
id="language-picker-toggle"
|
|
|
|
aria-label={t('select_a_language')}
|
|
|
|
data-bs-toggle="dropdown"
|
|
|
|
className="btn-inline-link"
|
|
|
|
variant="link"
|
|
|
|
>
|
|
|
|
<Icon
|
|
|
|
type="language"
|
|
|
|
className="fa fa-fw"
|
|
|
|
accessibilityLabel={t('select_a_language')}
|
|
|
|
/>
|
|
|
|
{translatedLanguages?.[currentLangCode]}
|
|
|
|
</DropdownToggle>
|
|
|
|
|
2024-09-25 09:46:02 -04:00
|
|
|
<DropdownMenu
|
|
|
|
className="dropdown-menu-sm-width"
|
|
|
|
aria-labelledby="language-picker-toggle"
|
|
|
|
>
|
2024-08-29 06:48:16 -04:00
|
|
|
{subdomainLang &&
|
|
|
|
Object.entries(subdomainLang).map(([subdomain, subdomainDetails]) => {
|
2024-09-02 08:12:55 -04:00
|
|
|
if (
|
|
|
|
!subdomainDetails ||
|
|
|
|
!subdomainDetails.lngCode ||
|
|
|
|
subdomainDetails.hide
|
|
|
|
)
|
|
|
|
return null
|
2024-08-29 06:48:16 -04:00
|
|
|
const isActive = subdomainDetails.lngCode === currentLangCode
|
|
|
|
return (
|
|
|
|
<li role="none" key={subdomain}>
|
|
|
|
<DropdownItem
|
|
|
|
href={`${subdomainDetails.url}${currentUrlWithQueryParams}`}
|
|
|
|
active={isActive}
|
|
|
|
aria-current={isActive ? 'true' : false}
|
|
|
|
trailingIcon={isActive ? 'check' : null}
|
|
|
|
>
|
|
|
|
{translatedLanguages?.[subdomainDetails.lngCode]}
|
|
|
|
</DropdownItem>
|
|
|
|
</li>
|
|
|
|
)
|
|
|
|
})}
|
|
|
|
</DropdownMenu>
|
|
|
|
</Dropdown>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
export default LanguagePicker
|