nanek / mstranslator Goto Github PK
View Code? Open in Web Editor NEWDEPRECATED: Microsoft Translator API module for node.js
License: MIT License
DEPRECATED: Microsoft Translator API module for node.js
License: MIT License
Translated text keep adding space to br tag like this
http://social.microsoft.com/Forums/en-US/f75d9715-5fb5-4852-9a1c-32593ee429e5/translator-api-adding-spaces-into-br-tags?forum=translator
So I try params:
var params = {
text: title,
to: 'vi',
options: { contentType : 'text/html' }
};
and one again with
var params = {
text: title,
to: 'vi',
contentType : 'text/html'
};
But it still doesn't work. Any help would be greatly appreciated.
In defining the options object, one should follow the syntax below, otherwise, translateArray(*) will give the error: "Expecting element 'root' from namespace ''..Encountered 'none' with name '', namespace".
var params = {texts: ["test","this"], from: "en", to: "zh-CHS", options:"{\"ProfanityAction\":\"Deleted\"}"};
Reference: https://msdn.microsoft.com/en-us/library/ff512407.aspx
Hi @nanek,
I'm having a weird problem were the MS API simply stops recognizing my app. I spin up the server, the translation requests through this lib work as expected and at any time for no reason it stops working.
see the log below. it works and then it starts failing.
/translate { text: 'hola', from: 'es', to: 'en' }
all good in translate Hello
/translate { text: 'hola que tal?', from: 'es', to: 'en' }
all good in translate Hello, how are you doing?
/translate { text: '', from: 'es', to: 'en' }
error in translate [Error: "TranslateApiException: Cannot find an active Azure Market Place Translator Subscription associated with the request credentials. : ID=5005.V2_Json.Translate.2C53805E"]
/translate { text: 'hola', from: 'es', to: 'en' }
error in translate [Error: "TranslateApiException: Cannot find an active Azure Market Place Translator Subscription associated with the request credentials. : ID=3444.V2_Json.Translate.2CB38A02"]
Do you have any idea why this might be happening ?
I couldn't find any useful information related to this error.
When I run your libary with less than 4737 characters, like so:
translate({
text: article.body.substr(0, 4636),
from: 'zh-CHS',
to : 'en',
})
It works fine. Yet when I run it with 4647 characters or more:
translate({
text: article.body.substr(0, 4637),
from: 'zh-CHS',
to : 'en',
})
I get an exception:
[SyntaxError: Unexpected token !]
SyntaxError: Unexpected token !
at Object.parse (native)
at IncomingMessage.<anonymous> (/home/tom/projects/chambeng/chambeng-amt/node_modules/mstranslator/mstranslator.js:116:25)
at IncomingMessage.emit (events.js:129:20)
at _stream_readable.js:908:16
at process._tickCallback (node.js:355:11
And when I inspect the API's response it gives:
!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN""http://www.w3.org/TR/html4/strict.dtd">
<HTML><HEAD><TITLE>Bad Request</TITLE>
<META HTTP-EQUIV="Content-Type" Content="text/html; charset=us-ascii"></HEAD>
<BODY><h2>Bad Request - Request Too Long</h2>
<hr><p>HTTP Error 400. The size of the request headers is too long.</p>
</BODY></HTML>
It seems like this libary should use another HTTP method and/or bundle large requests into several smaller requests.
This is some quick test code that I wrote to make sure that I was getting the arguments right:
translator.getLanguageNames("en", ["sv", "es", "ru"], console.log);
When I run it, I get this error:
TypeError: "listener" argument must be a function
at _addListener (events.js:216:11)
at ClientRequest.addListener (events.js:270:10)
at MsTranslator.call (C:\Users\Nick\Desktop\App\node_modules\mstranslator\mstranslator.js:150:7)
at C:\Users\Nick\Desktop\App\node_modules\mstranslator\mstranslator.js:78:19
at IncomingMessage.<anonymous> (C:\Users\Nick\Desktop\App\node_modules\mstranslator\mstranslator.js:103:9)
at emitNone (events.js:91:20)
at IncomingMessage.emit (events.js:185:7)
at endReadableNT (_stream_readable.js:926:12)
at _combinedTickCallback (internal/process/next_tick.js:74:11)
at process._tickDomainCallback (internal/process/next_tick.js:122:9)
Can someone help me here?
The application is working, but not rarely I'm getting the following error.
_events.js:85
throw er; // Unhandled 'error' event
^
Error: connect ETIMEDOUT
at exports.errnoException (util.js:746:11)
at TCPConnectWrap.afterConnect as oncomplete
The code is
var MsTranslator = require('mstranslator');
// Second parameter to constructor (true) indicates that
// the token should be auto-generated.
var client = new MsTranslator({
client_id: "mejustme"
, client_secret: "tM0Zc37RypU3Lqm8WtFH7XXuTAOfkoJZraMz2axEVf4="
}, true);
var params = {
text: 'most beautiful place is spain'
, from: 'en'
, to: 'es'
};
// Don't worry about access token, it will be auto-generated if needed.
client.translate(params, function(err, data) {
console.log(data);
});
Babel 6 (6.8.0) reports mstranslator.js is attempting to delete a local variable (buffers) at line 177.
node_modules/mstranslator/mstranslator.js: Deleting local variable in strict mode (177:6)
175 | index += buf.length;
176 | });
> 177 | delete(buffers);
| ^
178 | fn(null, body);
179 | });
180 | });
Process finished with exit code 1
The delete just looks incorrect and it looks like the fix is to remove line 177 (line179 in the current master).
Hi guys
I have installed this module into my vscode extension, made sure the MSTranslator is required correctly, I have a valid Azure key, but when I run the code I can debug and follow it to client.initialize_token(function(){ line, everything looks ready to go but then it just jumps away, no data is ever console logged.
Perhaps not being able to debug it into the functions is my poor understanding of javascript, but no code is ever called, azure is not called, my dashboard shows no calls are made.
What am I missing here?
Hi,
I was wondering if this package can handle translating to multiple languages at once with only one calls. Because as it's up to right now, I have to make multiple calls to translate.
Hi, thanks for creating this module!
I was having some problems with the connection, giving me an ECONNRESET. I know that it is not a problem of your module, but I think it would be great if you listen for 'error' events, when you create the http / https request, so we can handle them as any other error.
Hello from frog land !
I use mstranslator and it works thanks for your Api
I use it with nodesjs and no problems.
But my application is web and on browser i would
like use the client credentials rather mine (server side)
I try to use it with client javascript but your api is writen with require and i turn around a solution because of http https querystring modules.
To work with these modules i tried browserify without success.
I don't want a node_modules directory for my web site.
My tree nodesjs is for logical works.
And i have some difficulties to make your very good api running.
Just because of these modules.
With browserify i have errors the output file using require which is looking for the good paths.
So i try to perform my translations without asking to the server nodes to work.
I prefer use the javascript browser side.
Do you have a full client javascript solution ?
Thanks for your attention, have a nice day.
Frog land is also cheese land. In the south it smell
P.s: sorry for my english
Add support for Paraphrase API, http://msdn.microsoft.com/en-us/library/hh847648.aspx
Is there any way to control speech speed?? @nanek
Are there any plans to include a TypeScript declaration file for this library?
Which license is this project using?
MIT?
err : null
translated_data :TranslateApiException: The Azure Market Place Translator Subscription associated with the request credentials is not in an active state. : ID=3444.V2_Json.TranslateArray.5B6EAD27
Translate.translateArray(params, function(err, translated_data) { //Check if any error found console.log("err : "+err, "translated_data "+translated_data) }
according to api ref: https://msdn.microsoft.com/en-us/library/ff512420.aspx
speak is returning wave or mp3 stream, not url to it
Perhaps 0.11.x too...
If I understand correctly - this modules uses API v2 that now is marked as deprecated.
Migration guide has note that V2 api will be discontinued on April 30, 2019.
Are there plans to migrate to API v3?
I think #45 depends on this question too.
Services like https://david-dm.org/, https://gemnasium.com/ or http://www.versioneye.com/ make it easy to see which dependencies are out of date.
Currently there seems to be the only development dependency out of date, mocha
.
Any of the three services above are free and can be logged in with Github account.
For example, calling translate before client is initialized results in the following result string (but no error object):
client.translate(params, function(err, data) {
if(err) {
console.log(err);
return;
}
console.log("data: ", data);
});
"data: ArgumentException: No bearer information found in the token : ID=0818.V2_Json.Translate.467BDC19"
Hi.
I'm getting the error
ArgumentException: The Web Token must have a signature at the end. The incoming token did not have a signature at the end of the token. : ID=6346.V2_Json.Translate.4B2C3363
The code I'm using is
var express = require('express');
var app = express();
var server = app.listen(3000,function(){
var host = server.address().address;
console.log(host);
var port = server.address().port;
console.log('Example app listening at http://%s:%s', host, port);
});
var MsTranslator = require('mstranslator');
// Second parameter to constructor (true) indicates that
// the token should be auto-generated.
var client = new MsTranslator({
client_id: "mejustme"
, client_secret: "tM0Zc37RypU3Lqm8WtFH7XXuTAOfkoJZraMz2axEVf4"
}, true);
var params = {
text: 'How\'s it going?'
, from: 'en'
, to: 'es'
};
// Don't worry about access token, it will be auto-generated if needed.
client.translate(params, function(err, data) {
console.log(data);
});
How could I fix it?
Thank you for the attention.
Not a big deal, but in your code sample in the readme you have this:
var MsTanslator = require('mstranslator');
var client = new MsTranslator({client_id:"your client_id", client_secret: "your client secret"});
You'll notice on the first line it says MsTanslator (missing first 'r'). When copying and pasting code for first time to kick the tires of the API, I noticed it. Nice work on the API though.
As mentioned in Expresso, https://github.com/visionmedia/expresso
TDD framework for nodejs. This module is no longer maintained by me, if you wish to maintain it let me know, otherwise use Mocha.
Since it is no longer actively maintained (and fails to install for me), switch to Mocha as suggested.
Hi, thanks for your great module.
I've just installed it after following all the steps to setup my microsoft translator api, and introduced my client_id and client_secret.
The problem is it randomly traduces the text (about 50% of the times), but without consuming my quota of 2M (and I've used microsoft site to test and consume it (https://datamarket.azure.com/dataset/explore/bing/microsofttranslator). The 50% of the time that fails it gives this error:
The Azure Market Place Translator Subscription associated with the request credentials has zero balance.
Is this any known bug or am I missing something?
Thanks in advance.
I am working in a university, so I have to write a proxy when I need to access external APIs, I already did that with Wikipedia Api, but how can I provide mstranslator functions with a proxy??
i'm running the example in the readme, after the translated text is printed, the process will not exit. Is there any exit method to call?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.