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.
- Host: GitHub
- URL: https://github.com/artembatura/react-localization-experiment
- Owner: artembatura
- License: mit
- Created: 2018-12-15T15:16:03.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2023-01-06T13:26:08.000Z (over 3 years ago)
- Last Synced: 2025-12-28T21:58:25.934Z (6 months ago)
- Topics: i18n, localization, react, translation
- Language: JavaScript
- Homepage:
- Size: 979 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 12
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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)