1.0.2 • Published 3 years ago

@rogal/react-translate v1.0.2

Weekly downloads
43
License
MIT
Repository
-
Last release
3 years ago

React-Translate NPM Version NPM Downloads Actions Status Coverage Status

Easier i18n to be happier

react-translate can prevent you going crazy about react interpolation

Install

npm install @rogal/react-translate --save

Getting Started

import React from 'react'
import {
  TranslateProvider,
  useTranslate,
} from '@rogal/react-translate';

const Childen = () => {
  const {t} = useTranslate();
  return <p>{t('common:helloWorld')}</p>
}
const App = () => {
  const providerValue = {
    fallbackLng: 'en',
    languages: ['en', 'es'],
    translations: {
      en: {
        common: {
          helloWorld: 'Hello world'
        },
      },
      es: {
        common: {
          helloWorld: 'Hola Mundo'
        },
      }
    }
  };
  return (
    <TranslateProvider value={providerValue}>
      <Children />
    </TranslateProvider>
  )
}

How to instance a i18nConfiguration so you can use it outside of react

You only need to import the i18nConfiguration and passed the next config

import {i18nConfiguration} from '@rogal/react-translate';
import commonES from 'locales/es/common';
import commonEN from 'locales/en/common';

const i18next = i18nConfiguration({
  languages: ['es', 'en'],
    translations: {
      es: {
        common: commonES
      },
      en: {
        common: commonEN
      }
    },
    fallbackLng: 'en',
    language: 'en'
});

const translation = i18next.t('helloWorld');

More examples

You can check the demo folder or run the storybook so you can see advanced used cases

Components

  • A TranslateProvider to pass configuration data to the context.
  • useTranslate hook to use the t function in your code and translate jsonKeys to strings
  • withTranslate HOC to support class components
  • A Trans component to have a fallback when translating

Features

  • i18n languages supported such as English or Spanish.
  • Easy to use for dev experience
  • Works with SSR

How to contribute

You can install and have an enviroment ready for use with Storybook

  npm i
  npm start

License

MIT

1.0.2

3 years ago

1.0.1

4 years ago

1.0.0

4 years ago

1.0.0-beta.18

4 years ago

1.0.0-beta.17

4 years ago

1.0.0-beta.16

4 years ago

1.0.0-beta.15

4 years ago

1.0.0-beta.14

4 years ago

1.0.0-beta.13

4 years ago

1.0.0-beta.12

4 years ago

1.0.0-beta.11

4 years ago

1.0.0-beta.10

4 years ago

1.0.0-beta.8

4 years ago

1.0.0-beta.9

4 years ago

1.0.0-beta.7

4 years ago

1.0.0-beta.6

4 years ago

1.0.0-beta.5

4 years ago

1.0.0-beta.4

4 years ago

1.0.0-beta.3

4 years ago

1.0.0-beta.2

4 years ago

1.0.0-beta.1

4 years ago

1.0.0-beta.0

4 years ago