Skip to content

Instantly share code, notes, and snippets.

@ayeshN
Created December 10, 2020 10:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ayeshN/8680093725eab3face76ff35571148eb to your computer and use it in GitHub Desktop.
Save ayeshN/8680093725eab3face76ff35571148eb to your computer and use it in GitHub Desktop.
App.js with language switching option
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