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

Problem with recent update from google api translate and complex strings #119

Closed
gbelot2003 opened this issue Sep 25, 2019 · 5 comments
Closed

Comments

@gbelot2003
Copy link

gbelot2003 commented Sep 25, 2019

Hello there. Just now I update the translate v3.4 module according with the changes you suggested, and for simple text works fine, but now the API uses the verb GET but the main problem is that I am using a text field with html, the answer is always: resulted in a 403 Forbidden response:
Im already using something like this to clear the code:

    $inpunt1 =  str_replace("<strong>", "",  $string);
    $inpunt2 =  str_replace("</strong>", "",  $inpunt1);
    $inpunt3 =  str_replace("<br />", "",  $inpunt2);
    $inpunt4 =  str_replace("/r", "",  $inpunt3);
    $inpunt5 =  str_replace(")", "",  $inpunt4);
    $inpunt6 =  str_replace("<p>", "",  $inpunt5);
    $inpunt7 =  str_replace("</p>", "",  $inpunt6);
    $input8 = preg_replace('/\s/', ' ', $inpunt7);
    $input9 = preg_replace('/\n/', '', $input8);

even after all this cleanning Im still getting this response from the server:

Client error: GET https://translate.google.com/translate_a/single?client=webapp&hl=en&dt=t&sl=es&tl=en&q=DESCRIPCI%26Oacute%3BN+MACROSC%26Oacute%3BPICA%3A++%26nbsp%3B++Se+recibe+1+frasco+conteniendo+2+l%26aacute%3Bminas+con+frotis+fijados+con+alcohol+de+regi%26oacute%3Bn+sangrado+pez%26oacute%3Bn+derecho%2C+se+colorean+con+hematoxilina-eosina.++++DIAGN%26Oacute%3BSTICO%3A+PEZON+DERECHO%2C+ASPIRADO+AGUJA+FINA%2C+EXTENDIDOS+-+++%26nbsp%3B++COMENTARIO%3A&ie=UTF-8&oe=UTF-8&multires=1&otf=0&pc=1&trs=1&ssel=0&tsel=0&kc=1&tk=531074.928252 resulted in a 403 Forbidden response:

My cuestion, is there a workaround, option or maybe another module to fix this issue,

thanks

@gbelot2003
Copy link
Author

Ok, if anyone comes to a problem like this, for me, html_entity_decode() solve the problem!!

@ederson13
Copy link

could you provide some more details regarding your fix ?

@gbelot2003
Copy link
Author

gbelot2003 commented Oct 6, 2019

Sorry for the delay, is very simple indid, in the controller, the string about to be translated, it has to be sanitize first, remember, now is a get verb. I just create a simple function before translation.
and of course, all the code about in my first entry is unnecesary, you just have clear the strings to pass for translations

private function cleanText($string)
{
    return trim(html_entity_decode($string, ENT_COMPAT, 'UTF-8'));
}

then just

$factor = $this->cleanText($muestra->body);
$body = $translator->setSource('es')
->setTarget('en')
->translate($factor);

@otnansirk
Copy link

But I still got that error. I added the function cleanText() before using it in translate()

@frzsombor
Copy link
Contributor

frzsombor commented Nov 25, 2019

@gbelot2003 I've tried figuring out what was the original text you wanted to translate, and by decoding the url you pasted I found that it could have been the following:

DESCRIPCI&Oacute;N MACROSC&Oacute;PICA: &nbsp; Se recibe 1 frasco conteniendo 2 l&aacute;minas con frotis fijados con alcohol de regi&oacute;n sangrado pez&oacute;n derecho, se colorean con hematoxilina-eosina. DIAGN&Oacute;STICO: PEZON DERECHO, ASPIRADO AGUJA FINA, EXTENDIDOS - &nbsp; COMENTARIO:

I see that you also figured out that HTML entities caused the problem because you solved it using html_entity_decode(). But what's really interesting, if I copy&paste the text above to the official Google Translate page, I also get a translation error on that page (which I never ever saw before). See:

image

It looks like this is an error with Google Translate itself, and I verified this as Google Translate fails even on a simple string if it contains any HTML entity like Hello &nbsp; world!.

If anybody expects to translate strings containing HTML entities I suggest them to decode the strings with html_entity_decode() before passing them to the translate function, until Google fixes this issue.

@Stichoza Until then I also suggest that this should be noted in the known limitations.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants