Newsworthy Presidential Mistakes

npm

Don't miss out on this year's npm Pride t-shirt designs!Order your favorites here »

choo-translate

1.0.1 • Public • Published

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

install

npm i choo-translate

Downloadsweekly downloads

11

version

1.0.1

license

MIT

last publish

collaborators

  • avatar
Report a vulnerability