Ecosyste.ms: Awesome

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

Awesome Lists | Featured Topics | Projects

https://github.com/zamarawka/i18n-lite

Modular, zero dependencies, tiny toolkit for i18n in react based apps.
https://github.com/zamarawka/i18n-lite

i18n react typescript

Last synced: about 18 hours ago
JSON representation

Modular, zero dependencies, tiny toolkit for i18n in react based apps.

Awesome Lists containing this project

README

        

[![Ci Status](https://github.com/zamarawka/i18n-lite/workflows/CI/badge.svg)](https://github.com/zamarawka/i18n-lite/actions)
[![Npm version](https://img.shields.io/npm/v/i18n-lite.svg?style=flat&logo=npm)](https://www.npmjs.com/package/i18n-lite)
[![React version](https://img.shields.io/npm/dependency-version/i18n-lite/peer/react.svg?style=flat&logo=react)](https://reactjs.org/)

# i18n-lite

Modular, zero dependencies, tiny toolkit for i18n in react based apps. Inspired by i18next api. Focused on reduce bundle size.

Package includes its TypeScript Definitions

# Install

```sh
npm install i18n-lite
```

# Usage

```tsx
// ./src/App.tsx
import I18n, { getLangDetector, Provider as I18nProvider } from 'i18n-lite';

import SomeComponentWithTranslation './SomeComponentWithTranslation';

const { detectLang, langHandler } = getLangDetector();

const en = {
some: 'some strings {{param}}',
richTextString: 'lorem ipsum {{param}}',
// ...
};

// Create I18n instance
const i18n = new I18n({
lang: detectLang(),
fallbackLng: 'en',
resource: {
en,
},
});

i18n.on('langChange', langHandler);

function App() {
return (



);
}

export default App;
```

```tsx
// ./src/SomeComponentWithTranslation.tsx
import { useTranslation, Trans } from 'i18n-lite';

export default function SomeComponentWithTranslation() {
// Simple way to translate strings with values interpolation
const { t } = useTranslation();

return (


{t('some', { param: 'here' })}

{/* Way to interpolate components and values */}
,
b: ,
}}
values={{
param: 'bar',
}}
/>


);
}
```

# Development

```sh
npm run format # code fomatting
npm run lint # linting
npm run test # testing
```

Active maintenance with care and ❤️.

Feel free to send a PR.