2.0.0 • Published 4 years ago
tinytranslate v2.0.0
TinyTranslate
A tiny hook to manage translations in your React Application
Features
- Support for deeply nested objects. Eg:
translate('profile.top.heading') - 100% Test coverage
- Fully controlled and stateless
Install
yarn add tinytranslate
OR
npm i tinytranslate --saveUsage
- Define your translations
const translations = {
en: {
locale: 'en-US',
messages: {
hello: 'Hello {name}'
}
},
}- Add TranslationProvider to your app
import { TranslationProvider } from 'tinytranslate'
const App = () => {
return (
<TranslationProvider translations={translations} locale='en'>
<Header />
</TranslationProvider>
)
}- Use useTranslation hook
import { useTranslation } from 'tinytranslate'
const Header = () => {
const translate = useTranslation()
return <>{translate('hello'}</>
}