Package Exports
- translate-json-object
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (translate-json-object) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Translate a JSON Object
A Node.js module to translate a JSON object from a detectable language to any other language currently via google translate API | yandex translate
⍗ Install
npm i translate-json-objectExample
Setup:
// Require the module and instantiate instance
var TJO = require('translate-json-object')();
// Choose the service to use google/yandex, if you provide both yandex will be used as the default
TJO.init({
googleApiKey: 'api_key',
yandexApiKey: 'api_key'
});
// An example scenario (json) object
var srcObj = {
"name": "Please enter your name",
"list": ["translate", "object", "made", "easy"],
"nested": {
"hello": "hello",
"world": "world"
}
};
TJO.translate(srcObj, 'es').then(function(data) {
console.log(data);
// RESULT ->
// { name: 'por favor, escriba su nombre',
// list: [ 'traducir', 'objeto', 'hecho', 'fácil' ],
// nested: { hello: 'Hola', world: 'mundo' }
// }
}).catch(function(err) {
console.log('error ', err)
});
◉ API
var api = require('translate-json-object')();| api.init(setting)
Initialize the setting of your module instance, it takes a setting object
|| setting
| properties | Type | Description |
|---|---|---|
| googleApiKey | String |
Google translate api token key |
| api.translate(sourceObject, language)
Translate an object to any given language, it returns a promise with the translated data
| Parameters | Type | Description |
|---|---|---|
| sourceObject | Object |
The object to be translated |
| language | String |
The language code you wish to translate too e.g 'es', 'fr', 'ar' ... - see list |
What's next?
TODO
- [✅] Adding yandex service v2.1.0
- [❌] Adding bing service
- [❌] Unit test
- [✅] JS Linting
Reach out
Feel free to reach out with feedback via github: issue, feature, bug, or enhancement inputs are greatly appreciated
© MIT