Ecosyste.ms: Awesome

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

Awesome Lists | Featured Topics | Projects

https://github.com/willin/hyperapp-i18n

I18n Plugin for Hyperapp
https://github.com/willin/hyperapp-i18n

hyperapp i18n

Last synced: 27 days ago
JSON representation

I18n Plugin for Hyperapp

Awesome Lists containing this project

README

        

# hyperapp-i18n

[![Travis CI](https://img.shields.io/travis/willin/hyperapp-i18n/master.svg)](https://travis-ci.org/willin/hyperapp-i18n) [![Codecov](https://img.shields.io/codecov/c/github/willin/hyperapp-i18n/master.svg)](https://codecov.io/gh/willin/hyperapp-i18n) [![npm](https://img.shields.io/npm/v/hyperapp-i18n.svg)](https://www.npmjs.org/package/hyperapp-i18n) [![Slack](https://hyperappjs.herokuapp.com/badge.svg)](https://hyperappjs.herokuapp.com "Join us")

I18n Plugin for [Hyperapp](https://github.com/hyperapp/hyperapp).

## Installation

Install with npm or Yarn.

```
npm i hyperapp-i18n
```

If you don't want to set up a build environment, you can download Hyperapp I18n from a CDN like [unpkg.com](https://unpkg.com/hyperapp-i18n) and it will be globally available through the window.i18n object. If your library is a high-order-app, export it as window.i18n.

```html

```

## Usage

```js
// i18n.js
import i18n from 'hyperapp-i18n';

export const { state, actions } = i18n({
'zh-CN': {
hello: '你好'
},
'en-US': {
hello: 'Hello'
}
}, 'zh-CN');

// app.js
import { app, h } from 'hyperapp';
import * as i18n from './i18n';

const state = {
i18n: i18n.state
};
const actions = {
i18n: i18n.actions
};

const view = ({ i18n: { messages, locale } }) => (


Current Lang: {locale}


Test1: {messages.hello}



);

const main = app(state, actions, view, document.body);
main.i18n.set('en-US');
```

See the Example folder for more detailed useage info.

## LICENSE

MIT