Skip to content
This repository has been archived by the owner on Nov 22, 2022. It is now read-only.

Commit

Permalink
add token for google translate service
Browse files Browse the repository at this point in the history
  • Loading branch information
mote0230 committed Oct 5, 2015
1 parent a7c7613 commit b7c7c49
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion providers/google-translate.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,18 @@ function translationResult(str) {
}
}

//some sort of token google uses
function generateToken() {
var a = Math.floor((new Date).getTime() / 36E5) ^ 123456;
return a + "|" + Math.floor((Math.sqrt(5) - 1) / 2 * (a ^ 654321) % 1 * 1048576)

}

function apiUrl(from, to, text) {
const protocol = 'https://'
const host = 'translate.google.com'
let path = `/translate_a/single?client=t&ie=UTF-8&oe=UTF-8` +
`&dt=bd&dt=ex&dt=ld&dt=md&dt=qca&dt=rw&dt=rm&dt=ss&dt=t&dt=at` +
`&dt=bd&dt=ex&dt=ld&dt=md&dt=qca&dt=rw&dt=rm&dt=ss&dt=t&dt=at&tk=` + generateToken() +
`&sl=${from}&tl=${to}&hl=${to}`
if (typeof text != 'undefined') {
path += `&q=${encodeURIComponent(text)}`
Expand Down

0 comments on commit b7c7c49

Please sign in to comment.