slim-i18n
TypeScript icon, indicating that this package has built-in type declarations

1.1.0 • Public • Published

Slim React i18n

Slim wrapper for i18n in React with flexible utils which can be used with any i18n library.

Install

npm install slim-i18n
// or
yarn add slim-i18n
 

Usage

// init
import { TranslationsProvider } from 'slim-i18n';
import getTranslationAdapter from './get-translation-adapter';
import App from './app';
 
const i18n = getTranslationAdapter();
 
ReactDOM.render(
    <TranslationsProvider value={i18n}>
        <App />
    </TranslationsProvider>,
    document.getElementById('my-app')
);
// with hook
import { useI18n } from 'slim-i18n';
 
export default function App() {
    const i18n = useI18n();
 
    return (
        <div>{i18n.gettext('Hello World! I can be multi language!')}</div>
    );
}
// with HOC
import { withTranslations } from 'slim-i18n';
 
export default withTranslations(({ i18n }) => (
    <div>{i18n.gettext('Hello World! I can be multi language!')}</div>
));
// with Translation component
import { Translation } from 'slim-i18n';
 
export default function App() {
    return (
        <Translation>
            {({ i18n }) => (
                <div>{i18n.gettext('Hello World! I can be multi language!')}</div>
            )}
        </Translation>
    );
}

Readme

Keywords

none

Package Sidebar

Install

npm i slim-i18n

Weekly Downloads

0

Version

1.1.0

License

WTFPL

Unpacked Size

13.4 kB

Total Files

22

Last publish

Collaborators

  • iouser