I'm trying to do a function using useState to change the languages of my website. However, I'm having an issue thinking about the logic of how can it be done since I'm newbie.
1st question:
How can I use the function "handleLanguage" to change the menu language when I click in <li>.
2nd question: Which would be the best way to change the whole language website by clicking on the option? Because as I see, now if I click, will change only one component.
Code:
const languages = {
en: {
about: "about",
project: "project",
contact: "contact",
slogan: "Think the Design, and I design the Code.",
button: "Learn more",
},
ptbr: {
about: "sobre",
project: "projetos",
contact: "contatos",
slogan: "Think the Design, and I design the Code.",
button: "Learn more",
},
jp: {
about: "nihon",
project: "nihon",
contact: "nihon",
slogan: "nihon",
button: "nihon",
},
ru: {
about: "руский",
project: "руский",
contact: "руский",
slogan: "руский",
button: "руский",
},
};
const RightNav = ({ open }) => {
const [text, setText] = useState("en");
const handleLanguage = (e) => {
setText("ptbr");
};
return (
<>
<Ul open={open}>
<li>{languages.en.about}</li>
<li>{languages.en.project}</li>
<li>{languages.en.contact}</li>
<li className="image">
<img src={English} alt="EN" />
</li>
<li className="image">
<img src={Japanese} alt="JP" />
</li>
<li className="image">
<img src={Russian} alt="RU" />
</li>
<li className="image">
<img src={Portuguese} alt="PT-BR" onClick={handleLanguage} />
</li>
</Ul>
</>
);
};