# mil-i18next

> Javascript i18next mixin for webcomponents

Latest version **1.1.2** (published 2019-09-03) · 0 weekly downloads

## Install

```sh
npm install mil-i18next
pnpm add mil-i18next
yarn add mil-i18next
bun add mil-i18next
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.2 |
| Published | 2019-09-03 |
| First published | 2019-08-28 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 5 |
| Unpacked size | 43.5 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| Author | MIL Made In Lagny |
| Maintainers | made_in_lagny |
| Keywords | i18next, web-component, litElement, localisation |

## Links

- npm: https://www.npmjs.com/package/mil-i18next
- Repository: https://github.com/madeInLagny/mil-i18next
- Issues: https://github.com/madeInLagny/mil-i18next/issues
- npm.io page: https://npm.io/package/mil-i18next

## Dependencies (5)

- [i18next](https://npm.io/package/i18next.md) ^17.0.12
- [lit-element](https://npm.io/package/lit-element.md) ^2.2.1
- [@polymer/polymer](https://npm.io/package/@polymer/polymer.md) ^3.0.0
- [i18next-xhr-backend](https://npm.io/package/i18next-xhr-backend.md) ^3.1.2
- [i18next-browser-languagedetector](https://npm.io/package/i18next-browser-languagedetector.md) ^3.0.3

## Alternatives

- [messageformat](https://npm.io/package/messageformat.md) — 329.7K weekly downloads
- [@mintlify/scraping](https://npm.io/package/@mintlify/scraping.md) — 294.8K weekly downloads
- [@mintlify/previewing](https://npm.io/package/@mintlify/previewing.md) — 209.5K weekly downloads
- [@mintlify/prebuild](https://npm.io/package/@mintlify/prebuild.md) — 209.5K weekly downloads
- [@mintlify/link-rot](https://npm.io/package/@mintlify/link-rot.md) — 206.3K weekly downloads

## Recent versions

- 1.1.2 (latest) — 2019-09-03
- 1.1.1 — 2019-08-28
- 1.1.0 — 2019-08-28
- 1.0.2 — 2019-08-28
- 1.0.1 — 2019-08-28
- 1.0.0 — 2019-08-28

## README

# \<mil-i18next\>

'mil-i18next' is a javascript mixin that implements [i18next](https://www.i18next.com/) in webcomponents and litElements.
It provides translation upfront and lazy-loading and automatic language detection.

## Usage

### Install from npm

```sh
npm install --save mil-i18next
```

### Import to your webcomponent

```js
import { i18nMixin } from "mil-i18next";
```

### Extend your class

```js
class myClass extends i18nMixin(...)
```

### Optionally override default properties

```js
constructor() {
    super();
    this.i18NextNs = ["app", "common", "notification"];
    this.i18NextFilePath = '/path to translation files/{{lng}}/{{ns}}.json'
    this.i18NextFallbackLng = "fr";
    this.i18NextDefaultNS = ["app"];
    this.i18NextDebug = true;
    this.i18NextResources = {
      en: {
        app: {
          key1: "Translations keyed here will be loaded before i18next renders",
          key2: "Use language files for lazy-loading",
          }
      },
      fr: {
        app: {
          key1: "Les valeurs saisies ici seront chargées avant l'initialisation d'i18next",
          key2: "Les valeurs qui peuvent être chargées sans bloquer l'initialisation doivent être saisies dans les fichiers de traduction.",
         }
       }
    };
  }
```

Properties reflect [i18next configuration options]('https://www.i18next.com/overview/configuration-options')

| Property            | Type    | i18next Option      | Default                               |
| ------------------- | ------- | ------------------- | ------------------------------------- |
| `i18NextNs`                | Array   | `ns`                | ['app']                               |
| `i18NextFilePath` | String  | `languageResources` | '/assets/locales/{{lng}}/{{ns}}.json' |
| `i18NextFallbackLng`       | String  | `fallbackLng`       | 'en'                                  |
| `i18NextDefaultNS`         | String  | `defaultNS`         | ['app']                               |
| `i18NextDebug`             | Boolean | `debug`             | false                                  |
| `i18NextResources`  | Object  | `resources`         | {}                                    |

Translation file load is asynchronous. Any translations that can be lazy-loaded should be keyed in translation files. `this.i18NextFilePath` must be updated accordingly. To avoid unpleasant text flashing, all other translations should be keyed in `this.i18NextResources`

### Use in your element

```js
${this.i18n.t("app:key1")}
```

---
_Source: https://npm.io/package/mil-i18next · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
