Switch between different languages with this one trick (ahem, package).
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') //بابەت
- 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
Provide a term string, and optional language. Will default to previously provided default language.