Ecosyste.ms: Awesome

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

Awesome Lists | Featured Topics | Projects

https://github.com/dmtrkovalenko/ns-react-18next

[Unmaintained] Namespaced i18next localization in react with no tears
https://github.com/dmtrkovalenko/ns-react-18next

context i18n i18next localization localized react typescript

Last synced: 6 days ago
JSON representation

[Unmaintained] Namespaced i18next localization in react with no tears

Awesome Lists containing this project

README

        

# NS react-i18next
[![npm package](https://img.shields.io/npm/v/ns-react-i18next.svg)](https://www.npmjs.org/package/ns-react-i18next)
[![gzip bundle size](http://img.badgesize.io/https://unpkg.com/[email protected]/index.amd.js?compression=gzip
)](https://unpkg.com/[email protected]/index.amd.js)
[![codecov](https://codecov.io/gh/dmtrKovalenko/ns-react-18next/branch/master/graph/badge.svg)](https://codecov.io/gh/dmtrKovalenko/ns-react-18next)
[![Build Status](https://travis-ci.org/dmtrKovalenko/ns-react-18next.svg?branch=master)](https://travis-ci.org/dmtrKovalenko/ns-react-18next)
> Manage i18next namespaces with a power of react v16 context

## Unmaintained

The purpose of this library was merged to official [react-i18next](https://github.com/i18next/react-i18next) at v9. So please use it. :)

### Installation
Available as npm package.
```sh
npm install ns-react-i18next
```

Add global provider to the root of your app

```jsx
import * as i18n from 'i18next';
import { I18NextProvider } from 'ns-react-i18next'

i18n
.use(LanguageDetector)
.init({
resources: translations,
fallbackLng: 'en',
debug: true,
defaultNS: 'common', // this namespace will be used if no namespace shared via context
fallbackNS: 'common',
});

ReactDom.render(


,
document.getElementById('root')
)
```

### Usage
Use another provider to share namespace between components sub-tree. Any `` component under this provider will render translated string of shared namespace + children string. Note that when the language will be changed (with a help of `i18n.changeLanguage()`) - every translate will rerender by itself.

```jsx
import { Translate, NamespaceProvider } from 'ns-react-i18next'

// specificNs:some_complex_structure

some_complex_structure


something_specific

// specificNs:something_specific

```

Even possible to share namespace for several routes.

```jsx


```

There any `Translate` of CustomersList, ManageCustomer and thiers sub-components and sub-routes of take the 'customers' namespace.