google-translate-php icon indicating copy to clipboard operation
google-translate-php copied to clipboard

When Google return wrong JSON?

Open WinterSilence opened this issue 4 years ago • 8 comments

Can't repeat request where need fix JSON. Can you show example?

WinterSilence avatar Jul 31 '20 22:07 WinterSilence

Please describe your problem in detail. What have you tried, what was the input and response, what was the error?

frzsombor avatar Aug 03 '20 11:08 frzsombor

@frzsombor resend your developers: ? at end of issue title calling "question" :)

WinterSilence avatar Aug 04 '20 13:08 WinterSilence

@WinterSilence your issue doesn't give any details. I honestly cannot understand what you're asking or what problem are you having. Please, describe it in details and provide info that @frzsombor suggested.

Stichoza avatar Aug 04 '20 14:08 Stichoza

@Stichoza It's not "bug" or "future request", it's only question about current code. Google return valid json, I cant find any reason for this fix and ask you why you: add this json fix?

WinterSilence avatar Aug 04 '20 15:08 WinterSilence

I can't answer the question, but at least now I guess that @WinterSilence is talking about this part of the code and would like to know why we have to do a preg_replace on the response body, based on $resultRegexes (and in which cases), as it looks like we already have a valid json at that point (also I haven't tested this statement).

frzsombor avatar Aug 05 '20 11:08 frzsombor

@frzsombor ups.. sorry, I thought that you action bot.

WinterSilence avatar Aug 05 '20 13:08 WinterSilence

@WinterSilence lol, that's why I couldn't understand what did you mean by "resend your developers" 🤣

Yeah maybe Google now sends the valid JSON but I remember that sometimes there were invalid responses containing things like {"words":[,,"ok","yes",,,]} and so on.

I hadn't tested it now, but I'm afraid there might be some extra commas left in Google's responses and if we remove the regex replacement, it might cause some errors.

Stichoza avatar Aug 11 '20 20:08 Stichoza

@Stichoza sorry again - I really confused and thanks for answer.

I hadn't tested it now, but I'm afraid there might be some extra commas left in Google's responses and if we remove the regex replacement, it might cause some errors.

I agree with you, but we goes to other way: We tested this package at translating changes in framework api (~50-60 pages, top 6 languages) - current api version of google translate always returns valid result, as result: we fix json only at errors at decoding.

WinterSilence avatar Aug 21 '20 10:08 WinterSilence

Leaving these regex replaces as is at least for now.

Stichoza avatar Nov 28 '22 20:11 Stichoza