hyperapp-i18n
v0.0.2
Published
[![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) [![
Downloads
6
Readme
hyperapp-i18n
I18n Plugin for 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 and it will be globally available through the window.i18n object. If your library is a high-order-app, export it as window.i18n.
<script src="https://unpkg.com/hyperapp-i18n"></script>
Usage
// 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 } }) => (
<div>
<h2>Current Lang: {locale}</h2>
<p>Test1: {messages.hello}</p>
</div>
);
const main = app(state, actions, view, document.body);
main.i18n.set('en-US');
See the Example folder for more detailed useage info.
LICENSE
MIT