Stichoza / google-translate-php

🔤 Free Google Translate API PHP Package. Translates totally free of charge.
MIT License
1.82k stars 382 forks source link

Google returning Error 400 (Bad Request) for certain queries. #13

Closed johnh10 closed 9 years ago

johnh10 commented 9 years ago

Nice class that mostly works but seems to have a small problem in certain cases.

For example I'm pulling in a YouTube video description in Russian:

Ставьте лайк и подписывайтесь если понравилось! Спасибо за просмотр :D\nLeave a like if you enjoyed and subscribe! Thanks for watching :D\n\nс вами Daev\n\n\nТеги***************************************************************************************************************************************************\n#Daev #world of tanks 9.6 #world of tanks арта #world of tanks артиллерия #world of tanks бонус код #world of tanks вбр #олени в world of tanks #как поднять кпд в world of tanks #как поднять стату в world of tanks #как поднять фпс в world of tanks #как играть в world of tanks #как заработать золото в world of tanks #world of tanks для новичков #world of tanks канал #world of tanks карты #world of tanks на русском #world of tanks обучение #world of tanks приколы и баги #world of tanks 60fps

and when I call $translate = GoogleTranslate::staticTranslate( $desc, "auto", "en" ); it returns FALSE.

Debugging the staticTranslate function I can see the result returned by Google is Error 400 (Bad Request). It only happens sometimes so I'm wondering if rawurlencode is tripping up on some of the text(?)

Stichoza commented 9 years ago

Does this error occur on certain texts or it's just happening randomly? I mean, the same text sometimes translates and sometimes not?

johnh10 commented 9 years ago

It's only on certain texts. I don't know why but some Russian language strings translate fine and others get the Error 400. It's reproducible.

In function staticTranslate I dumped the created url on a non-working example from https://www.youtube.com/watch?v=0NjqjNPhTlc if you wish to test:

http://translate.google.com/translate_a/t?client=t&text=%D0%B1%D0%B0%D0%B7%D1%8B%20%D0%B0%D0%BA%D0%BA%D0%B0%D1%83%D0%BD%D1%82%D0%BE%D0%B2%20world%20of%20tanks%20%20http%3A%2F%2Fcheat-worldoftanks.ga%2Fmes.html%0A%0A%0A%0A%0A%D0%9D%D1%80%D0%B0%D0%B2%D1%8F%D1%82%D1%81%D1%8F%20%D1%82%D0%B0%D0%BD%D0%BA%D0%B8%3F%20%D0%9F%D0%BE%D0%B4%D0%BF%D0%B8%D1%81%D1%8B%D0%B2%D0%B0%D0%B9%D1%82%D0%B5%D1%81%D1%8C%20%D0%BD%D0%B0%20%D0%BA%D0%B0%D0%BD%D0%B0%D0%BB%21%0A%D0%92%D1%81%D0%B5%20%D1%81%D0%B0%D0%BC%D1%8B%D0%B5%20%D0%B8%D0%BD%D1%82%D0%B5%D1%80%D0%B5%D1%81%D0%BD%D1%8B%D0%B5%20%D0%BD%D0%BE%D0%B2%D0%BE%D1%81%D1%82%D0%B8%20%D0%B2%20%D0%BD%D0%B0%D1%88%D0%B5%D0%BC%20%D1%82%D0%B2%D0%B8%D1%82%D1%82%D0%B5%D1%80%D0%B5%3A%20http%3A%2F%2Ftwitter.com%2Fworldoftanks_ru%0A%D0%97%D0%B0%D1%80%D0%B5%D0%B3%D0%B8%D1%81%D1%82%D1%80%D0%B8%D1%80%D1%83%D0%B9%D1%82%D0%B5%D1%81%D1%8C%20%D0%B8%20%D0%B8%D0%B3%D1%80%D0%B0%D0%B9%D1%82%D0%B5%20%D0%B2%20World%20Of%20Tanks%20%D0%B1%D0%B5%D1%81%D0%BF%D0%BB%D0%B0%D1%82%D0%BD%D0%BE%3A%20http%3A%2F%2Fworldoftanks.ru%2F%0A%0A%D0%9E%D0%B1%D1%81%D1%83%D0%B6%D0%B4%D0%B5%D0%BD%D0%B8%D0%B5%20%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE%20%D0%BD%D0%B0%20%D1%84%D0%BE%D1%80%D1%83%D0%BC%D0%B5%3A%20http%3A%2F%2Fforum.worldoftanks.ru%2Findex.ph...%0A%0A%D0%BF%D1%80%D0%BE%D0%BA%D0%B0%D1%87%D0%B0%D1%82%D1%8C%20world%20of%20tanks%0A%D0%B1%D0%B0%D0%B7%D1%8B%20%D0%B0%D0%BA%D0%BA%D0%B0%D1%83%D0%BD%D1%82%D0%BE%D0%B2%20world%20of%20tanks%0A%D0%BF%D1%80%D0%BE%D0%BA%D0%B0%D1%87%D0%B0%D1%8E%20%D0%B0%D0%BA%D0%BA%D0%B0%D1%83%D0%BD%D1%82%20world%20of%20tanks%0A%D0%BF%D1%80%D0%BE%D0%BA%D0%B0%D1%87%D0%BA%D0%B0%20world%20of%20tanks%0Aworld%20of%20tanks%20%D0%BF%D1%80%D0%BE%D0%BA%D0%B0%D1%87%D0%BA%D0%B0%20%D1%82%D0%B0%D0%BD%D0%BA%D0%BE%D0%B2%0Aworld%20of%20tanks%20%D0%BF%D1%80%D0%BE%D0%BA%D0%B0%D1%87%D0%BA%D0%B0%20%D1%8D%D0%BA%D0%B8%D0%BF%D0%B0%D0%B6%D0%B0%0A%D0%B1%D0%B0%D0%B7%D1%8B%20%D0%B0%D0%BA%D0%BA%D0%B0%D1%83%D0%BD%D1%82%D0%BE%D0%B2%20world%20of%20tanks%0A%D0%BF%D1%80%D0%BE%D0%BA%D0%B0%D1%87%D0%BA%D0%B0%20%D0%B0%D0%BA%D0%BA%D0%B0%D1%83%D0%BD%D1%82%D0%B0%20world%20of%20tanks%0A%D0%B1%D0%B5%D1%81%D0%BF%D0%BB%D0%B0%D1%82%D0%BD%D0%B0%D1%8F%20%D0%BF%D1%80%D0%BE%D0%BA%D0%B0%D1%87%D0%BA%D0%B0%20world%20of%20tanks%0A%D0%BF%D1%80%D0%BE%D0%BA%D0%B0%D1%87%D0%BA%D0%B0%20world%20of%20tanks%20%D0%B1%D0%B5%D1%81%D0%BF%D0%BB%D0%B0%D1%82%D0%BD%D0%BE%0A%D0%B1%D0%B0%D0%B7%D1%8B%20%D0%B0%D0%BA%D0%BA%D0%B0%D1%83%D0%BD%D1%82%D0%BE%D0%B2%20world%20of%20tanks%0Aworld%20of%20tanks%20%D0%B1%D1%8B%D1%81%D1%82%D1%80%D0%B0%D1%8F%20%D0%BF%D1%80%D0%BE%D0%BA%D0%B0%D1%87%D0%BA%D0%B0%0A%D0%BF%D1%80%D0%BE%D0%BA%D0%B0%D1%87%D0%BA%D0%B0%20%D0%BF%D0%B5%D1%80%D0%BA%D0%BE%D0%B2%20world%20of%20tanks%0Awor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ago

I guess there is some kind of limit on GET request size (But it should cause Error 414 instead of 400 ).

I can't fix this bug right now (3AM here). I'll take care tomorrow, sorry.

By the way maybe it's related to #8

johnh10 commented 9 years ago

Yes that would explain both issues. Now we have to figure out how best to handle it - change the GET request to a POST request?

Stichoza commented 9 years ago

This is fixed in latest version v3.0.1