@js-pack/i18n-react
v1.1.0
Published
easy-to-use translation library
Downloads
3
Maintainers
Readme
@js-pack/i18n-react
react wrapper of @js-pack/i18n
Install
npm i @js-pack/i18n-react
Usage
App.js
import { I18nProvider } from '@js-pack/i18n-react';
const supportedLocales = ['tr-TR', 'en-US'];
const App = () => {
const [locale, setLocale] = useState();
const [resourceMap, setResourceMap] = useState();
useEffect(() => {
setResourceMap({
'en-US': {
'Selam!': 'Hello!',
},
});
}, []);
return (
<I18nProvider
supportedLocales={supportedLocales}
locale={locale}
defaultLocale="tr-TR"
resourceMap={resourceMap}
onLoad={(loadedLocale) => {
setLocale(loadedLocale);
}}>
{/* ... App */}
</I18nProvider>
);
};
Page.js
import { useTranslation } from '@js-pack/i18n-react';
const PageComponent = ()=>{
const { t } = useTranslation();
return <div>{t('Selam!')}</div>
}