-
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.
- Loading branch information
1 parent
c649b5a
commit d78ed6f
Showing
4 changed files
with
77 additions
and
5 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default } from "./translationKeys.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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import styled from "styled-components"; | ||
|
||
export const Container = styled.div` | ||
/* background-color: red; */ | ||
`; | ||
|
||
export const Keys = styled.span` | ||
cursor: pointer; | ||
padding: 0.2em; | ||
color: black; | ||
font-size: 13px; | ||
font-weight: 100; | ||
`; |
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 |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import { useState, useEffect } from "react"; | ||
import * as Styled from "./styles.js"; | ||
import { withTranslation } from "react-i18next"; | ||
|
||
const TranslationKeys = prop => { | ||
const [selectedLanguage, setSelectedLanguage] = useState(); | ||
|
||
const languages = [ | ||
{ id: 0, language: "de" }, | ||
{ id: 1, language: "fr" }, | ||
{ id: 2, language: "it" }, | ||
{ id: 3, language: "en" }, | ||
]; | ||
|
||
useEffect(() => { | ||
let lang; | ||
|
||
switch (prop.i18n.language) { | ||
case "de": | ||
lang = languages[0]; | ||
break; | ||
case "fr": | ||
lang = languages[1]; | ||
break; | ||
case "it": | ||
lang = languages[2]; | ||
break; | ||
case "en": | ||
lang = languages[3]; | ||
break; | ||
default: | ||
lang = languages[0]; | ||
} | ||
setSelectedLanguage(lang); | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, [prop.i18n.language]); | ||
|
||
return ( | ||
<Styled.Container> | ||
{languages.map((item, key) => ( | ||
<Styled.Keys | ||
key={key} | ||
onClick={() => { | ||
setSelectedLanguage(item); | ||
if (prop?.ignori18n) { | ||
prop.handleSelectedLanguage(item.language); | ||
} else { | ||
prop.i18n.changeLanguage(item.language); | ||
} | ||
}} | ||
style={{ | ||
color: selectedLanguage?.language === item.language ? "red" : "black", | ||
textDecoration: selectedLanguage?.language === item.language ? "underline" : "none", | ||
}}> | ||
{item.language.toUpperCase()} | ||
</Styled.Keys> | ||
))} | ||
</Styled.Container> | ||
); | ||
}; | ||
|
||
const TranslatedKeys = withTranslation("common")(TranslationKeys); | ||
export default TranslatedKeys; |
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