https://github.com/davidnguyen11/i18n-lite
https://github.com/davidnguyen11/i18n-lite
i18n lite typescript typescript-library
Last synced: 3 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/davidnguyen11/i18n-lite
- Owner: davidnguyen11
- Created: 2019-04-05T02:48:24.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2019-04-05T06:19:43.000Z (about 6 years ago)
- Last Synced: 2025-02-08T15:34:08.588Z (5 months ago)
- Topics: i18n, lite, typescript, typescript-library
- Language: TypeScript
- Size: 9.77 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# i18n lightweight
[](https://travis-ci.org/davidnguyen179/i18n-lite) [](https://codecov.io/gh/davidnguyen179/i18n-lite)
This component is the wrapped library of [intl-messageformat](https://github.com/yahoo/intl-messageformat).
## Usage
```bash
my-app
├── components/
└── abc/
└──locale/
└──locale.en.json
└──locale.vi.json
└──index.js
└──index.js
├── App.js
```Create json locale files
**components/abc/locale/locale.en.json**
```json
{
"greeting": "Hi {someone}. My name is {name}"
}
```**components/abc/locale/locale.vi.json**
```json
{
"greeting": "Chào {someone}. Tên mình là {name}"
}
```**components/abc/locale/index.js**
```ts
import { getI18n } from 'i18n-lite';export const i18n = getI18n({
messages: locale => require(`./locale.${locale}.json`)
});
```**components/abc/index.js**
```js
import { i18n } from './locale';const { greeting } = i18n.messages();
const content = greeting({ someone: 'John', name: 'David' });// Vietnamese: Chào John. Tên mình là David
// English: Hi John. My name is David
```**my-app/App.js**
```js
import { setGlobalLocale } from 'i18n-lite';setGlobalLocale({ locale: 'vi' });
```