如watson-developer-cloud中所述,我使用以下代码翻译某些文字:
var watson = require('watson-developer-cloud');
var language_translation = watson.language_translation({
username: '<username>',
password: '<password>',
version: 'v2'
});
var myTranslation = {};//is supposed to hold the translation provided by the following code:
language_translation.translate({
text: 'A sentence must have a verb', source : 'en', target: 'es' },
function (err, translation) {
if (err)
console.log('error:', err);
else{
myTranslation = JSON.stringify(translation, null, 2);
console.log(myTranslation);//print out the JSON with translation data
}
});
Here Begin problems:
console.log(myTranslation); // Print out an empty hash...
为什么myTranslation
在else
语句中保留了正确的数据,但在它之外,它是否包含空哈希?