0.2.2 ā¢ Published 4 years ago
i18n-butler v0.2.2
I18n Butler
I18n simple and convenient with React and Redux
- šØāš» Provide I18n as JSON
- š Use I18n as React Hook
- š„³ Works wherever Redux works (yes, also with React and React Native)
- š„³ No dependencies
- š§ Tool for Excel2JSON conversion and reverse
Getting Started
Install I18n Butler
$ yarn add i18n-butler
# or
$ npm install i18n-butler
Usage
I18n Butler offers one method only, which creates a React Hook.
I18n
šØ I18n presumes you provide a reducer that is accessible via state.i18n
and provides the current language, e.g. { lang: 'en' }
. You might detect this dynamically by using Redux Saga. Now create the Hook.
// useTranslation.js
import I18n from 'i18n-butler'
const i18n = {
helloWorld: {
translation: {
en: 'Hello World',
de: 'Hallo Welt'
},
context: 'app', // For custom group / filter / sort
group: 'common' // For custom group / filter / sort
}
}
export const { useTranslation } = I18n({
i18n,
fallback: 'en',
state: state => state.i18n
});
Use the hook in any component.
import { useTranslation } from "../hooks/useTranslation";
const Home = () => {
const { i18n, t } = useTranslation();
return <div>{t(i18n.helloWorld)}</div>;
};
export default Home;
XLSX
Use this command to convert from Excel to JSON. Script is constantly watching your XLSX š, write I18n in Excel, see result instantly in your App.
$ yarn xlsx -t json -i ./examples/i18n.xlsx -o ./examples/i18n.json
Use this command to convert from JSON to Excel.
$ yarn xlsx -t xlsx -i ./examples/i18n.json -o ./examples/i18n.xlsx