Code Monkey home page Code Monkey logo

translate-json-object's People

Contributors

dependabot[bot] avatar duongtungls avatar karenpommeroy avatar khaledmohamedp avatar lovell avatar robertsasak avatar whyboris avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

translate-json-object's Issues

Service failed

I am trying to use your module with the example you have. I have created and specified my Google Cloud Translation API key, but am receiving the error "Service failed".

// 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: 'AIzaSyD42ymVCzU0iQZ8O3ENgEsZ-VS4PrF_zu8'
});

// An example scenario (json) object 
var example = {
    "name": "Please enter your name",
    "list": ["translate", "object", "made", "easy"],
    "nested": {
        "hello": "hello",
        "world": "world"
    }
};

// Translate method takes (source object, and language code) 
TJO.translate(example, 'es')
    .then(function (data) {
        console.log(data);
    }).catch(function (err) {
        console.log('error ', err)
    });

image

No error message with an invalid out language

When a non existent language is used, there is no error message:

TJO.translate(example, 'ch')
    .then(function(data) {
      console.log(data);
    }).catch(function(err) {
      console.log('error ', err)
    });

Instead of that there is a error message in the console and the node closes:

/test/expressjs/node_modules/translate-json-object/lib/service/yandex.js:29
				var result = res.text[0].split(hashSimple);
				                     ^

TypeError: Cannot read property '0' of undefined
    at /test/expressjs/node_modules/translate-json-object/lib/service/yandex.js:29:26
    at Request.handler [as _callback] (/test/expressjs/node_modules/yandex-translate/index.js:14:5)
    at Request.self.callback (/test/expressjs/node_modules/yandex-translate/node_modules/request/request.js:199:22)
    at emitTwo (events.js:106:13)
    at Request.emit (events.js:194:7)
    at Request.<anonymous> (/test/expressjs/node_modules/yandex-translate/node_modules/request/request.js:1036:10)
    at emitOne (events.js:101:20)
    at Request.emit (events.js:191:7)
    at IncomingMessage.<anonymous> (/test/expressjs/node_modules/yandex-translate/node_modules/request/request.js:963:12)
    at emitNone (events.js:91:20)

BTW: The lib save me a ton of work ;)

Yandex - issues with text containing '/'

Because hashSimple contains '/' character result text from yandex can sometimes be incorrectly converted to array (as string from yandex also may contain '/')

This results in some keys missing in resulting json object.

Specify values to omit

I think it would be great if you could add an array of variable names that this should omit and let with the existing language, Ex: i have a JSON and the first few variables are things i will always need in english,

node server is hanged

Hello,

I ran translate API background process, which means I sent a response to the user then I triggered a translate function.

If I make a new API call the server not responding.

`router.post('/translateSpainsh', function (req, res) {
var survey_structure = req.body.survey_structure;
var survey_id = req.body.survey_id;
var dataStruc ={
survey_structure:survey_structure
}
transalteSurvey(dataStruc,survey_id);

});

function transalteSurvey(dataItem,surveyId)
{
var sync = true;
TJO.init({
googleApiKey: 'test_key'
});
var surveyObj = JSON.parse(dataItem.survey_structure);
TJO.translate(surveyObj, 'es')
.then(function (data) {
var surveyData = {
survey_structure_es:JSON.stringify(data),
translate_status:1
}
var sql = "UPDATE survey SET ? WHERE id = " + surveyId;
connection.query(sql, [surveyData], function (err, results) {
if (err) { console.log(err); }
});
// sync = false;
}).catch(function (err) {
console.log('error ', err)
var surveyData = {
translate_status:0
}
var sql = "UPDATE survey SET ? WHERE id = " + surveyId;
connection.query(sql, [surveyData], function (err, results) {
if (err) { console.log(err); }
else {
console.log(' some Network error');
}
});
});
}`

Thanks in advance!

Security report

Hi,

If i run npm auditi get a series of security issues connected with your dependencies, would you mind update your dependencies?

┌──────────────────────────────────────────────────────────────────────────────┐
│                                Manual Review                                 │
│            Some vulnerabilities require your attention to resolve            │
│                                                                              │
│         Visit https://go.npm.me/audit-guide for additional guidance          │
└──────────────────────────────────────────────────────────────────────────────┘
┌───────────────┬──────────────────────────────────────────────────────────────┐
│ Moderate      │ Prototype pollution                                          │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Package       │ hoek                                                         │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Patched in    │ > 4.2.0 < 5.0.0 || >= 5.0.3                                  │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Dependency of │ translate-json-object                                        │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Path          │ translate-json-object > google-translate > request > hawk >  │
│               │ boom > hoek                                                  │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ More info     │ https://nodesecurity.io/advisories/566                       │
└───────────────┴──────────────────────────────────────────────────────────────┘
┌───────────────┬──────────────────────────────────────────────────────────────┐
│ Moderate      │ Prototype pollution                                          │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Package       │ hoek                                                         │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Patched in    │ > 4.2.0 < 5.0.0 || >= 5.0.3                                  │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Dependency of │ translate-json-object                                        │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Path          │ translate-json-object > google-translate > request > hawk >  │
│               │ cryptiles > boom > hoek                                      │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ More info     │ https://nodesecurity.io/advisories/566                       │
└───────────────┴──────────────────────────────────────────────────────────────┘
┌───────────────┬──────────────────────────────────────────────────────────────┐
│ Moderate      │ Prototype pollution                                          │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Package       │ hoek                                                         │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Patched in    │ > 4.2.0 < 5.0.0 || >= 5.0.3                                  │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Dependency of │ translate-json-object                                        │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Path          │ translate-json-object > google-translate > request > hawk >  │
│               │ hoek                                                         │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ More info     │ https://nodesecurity.io/advisories/566                       │
└───────────────┴──────────────────────────────────────────────────────────────┘
┌───────────────┬──────────────────────────────────────────────────────────────┐
│ Moderate      │ Prototype pollution                                          │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Package       │ hoek                                                         │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Patched in    │ > 4.2.0 < 5.0.0 || >= 5.0.3                                  │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Dependency of │ translate-json-object                                        │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Path          │ translate-json-object > google-translate > request > hawk >  │
│               │ sntp > hoek                                                  │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ More info     │ https://nodesecurity.io/advisories/566                       │
└───────────────┴──────────────────────────────────────────────────────────────┘
┌───────────────┬──────────────────────────────────────────────────────────────┐
│ Moderate      │ Prototype pollution                                          │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Package       │ hoek                                                         │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Patched in    │ > 4.2.0 < 5.0.0 || >= 5.0.3                                  │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Dependency of │ translate-json-object                                        │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Path          │ translate-json-object > yandex-translate > request > hawk >  │
│               │ boom > hoek                                                  │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ More info     │ https://nodesecurity.io/advisories/566                       │
└───────────────┴──────────────────────────────────────────────────────────────┘
┌───────────────┬──────────────────────────────────────────────────────────────┐
│ Moderate      │ Prototype pollution                                          │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Package       │ hoek                                                         │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Patched in    │ > 4.2.0 < 5.0.0 || >= 5.0.3                                  │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Dependency of │ translate-json-object                                        │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Path          │ translate-json-object > yandex-translate > request > hawk >  │
│               │ cryptiles > boom > hoek                                      │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ More info     │ https://nodesecurity.io/advisories/566                       │
└───────────────┴──────────────────────────────────────────────────────────────┘
┌───────────────┬──────────────────────────────────────────────────────────────┐
│ Moderate      │ Prototype pollution                                          │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Package       │ hoek                                                         │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Patched in    │ > 4.2.0 < 5.0.0 || >= 5.0.3                                  │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Dependency of │ translate-json-object                                        │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Path          │ translate-json-object > yandex-translate > request > hawk >  │
│               │ hoek                                                         │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ More info     │ https://nodesecurity.io/advisories/566                       │
└───────────────┴──────────────────────────────────────────────────────────────┘
┌───────────────┬──────────────────────────────────────────────────────────────┐
│ Moderate      │ Prototype pollution                                          │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Package       │ hoek                                                         │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Patched in    │ > 4.2.0 < 5.0.0 || >= 5.0.3                                  │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Dependency of │ translate-json-object                                        │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Path          │ translate-json-object > yandex-translate > request > hawk >  │
│               │ sntp > hoek                                                  │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ More info     │ https://nodesecurity.io/advisories/566                       │
└───────────────┴──────────────────────────────────────────────────────────────┘
┌───────────────┬──────────────────────────────────────────────────────────────┐
│ Moderate      │ ReDoS via long string of semicolons                          │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Package       │ tough-cookie                                                 │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Patched in    │ >=2.3.0                                                      │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Dependency of │ translate-json-object                                        │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Path          │ translate-json-object > yandex-translate > request >         │
│               │ tough-cookie                                                 │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ More info     │ https://nodesecurity.io/advisories/130                       │
└───────────────┴──────────────────────────────────────────────────────────────┘
┌───────────────┬──────────────────────────────────────────────────────────────┐
│ High          │ Regular Expression Denial of Service                         │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Package       │ tough-cookie                                                 │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Patched in    │ >=2.3.3                                                      │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Dependency of │ translate-json-object                                        │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Path          │ translate-json-object > yandex-translate > request >         │
│               │ tough-cookie                                                 │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ More info     │ https://nodesecurity.io/advisories/525                       │
└───────────────┴──────────────────────────────────────────────────────────────┘
┌───────────────┬──────────────────────────────────────────────────────────────┐
│ Moderate      │ Memory Exposure                                              │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Package       │ tunnel-agent                                                 │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Patched in    │ >=0.6.0                                                      │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Dependency of │ translate-json-object                                        │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Path          │ translate-json-object > google-translate > request >         │
│               │ tunnel-agent                                                 │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ More info     │ https://nodesecurity.io/advisories/598                       │
└───────────────┴──────────────────────────────────────────────────────────────┘
┌───────────────┬──────────────────────────────────────────────────────────────┐
│ Moderate      │ Memory Exposure                                              │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Package       │ tunnel-agent                                                 │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Patched in    │ >=0.6.0                                                      │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Dependency of │ translate-json-object                                        │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Path          │ translate-json-object > yandex-translate > request >         │
│               │ tunnel-agent                                                 │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ More info     │ https://nodesecurity.io/advisories/598                       │
└───────────────┴──────────────────────────────────────────────────────────────┘

Note that the tunnel agent havnt fix their issues yet so you cant fix that though :)

Yandex API returns (.|.)] in their response

Hello, I develop a multi-language service and found your library quite helpfull.
But recently I had an interesting issue with yandex API.
And more I use it more I face this problem.
The issue appears suddenly, it doesn't bind with length or complexeety of a json file.
The problem looks like this:

{
    "key": "value(.|.)]key2 value2",
    "key3": "value3",
    "key4": "value4"
}

Steps to reproduce

  1. We have some json file in eng
{
    "mySchemesRoute": "Tariffs",
    "distribution": "Distribution",
    "allSchemesRoute": "Catalog schemes",
    "cityPlaceholder": "City"
}
  1. We run translate from en to fr and recive
{
    "mySchemesRoute": "Les droits de douane(.|.)]La Distribution de",
    "distribution": "Catalogue des régimes de",
    "allSchemesRoute": "Ville"
}

In example above, we lost the last key/value, and our first value is not exactly what we expect to receive :)

As I understood, you use var hashSimple = '[(.|.)]' as symbol to join the array value we use, because yandex wants to receive a string, and we use something that user never want to translate, right?.
I dont know why, but after we send, in our example, "Tariffs[(.|.)]Distribution...etc'.
We recieve from yandex Les droits de douane(.|.)]La Distribution de so they somehow LOST our first "[" symbol, and so your split (var result = res.text[0].split(hashSimple);) can't do it properly

Solution

As an solution for me, i use var hashSimple = '/|/|/|'

Maybe this should be committed in repo?

use async/await

Hi, i want to use async/await instead of TJO.translate(example, 'es')
.then(function(data) {
console.log(data);
}).catch(function(err) {
console.log('error ', err)
});

Bug with yandex and en to ru translation (when special chars is exist)

Hi!
Thanks you for package.

There is error when I try to translate from EN to RU using yandex api.
(in the same time from en to es correct)

example:
{ "messages": { "specialCharacters": "Field blablabla ('), dashes (-), periods (.), and spaces ( )", "alphanumSpecialCharacters": "Field blablabla ('), dashes (-), periods (.), and spaces ( )", .... }

Result: that two lines concatenate to one, third line contains value of 4th line, etc.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.