All Projects → lrlna → translation-picker

lrlna / translation-picker

Licence: MIT license
switch between different translations of a term 🅰️ 🅱️

Programming Languages

javascript
184084 projects - #8 most used programming language

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

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].