How to separate original and translated review comment from a from google maps api

809 Views Asked by At

I have a lot of google access tokens in my DB (more than 1k). These tokens belong to google-my-business owners that have been authenticated to my app via google and gave permissions to use their tokens. I want to get all google reviews from all these accounts and save them to my DB. But when I get reviews, I get them with an automatically generated translation as a single string. And I want to split the original and translated and save it separately. Reviews have this format.

(Translated by Google) Awesome!
(Original) Круто!

Usually, I would just split this string by "(Translated by Google)" substring. But this solution doesn't work, because the substring is actually different and depends on the user's account language settings. And if user set up his language to russian, this substring will look like "(Переведено Google)". Is there any way to split the original comment from translated one, considering different language settings?

P.S. This question is not a duplicate because other ones don't have this language problem.

1

There are 1 best solutions below

1
On

I found a solution that I really don't like and it's an overkill, but that's the only thing that came to my mind. First I get the user's language settings by calling this endpoint https://developers.google.com/my-business/reference/rest/v4/accounts. Then I translate '(Translated by Google)' string via google translate API to this language and then I split the review comment by this string. It works, but if you suggest something better, it would be awesome.