# i18n-helper

> i18n helper

Latest version **1.2.0** (published 2016-01-15) · ISC license · 0 weekly downloads

## Install

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

## 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.2.0 |
| Published | 2016-01-15 |
| First published | 2015-09-18 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 6 |
| Author | gbk |
| Maintainers | gbk |
| Keywords | i18n, helper |

## Links

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

## Alternatives

- [lodash.assign](https://npm.io/package/lodash.assign.md) — 2.3M weekly downloads
- [lodash.chunk](https://npm.io/package/lodash.chunk.md) — 1.8M weekly downloads
- [react-native-ios-utilities](https://npm.io/package/react-native-ios-utilities.md) — 138.5K weekly downloads
- [@technically/lodash](https://npm.io/package/@technically/lodash.md) — 50.9K weekly downloads
- [@fluid-topics/ft-icon](https://npm.io/package/@fluid-topics/ft-icon.md) — 20.6K weekly downloads

## Recent versions

- 1.2.0 (latest) — 2016-01-15
- 1.1.1 — 2015-09-21
- 1.1.0 — 2015-09-21
- 1.0.1 — 2015-09-18

## README

# i18n-helper

[![npm version](https://badge.fury.io/js/i18n-helper.svg)](http://badge.fury.io/js/i18n-helper)

---

I18n helper for node, you can use it as a helper in jsx , handlebars , ejs or any other template engines .

## Install

```shell
npm install i18n-helper --save
```

## Usage

```js
var locale = 'en';
var langs = {
    en: {
        'greetings': 'Hello {1} !'
    },
    zh: {
        'greetings': '你好 {1}！'
    }
};

var i18n = require('i18n-helper')(langs[locale]);

console.log(i18n('greetings', 'Jack')); // => 'Hello Jack !'
```

### Init

`i18n-helper` exports a generator which returns an i18n helper.

You can pass multiply resources into this generator,
the resources will be merged to one from right to left.

```js
// global resource and module resource
var globalLangs = require('../i18n/en');
var moduleLangs = require('./i18n/en');

// the i18n helper generator
var i18nHelperGenerator = require('i18n-helper');

// create an i18n helper with the giving resources
var i18nHelper = i18nHelperGenerator(globalLangs, moduleLangs);
```

### Find Key

The helper will try to find the matched key from the merged resource,
if not found, the key itself is returned.

```js
var i18n = i18nHelper({ key1: 'hello', key2: 'world' });

console.log(i18n('key'));
// => 'key'
```

You can override `i18n.keyNotFound` to apply your customized `key not found` handler ( >= 1.1.0 ).

```js
var i18n = i18nHelper({ key1: 'hello', key2: 'world' });

i18n.keyNotFound = function(key) {
    return key + ' is not found';
};

console.log(i18n('key'));
// => 'key is not found'
```

### Template

If the value to the key is a template ( with a string like `{1}` ),
then the arguments will be substituted into the template.

```js
var i18n = i18nHelper({ greetings: 'Hello {1} ! Welcome to {2} .' });

console.log(i18n('greetings', 'Jack', 'China'));
// => 'Hello Jack ! Welcome to China .'
```

## Change Log

### 1.2.0

- support templating key #1.

### 1.1.0

- add `keyNotFound` handler.

## Links

- [Bug Report](https://github.com/gbk/i18n-helper/issues)

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