Created
December 10, 2020 10:30
-
-
Save ayeshN/8680093725eab3face76ff35571148eb to your computer and use it in GitHub Desktop.
App.js with language switching option
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
import logo from "./logo.svg"; | |
import "./App.css"; | |
import { withTranslation } from "react-i18next"; | |
const App = (props) => { | |
const { t } = props; | |
const onLanguageChanged = (event) => { | |
let language = event.currentTarget.value; | |
props.i18n.changeLanguage(language); | |
}; | |
return ( | |
<div className="App"> | |
<header className="App-header"> | |
<button value="en" onClick={(value) => onLanguageChanged(value)}> | |
English | |
</button> | |
<button Value="sv" onClick={(value) => onLanguageChanged(value)}> | |
Swedish | |
</button> | |
<img src={logo} className="App-logo" alt="logo" /> | |
<p>{t("Hi")}</p> | |
<p>{t("Welcome")}</p> | |
</header> | |
</div> | |
); | |
}; | |
export default withTranslation()(App); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment