Skip to content

Instantly share code, notes, and snippets.

@shahmir811
Created October 5, 2020 03:48
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 shahmir811/8a68b1f83fe33b8168d0d29e5977be60 to your computer and use it in GitHub Desktop.
Save shahmir811/8a68b1f83fe33b8168d0d29e5977be60 to your computer and use it in GitHub Desktop.
App.js file of localization porject
import React from 'react';
import './App.css';
import { useTranslation } from 'react-i18next';
function App() {
const { t, i18n } = useTranslation();
const handleClick = (lang) => {
i18n.changeLanguage(lang);
};
return (
<div className="App">
<nav
style={{ width: '100%', padding: '2rem 0', backgroundColor: 'grey' }}
>
<button onClick={() => handleClick('en')}>English</button>
<button onClick={() => handleClick('ur')}>Urdu</button>
</nav>
<h1>{t('Welcome to React js')}</h1>
<h1>
{t('Thanks.1')} {t('Why.1')}
</h1>
</div>
);
}
export default App;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment