translation-picker
switch between different translations of a term
Last updated 4 years ago by lrlna .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install translation-picker 
SYNC missed versions from official npm registry.

translation-picker

Switch between different languages with this one trick (ahem, package).

Usage

The easiest way to handle multiple languages is to store various translations in a file, something like this:

{
  "ar": {
    "language": "العربية",
    "subject": "الموضوع"
  },
  "fa": {
    "language": "فارسی",
    "subject": "موضوع"
  },
  "ku": {
    "language": "کوردی",
    "subject": "بابەت"
  }
}

That you can then use with translation-picker:

var translationPicker = require('translation-picker')
var path = require('path')
var fs = require('fs')

var file = fs.readFileSync(path.join(__dirname, './path/to/json/file'))
var translate = translationPicker({
  translations: file,
  default: 'ar'
})

translate('subject', 'ku') //بابەت

var translate = translationPicker(opts)

  • opts.translations: takes in a buffer, or an object
  • opts.default: have a language you want to default if no language is provided in translate.pick

translate.pick(term, [lang])

Provide a term string, and optional language. Will default to previously provided default language.

License

MIT

Current Tags

  • 1.0.2                                ...           latest (4 years ago)

3 Versions

  • 1.0.2                                ...           4 years ago
  • 1.0.1                                ...           4 years ago
  • 1.0.0                                ...           4 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 3
Dependencies (4)
Dev Dependencies (1)
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |