1.0.1 • Published 7 years ago

choo-translate v1.0.1

Weekly downloads
-
License
MIT
Repository
-
Last release
7 years ago

choo-translate

npm standard

Simple translation solution for choo!

Expect your translations files to be available as /assets/${lang}.json (you could just use bankai then)

Usage

var choo = require('choo')

var app = choo()
app.use(log())
app.use(require('choo-translate')('fr'))
app.mount('body')
const assert = require('assert')

module.exports = translate

function translate (translations, opts) {
  const { term } = opts

  assert.equal(typeof translations, 'object', 'elements/translate: where are translations ?')
  assert.equal(typeof opts, 'object', 'elements/translate: opts should be type object')

  return translations[term] || ''
}

You can change langs by sending

...

state.lang = 'en'

emitter.emit('load:translations', 'en')

Then in your templates

html`${translate(state.translations, { term: 'CHOO_IS_FUN' })}`

License

MIT