forked from WildMeOrg/Wildbook
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request WildMeOrg#604 from WildMeOrg/590_react_lang_select…
…ion_persist 590 react lang selection persist
- Loading branch information
Showing
7 changed files
with
63 additions
and
66 deletions.
There are no files selected for viewing
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
105 changes: 50 additions & 55 deletions
105
frontend/src/components/navBar/MultiLanguageDropdown.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1,54 @@ | ||
import React, { useContext, useState }from 'react'; | ||
import Dropdown from 'react-bootstrap/Dropdown'; | ||
import DownIcon from '../svg/DownIcon'; | ||
import LocaleContext from '../../IntlProvider'; | ||
import { locales, localeMap, languageMap } from '../../constants/locales'; | ||
import React, { useContext, useState } from "react"; | ||
import Dropdown from "react-bootstrap/Dropdown"; | ||
import DownIcon from "../svg/DownIcon"; | ||
import LocaleContext from "../../IntlProvider"; | ||
import { locales, localeMap, languageMap } from "../../constants/locales"; | ||
import Cookies from "js-cookie"; | ||
|
||
export default function MultiLanguageDropdown() { | ||
const { onLocaleChange } = useContext(LocaleContext); | ||
const initialLocale = Cookies.get("wildbookLangCode") || "en"; | ||
const [flag, setFlag] = useState(initialLocale); | ||
return ( | ||
<div | ||
className="d-flex align-items-center justify-content-center border-0 rounded-pill m-2" | ||
style={{ | ||
backgroundColor: "rgba(255, 255, 255, 0.25)", | ||
minWidth: "65px", | ||
height: "35px", | ||
}} | ||
> | ||
<Dropdown> | ||
<Dropdown.Toggle variant="basic" id="dropdown-basic"> | ||
<img | ||
src={`/react/flags/${flag}.png`} | ||
alt="flag" | ||
style={{ width: "20px", height: "12px" }} | ||
/> | ||
<span style={{ paddingLeft: 7 }}> | ||
<DownIcon /> | ||
</span> | ||
</Dropdown.Toggle> | ||
|
||
const { onLocaleChange } = useContext(LocaleContext); | ||
const [ flag, setFlag ] = useState('UK'); | ||
return ( | ||
<div style={{ | ||
backgroundColor: 'rgba(255, 255, 255, 0.25)', | ||
border: 'none', | ||
borderRadius: '30px', | ||
minWidth: '65px', | ||
height: '35px', | ||
display: 'flex', | ||
alignItems: 'center', | ||
justifyContent: 'center', | ||
margin: '10px', | ||
}}> | ||
|
||
<Dropdown style={{ | ||
border: 'none', | ||
color: 'white', | ||
display: 'flex', | ||
flexDirection: 'row', | ||
alignItems: 'center', | ||
justifyContent: 'center', | ||
|
||
}}> | ||
<Dropdown.Toggle variant="basic" id="dropdown-basic" > | ||
<img src={`/react/flags/${flag}.png`} alt="flag" style={{width: '20px', height: '12px'}} /> | ||
<span style={{paddingLeft: 7}}><DownIcon /></span> | ||
</Dropdown.Toggle> | ||
|
||
<Dropdown.Menu> | ||
{ | ||
locales.map((locale, index) => ( | ||
<Dropdown.Item | ||
key={index} | ||
onClick={() => { | ||
onLocaleChange(locale); | ||
setFlag(localeMap[locale]); | ||
}}> | ||
<img | ||
src={`/react/flags/${localeMap[locale]}.png`} alt={locale} | ||
style={{width: '20px', height: '12px', marginRight: '10px'}} /> | ||
{languageMap[locale]} | ||
</Dropdown.Item> | ||
)) | ||
} | ||
</Dropdown.Menu> | ||
</Dropdown> | ||
</div> | ||
) | ||
<Dropdown.Menu> | ||
{locales.map((locale, index) => ( | ||
<Dropdown.Item | ||
key={index} | ||
onClick={() => { | ||
onLocaleChange(locale); | ||
setFlag(localeMap[locale]); | ||
}} | ||
> | ||
<img | ||
src={`/react/flags/${localeMap[locale]}.png`} | ||
alt={locale} | ||
style={{ width: "20px", height: "12px", marginRight: "10px" }} | ||
/> | ||
{languageMap[locale]} | ||
</Dropdown.Item> | ||
))} | ||
</Dropdown.Menu> | ||
</Dropdown> | ||
</div> | ||
); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,16 @@ | ||
|
||
const locales = ['en', 'es', 'fr', 'it']; | ||
const locales = ["en", "es", "fr", "it"]; | ||
const localeMap = { | ||
en: 'UK', | ||
es: 'ES', | ||
fr: 'FR', | ||
it: 'IT', | ||
en: "en", | ||
es: "es", | ||
fr: "fr", | ||
it: "it", | ||
}; | ||
|
||
const languageMap = { | ||
en: 'English', | ||
es: 'Español', | ||
fr: 'Francés', | ||
it: 'Italiano', | ||
en: "English", | ||
es: "Español", | ||
fr: "Francés", | ||
it: "Italiano", | ||
}; | ||
|
||
export { locales, localeMap, languageMap }; |