Ecosyste.ms: Awesome

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

Awesome Lists | Featured Topics | Projects

https://github.com/widen/i18next-async-backend

i18next backend which loads resources via promises. Useful when loading resources via dynamic imports.
https://github.com/widen/i18next-async-backend

dynamic-import frontend i18next i18next-backend i18next-plugin

Last synced: about 5 hours ago
JSON representation

i18next backend which loads resources via promises. Useful when loading resources via dynamic imports.

Awesome Lists containing this project

README

        

# i18next-async-backend

[![Build](https://github.com/Widen/i18next-async-backend/actions/workflows/build.yml/badge.svg)](https://github.com/Widen/i18next-async-backend/actions/workflows/build.yml)
[![npm](https://img.shields.io/npm/v/i18next-async-backend)](https://www.npmjs.com/package/i18next-async-backend)
[![changesets](https://img.shields.io/badge/maintained%20with-changesets-blue)](https://github.com/atlassian/changesets)

[i18next](https://www.i18next.com) backend which loads resources via promises.
Useful when loading resources via dynamic imports.

## Installation

### npm

```sh
npm install i18next-async-backend
```

### Yarn

```
yarn add i18next-async-backend
```

## Usage

```js
import i18next from 'i18next'
import AsyncBackend from 'i18next-async-backend'

const resources = {
es: () => import('./locales/es/translation.json'),
}

i18next.use(AsyncBackend).init({
backend: { resources },
})
```

## Recipes

### Single namespace

```js
const resources = {
en: () => import('./locales/en/translation.json'),
es: () => import('./locales/es/translation.json'),
}
```

### Multiple namespaces

```js
const resources = {
en: {
common: () => import('./locales/en/common.json'),
glossary: () => import('./locales/en/glossary.json'),
},
es: {
common: () => import('./locales/es/common.json'),
glossary: () => import('./locales/es/glossary.json'),
},
}
```