Last active
August 12, 2020 18:42
-
-
Save ljmotta/4a3533c1907593ea0046222c577ca77b to your computer and use it in GitHub Desktop.
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
function MyComponent() { | |
const { locale, setLocale, i18n } = useContext(myI18nCtx); | |
const [name, setName] = useState(""); | |
return ( | |
<div> | |
<p>{i18n.home.title} :)</p> | |
<p>{i18n.home.body}</p> | |
<input type={"text"} value={name} onChange={e => setName(e.target.value)} /> | |
{/* a couple of <br /> tags, just to give a better look to the example. */} | |
<br /> | |
{/* `welcome` will always fallback on the 'en' dictionary because the ‘pt’ dictionary doesn't provide it. */} | |
<I18nHtml>{i18n.welcome(name)}</I18nHtml> | |
<br /> | |
<a onClick={() => setLocale("pt")}>pt</a> | |
<br /> | |
<a onClick={() => setLocale("en")}>en</a> | |
<p>{i18n.myCurrentLocale(locale)}</p> | |
</div> | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment