# svjs-i18n

> Simple internationalisation and translation as es6 module

Latest version **1.1.2** (published 2018-08-10) · MIT license · 0 weekly downloads

## Install

```sh
npm install svjs-i18n
pnpm add svjs-i18n
yarn add svjs-i18n
bun add svjs-i18n
```

## 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 | 2018-08-10 |
| First published | 2018-06-26 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 9.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | https://shaack.com |
| Maintainers | shaack |
| Keywords | es6, svjs |

## Links

- npm: https://www.npmjs.com/package/svjs-i18n
- Repository: https://github.com/shaack/svjs-i18n
- Homepage: https://github.com/shaack/svjs-i18n#readme
- Issues: https://github.com/shaack/svjs-i18n/issues
- npm.io page: https://npm.io/package/svjs-i18n

## Recent versions

- 1.1.2 (latest) — 2018-08-10
- 1.1.1 — 2018-07-09
- 1.1.0 — 2018-07-09
- 1.0.5 — 2018-06-26
- 1.0.3 — 2018-06-26
- 1.0.2 — 2018-06-26
- 1.0.1 — 2018-06-26
- 1.0.0 — 2018-06-26

## README

# svjs-i18n

A simple ES6 module to support internationalisation
of JavaScript UIs. 

## Usage example
```javascript
const i18n = new I18n({locale: "de"})
i18n.load({
    de: {
        "myname": "Mein Name ist $2, $1 $2"
    },
    en: {
        "myname": "My name is $2, $1 $2"
    }
})
const translation = i18n.t("myname", "James", "Bond")
Test.assertEquals("Mein Name ist Bond, James Bond", translation)    
```
You can set the locale via configuration
```javascript
const i18n = new I18n({locale: "de"})
```
In case the locale option is not given, the language attribute 
given for the html tag will be used:
```html
<html lang="de">
```
If that `lang` attribute is also missing, 
it will try to use the locale specified by the browser.

## Load language file
You can load the dictionary from external json files:
```javascript
const i18n = new I18n("de")
i18n.load({
    de: "translations-de.json",
    en: "translations-en.json"
}).then(() => {
    Test.assertEquals("Haus", i18n.t("house"))
    Test.assertEquals("Hallo", i18n.t("hello"))
    i18n.locale = "en"
    Test.assertEquals("House", i18n.t("house"))
    Test.assertEquals("Hello", i18n.t("hello"))
})
```

## Add multiple dictionaries
You can add multiple dictionaries. All dictionaries are added. 
Same keys will be overwritten. 
```javascript
i18n.load({
    de: "translations-de.json"
}.then(() => {
    i18n.load({
        de: {
            "house": "Haus"
        }
    })
    i18n.load({
        en: {
            "house": "House"
        }
    })
    i18n.load({
        en: {
            "house": "My House"
        }
    })
    Test.assertEquals("My House", i18n.t("house"))
}))
```

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