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

https://github.com/artembatura/react-localization-experiment

Just example how localization can be implemented as alternative to typical Intl.
https://github.com/artembatura/react-localization-experiment

i18n localization react translation

Last synced: 5 months ago
JSON representation

Just example how localization can be implemented as alternative to typical Intl.

Awesome Lists containing this project

README

          

# react-localization-experiment

Just example how localization can be implemented in other way in React as alternative to key-value based Intl.

```jsx harmony
import React from 'react';

import { addDictionary, LocaleProvider, L } from 'react-localization-experiment';

addDictionary([
{
en: "hello",
ru: "привет"
},
{
en: "world",
ru: "мир"
}
]);

const App = () => (


Hello, world!
{/* Привет, мир! */}

Привет, мир!
{/* Hello, world! */}



);
```

[CodeSandbox](https://codesandbox.io/s/w7pmpzzpy5)

## Installation

### npm

```
npm i react-localization-experiment
```

### Yarn

```
yarn add react-localization-experiment
```

## API

```typescript
declare function addDictionary(
translations: Array<{ [lang: string]: string }>
): void;

declare function translate(
text: string,
fromLang: string,
toLang: string
): string;

declare const LocaleProvider: React.FC<{
srcLocale: string;
locale: string;
children?: any[];
}>;

declare const L: React.FC<{
children: string;
from: string;
to: string;
}>;
```

### License

`react-localization-experiment` is [MIT licensed](./LICENSE)