Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to return apostrophe when using Google Translate API for Android?

I have an Android application that uses Google Translate API. Everything works great, including when I tried to translate phrases that include apostrophe like "We've eaten" to Spanish.

However, problems occur when the translation result I should be getting back contains an apostrophe. For example, when I translate a Spanish phrase, "A ver", into English, it returns "Let&#39s see" with a ";" after "9". It seems like whenever I have a phrase that should return an apostrophe, it returns "&#39" with a ";" after "9". (Not placing ";" after "9" because it gets converted to an apostrophe by stackoverflow).

I can think of a way to solve it. After I get the translation result, I can match the string for ""&#39" + ";" and replace it with an apostrophe.

However, I don't feel like this is the way I should approach it. It's very unlikely that a user will actually type in "&#39" as an input for translation, but hard coding a manual conversion like this seems like it might cause problems down the road. I'll love to hear your thoughts on this.

Please let me know how I should fix/approach this issue.

Thank you!

like image 397
Charles Li Avatar asked Dec 15 '22 02:12

Charles Li


1 Answers

The best solution is to add &format=text to your query.

like image 99
Guillaume Ramey Avatar answered Dec 16 '22 16:12

Guillaume Ramey