Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Add support for auto switch URL. #76

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
var querystring = require('querystring');

var url = require('url');
var got = require('got');
var safeEval = require('safe-eval');
var token = require('google-translate-token');
Expand Down Expand Up @@ -30,7 +31,6 @@ function translate(text, opts) {
opts.to = languages.getCode(opts.to);

return token.get(text).then(function (token) {
var url = 'https://translate.google.com/translate_a/single';
var data = {
client: 't',
sl: opts.from,
Expand All @@ -47,7 +47,7 @@ function translate(text, opts) {
};
data[token.name] = token.value;

return url + '?' + querystring.stringify(data);
return url.resolve(token.url, '/translate_a/single?' + querystring.stringify(data));
}).then(function (url) {
return got(url).then(function (res) {
var result = {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"homepage": "https://github.com/matheuss/google-translate-api#readme",
"dependencies": {
"configstore": "^2.0.0",
"google-translate-token": "latest",
"google-translate-token": "github:gucong3000/google-translate-token#google.cn",
"got": "^6.3.0",
"safe-eval": "^0.3.0"
},
Expand Down