English – Adding Google Translate API (This is a paid API) to Android apps

Here are the steps required to add Google Translate API to your Android apps. The intention of this document is to share an approach to implementing the functionality and implementation can be optimized further.

Image credits : https://www.teachingenglish.org.uk

Some things to keep in mind

  1. This is a paid API and hence you need to keep an eye on the usage.
  2. The shared Proguard config is just a working sample. It can still be improved.
  3. You should limit the key usage to just the android app using the console to avoid quota theft. Steps to do that are not in the scope of this article but is relatively straight forward to implement.

Gradle changes

Sample code change

Interface for callback handling

Translation function

Note: Translate function internally runs a network call so it cannot be called on the main UI thread. Hence the above function has to executed on a different thread.

Proguard Config

Some recommendations

  • App size and method count increase is considerable even though we are using only translate API. The web call wrapper approach works better if you have strong need to keep app size small but is less secure against quota theft.
  • Keep a close track on the usage and cost incurred. This API can become expensive for unicode based languages if the number of translations performed are high.
  • Keep a remote config switch to turn the feature off is a good idea. Firebase remote config tool can be used for the same.


Hope this article provides direction to those of you working with Google Translate API on android apps and in case you find improvements over what I have shared here, please do let me know. Thanks in advance.

Deixe um comentário

Preencha os seus dados abaixo ou clique em um ícone para log in:

Logotipo do WordPress.com

Você está comentando utilizando sua conta WordPress.com. Sair /  Alterar )

Foto do Google

Você está comentando utilizando sua conta Google. Sair /  Alterar )

Imagem do Twitter

Você está comentando utilizando sua conta Twitter. Sair /  Alterar )

Foto do Facebook

Você está comentando utilizando sua conta Facebook. Sair /  Alterar )

Conectando a %s