# hexo-i18n

> i18n module for Hexo.

Latest version **2.0.0** (published 2022-11-08) · MIT license · 0 weekly downloads

## Install

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

## Health

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

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.0 |
| Published | 2022-11-08 |
| First published | 2015-01-08 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | >=14 |
| Dependencies | 1 |
| Unpacked size | 10.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 16 |
| Author | Tommy Chen |
| Maintainers | ertrzyiks, abnerchou, tommy351, hexobot, jlhwung, tomap, curben, yoshinorin |
| Keywords | hexo, i18n, localization |

## Links

- npm: https://www.npmjs.com/package/hexo-i18n
- Repository: https://github.com/hexojs/hexo-i18n
- Homepage: https://hexo.io/
- Issues: https://github.com/hexojs/hexo-i18n/issues
- npm.io page: https://npm.io/package/hexo-i18n

## Dependencies (1)

- [sprintf-js](https://npm.io/package/sprintf-js.md) ^1.1.2

## Alternatives

- [postcss-color-hex-alpha](https://npm.io/package/postcss-color-hex-alpha.md) — 6.4M weekly downloads
- [randomcolor](https://npm.io/package/randomcolor.md) — 348.0K weekly downloads
- [bows](https://npm.io/package/bows.md) — 1.3K weekly downloads
- [ep_prefer_color_scheme](https://npm.io/package/ep_prefer_color_scheme.md) — 260 weekly downloads
- [coc-yank](https://npm.io/package/coc-yank.md) — 61 weekly downloads

## Recent versions

- 2.0.0 (latest) — 2022-11-08
- 1.0.0 — 2019-09-01
- 0.2.1 — 2015-02-11
- 0.2.0 — 2015-01-18
- 0.1.0 — 2015-01-09
- 0.0.1 — 2015-01-08

## README

# hexo-i18n

[![Build Status](https://github.com/hexojs/hexo-i18n/workflows/Tester/badge.svg)](https://github.com/hexojs/hexo-i18n/actions?query=workflow%3ATester)
[![NPM version](https://badge.fury.io/js/hexo-i18n.svg)](https://www.npmjs.com/package/hexo-i18n)
[![Coverage Status](https://img.shields.io/coveralls/hexojs/hexo-i18n.svg)](https://coveralls.io/r/hexojs/hexo-i18n?branch=master)

i18n module for [Hexo].

## Installation

``` bash
$ npm install hexo-i18n --save
```

## Usage

### Example

``` js
var i18n = new require('hexo-i18n')({
  languages: ['zh-TW', 'en']
});

i18n.set('en', {
  ok: 'OK',
  name: 'My name is %1$s %2$s.',
  index: {
    title: 'Home'
  },
  video: {
    zero: 'No videos',
    one: 'A video',
    other: '%d videos'
  }
});

i18n.set('zh-TW', {
  name: '我的名字是 %2$s %1$s。',
  index: {
    title: '首頁'
  },
  video: {
    zero: '沒有影片',
    one: '一部影片',
    other: '%d 部影片'
  }
});

var __ = i18n.__();
var _p = i18n._p();

__('ok') // OK
__('index.title') // 首頁
__('name', '大呆', '王') // 我的名字是王大呆
_p('video', 0) // 沒有影片
_p('video', 1) // 一部影片
_p('video', 10) // 10 部影片
```

### new i18n([options])

Creates a new i18n instance.

Option | Description | Default
--- | --- | ---
`languages` | Default languages. It can be an array or a string | `default`

### i18n.get([lang]) → Object

Returns a set of localization data. `lang` can be an array or a string, or the default language defined in constructor if not set. This method will build the data in order of languages.

### i18n.set(lang, data)

Loads localization data.

### i18n.remove(lang)

Unloads localization data.

### i18n.list()

Lists loaded languages.

### i18n.__() → Function(key, arg...)

Returns a function for localization.

### i18n._p() → Function(key, count, ...)

This method is similar to `i18n.__`, but it returns pluralized string based on the second parameter. For example:

``` js
_p('video', 0) = __('video.zero', 0)
_p('video', 1) = __('video.one', 1)
_p('video', 10) = __('video.other', 10)
```

## License

MIT

[Hexo]: https://hexo.io/

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