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

https://github.com/gpmcadam/eighteen

Simple i18n library for React
https://github.com/gpmcadam/eighteen

internationalisation internationalization javascript nodejs react reactjs translation

Last synced: 4 months ago
JSON representation

Simple i18n library for React

Awesome Lists containing this project

README

          

# Eighteen

A simple, elegant, i18n library for ReactJS.

## Principles

Eighteen is written to get out of your way, make internationalisation of your
React apps easy, and keep your code readable.

It's light, and has no dependencies.

## Get Started

Install Eighteen:

`npm install --save eighteen`

Configure:

```
import Eighteen from 'eighteen';

Eighteen.configure({
locales: {
'fr-FR': {
'Hello': 'Bonjour'
}
}
});
```

Use:

```
import { Text } from 'eighteen';

class MyComponent extends Component {
render() {
return (
Hello
);
// Renders:
// Bonjour
}
}
```

## Configuration

`Eighteen.configure` takes the following options.

### `locales` (Object)

An object, where each key is the locale identifier (e.g. `en-GB`) and the values are a key-value list of translations.

Translations are keyed by the default translation, and the value is the locale-specific translation. For example, if your default translation is `en-GB`, your `fr-FR` configuration might look like this:

```
locales: {
'fr-FR': {
'Hello': 'Bonjour'
}
}
```

### `defaultLocale` (string)

The default locale key to use when a `locale` prop is not passed to the `Test` component.

## Advanced Formatting

You can provided advanced formatting for your translations by providing an `args` which replaces the format indicators in the order they are given.

```
You have %s new message(s)
// You have 1 new message(s)
```