Forum Discussion

Akenefick's avatar
Akenefick
Genius
5 months ago

Integrating Community with Google Translate

Hi

We are exploring integrating google translate into our community. So, I had a couple of questions.

Google uses Oauth 2.0 as detailed here https://developers.google.com/identity/protocols/oauth2/service-account#httprest which I am completely unfamiliar with. So, I have been slowly working my way through these instructions to request the access token from google.

I'm up to generating the signature which google says requires RSA SHA256 algorithm. In the Khoros documentation I found this digest.hmac("algorithm","key","message") (khoros.com) and it looks like I can use HMAC SHA256. Again, all of this is Greek to me ðŸ˜€ but a little searching tells me HMAC and RSA are two different things.

So, does anyone know if RSA is possible with Khoros? I can't find anything about it in the documentation.

Also, has anyone else done this kind of integration specifically with google translate? If so, can you share how to do this authentication?

Thanks!

  • I had a look at the docs you linked for Google and it indeed seems overly complicated. I mean an endpoint that does send something to a payed service doesn't need OAuth in my opinion, it just needs a valid API key to associate the request with your account, there is no "identity element" involved to distinguish between various users, that's what OAuth is usually used for in my world... e.g. I'm not seeing the point in going trough all the OAuth hoops for something relatively simple like that...

    but:

    but of course I don't know if you intend to use the Advanced API (v3)? Otherwise you might be able to get around with a regular API key / Bearer token auth, here's how you'd do it: https://stackoverflow.com/a/70656679/4428236 

    If you don't want to bother at all with authentication you could try and get inspired by this https://github.com/Stichoza/google-translate-php/blob/master/src/GoogleTranslate.php , it basically "abuses" translate.google.com (the web version) to translate stuff for free 😉.

  • Can't help a lot with the exact question regarding RSA/HMAC signatures, from what I know those are two different "schemes" to sign the payload, HMAC uses one key, RSA afaik needs two (pub/private), so I have a feeling that what is available in Khoros won't do for that. Doing OAuth in FreeMarker always felt awkward to me and I avoided it whenever I could, meaning if I can sent some kind of Bearer token via "authorization" header in the request, I will always choose that... meaning maybe there is an alternative way to authenticate with your Google API?

    If it's not possible you might wanna check out https://libretranslate.com as an alternative translation API. It actually does work quite well but of course depends on your use case. You can also self-deploy it on your own infrastructure (it's dockerized, takes 15-30mins) or you can buy an API key for the public/web endpoint for 29$/month (unlimited translations, nothing like $ per 1 million characters like Google and co, rate limited to 80 translations per min).

    • Great thanks for the recommendation. We were looking at Google because my company already uses it elsewhere, but I was checking out Microsoft and they are much easier to authenticate. I will take a look at Libretranslate too.

      Thanks!

  • I had a look at the docs you linked for Google and it indeed seems overly complicated. I mean an endpoint that does send something to a payed service doesn't need OAuth in my opinion, it just needs a valid API key to associate the request with your account, there is no "identity element" involved to distinguish between various users, that's what OAuth is usually used for in my world... e.g. I'm not seeing the point in going trough all the OAuth hoops for something relatively simple like that...

    but:

    but of course I don't know if you intend to use the Advanced API (v3)? Otherwise you might be able to get around with a regular API key / Bearer token auth, here's how you'd do it: https://stackoverflow.com/a/70656679/4428236 

    If you don't want to bother at all with authentication you could try and get inspired by this https://github.com/Stichoza/google-translate-php/blob/master/src/GoogleTranslate.php , it basically "abuses" translate.google.com (the web version) to translate stuff for free 😉.

    • The person from my company already using google elsewhere said to use API V3. I didn't ask why. I'm not sure if there is a good reason, but I think we have decided to go our own way with the community and try something simpler (looking into Microsoft but I plan to take a look at Libretranslate too). Also, with Aurora on the horizon we haven't decided if we want to invest the effort in this yet, but I'd like to start playing with it on stage.

      Thanks for all the help!