An open API service indexing awesome lists of open source software.

https://github.com/significa/significa-react-i18n

Simple i18n library for React
https://github.com/significa/significa-react-i18n

Last synced: 10 months ago
JSON representation

Simple i18n library for React

Awesome Lists containing this project

README

          

logo

[![React][React.js]][React-url]

A Zero dependency opinionated Significa's i18n package for React.

Table of Contents


  1. Usage

  2. Messages object

  3. Message parameters

  4. License

## Usage

Include the provider on the top level of your app.

Pass the messages object based on the current language selected on your app.

```js
import { I18nProvider } from '@significa/react-i18n'

```

You can either use the `useTranslation` helper or the `Translation` component

```js
import { useTranslation } from '@significa/react-i18n'

const YourComponent = () => {
const { t } = useTranslation()

return (


{t('yourMessage')}



)
}
```

```js
import { Translation } from '@significa/react-i18n'

const YourComponent = () => {
return (




)
}
```

## Messages object

Your messages object should be according to the following example.

```
{
id: message,
anotherId: anotherMessage
}
```

## Message parameters

It's possible to add parameters to the message, a string between double curlybraces is represented as a parameter.

```js
// Messages Object
{
greet: "Hello {{name}}"
}
```

```js

OR


{t('greet', { name: user.name })}


```

## License

[MIT](https://github.com/Significa/significa-start/blob/master/LICENSE)

[![Significa footer](https://user-images.githubusercontent.com/17513388/71971185-fc736b00-3201-11ea-9678-090b6b6a0b3f.png)](https://significa.co)

[React.js]: https://img.shields.io/badge/React-20232A?style=for-the-badge&logo=react&logoColor=61DAFB
[React-url]: https://reactjs.org/