hyperapp-i18n

0.0.2 • Public • Published

hyperapp-i18n

Travis CI Codecov npm Slack

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

Readme

Keywords

Package Sidebar

Install

npm i hyperapp-i18n

Weekly Downloads

1

Version

0.0.2

License

MIT

Unpacked Size

7.85 kB

Total Files

6

Last publish

Collaborators

  • willin