bpierre / gtranslate

Translate the selected text using Google Translate.
https://addons.mozilla.org/firefox/addon/gtranslate/
Mozilla Public License 2.0
95 stars 27 forks source link

google api needs to use POST for long requests #44

Closed mote0230 closed 9 years ago

mote0230 commented 9 years ago

Otherwise it returns error 400 Cutoff seems to be around 1359 characters

mote0230 commented 9 years ago

fixed https://github.com/bpierre/gtranslate/commit/2ceeecedb2dea66b980165b23aca275e70b96a81 the code might use some styling

mote0230 commented 9 years ago

Still some issue with non-western scripts

mote0230 commented 9 years ago

Relevant code in chrome's official translate extension:

function(a, b, c, d) {
        if ("" != a) {
            window.selection = a;
            a = new Wf("gtx", "https://translate.googleapis.com");
            var e = chrome.i18n.getUILanguage ? chrome.i18n.getUILanguage() : "en";
            d = null != d ? d : "auto";
            var f = Ag();
            c = new M("source=" + c);
            var g = window.selection,
                k = a.a + "/translate_a/single",
                l = new M,
                v = new M;
            window.EGGS_JANGO && ("qab" == d && (l.set("slo", "qab"), d = "en"), "qab" == f && (l.set("tlo", "qab"), f = "en"));
            l.set("client", a.c);
            l.set("sl", d);
            l.set("tl", f);
            l.set("hl", e);
            Mc(l, "dt", ["t", "bd"]);
            l.set("dj", "1");
            c && l.g(c);
            v.set("q",
                g);
            Yf(a, k, l, v, t(a.f, a, b))
        }

  Yf = function(a, b, c, d, e) {
            c = c.toString();
            c += "&tk=" + Xf();
            d = d.toString();
            var f = "POST";
            b += "?" + c;
            2E3 > c.length + d.length && (f = "GET", b += "&" + d, d = "");
// ...
}