Android App Development
iOS App Development
Flutter App Development
Cross Platform App Development
Hire on-demand project developers and turn your idea into working reality.
Big thanks to Webkul and his team for helping get Opencart 3.0.3.7 release ready!
Deniel Kerr
Founder. Opencart
Top Partners
We are going to learn language translation for the Android app, In this blog, we will use Firebase Translation API to translate the word, sentence, or paragraph in any language, For a better understanding, we take an example to translate sentence English to the Hindi language.
Firebase provides free API to translate between multiple languages. Firebase supports 59 languages. You can easily integrate Firebase Translation API in your project
If you haven’t already, add Firebase to your Android project.
Add 2 dependency in your app-level build Gradle file.
After adding dependencies click on ‘sync project’ on the top right corner.
These dependencies will add all the Firebase language translation classes in your project.
We are taking an example to translate English into the Hindi language. 1.1)
We have to set Source language and Target language for translation, As we are translating English to Hindi So set FirebaseTranslateLanguage.EN as the source language and FirebaseTranslateLanguage.HI for target language in FirebaseTranslatorOptions.
To start the translation process call translate method and pass text which you want to translate(It should be in the source language). This method translates text into the target language. see above code (1.1) To get the success translated text you have to implement a callback listener. We implemented the success and failure listener. When successfully translate your text then it will receive in the onSuccess() method and for any error onFailure() method will be called.
Note – Firebase translation works only when the source and target language models exist in your device.
Don’t worry! Firebase provides a solution for this. You have to add a few lines before starting the translation to check the language models’ existence in the device or download the model if not exist. Call the downloadModelIfNeeded() before start the translation. This method will check the source and target language models exist in the device, If not then this will start the downloading of the language models automatically. To get the download completed event we have to implement callback listener when models downloaded successfully
If you want all things done automatically means checks both (source and target) model downloaded or not if not, then download automatically and start the translation process after download completed onSuccess() called. This is the correct time when you should start the translation process as we did in the final code see below.
Final code –
Finally, your translation process completed. Besides, you can translate in many languages as mentioned in the top.
Most importantly – After downloaded the language models in the device you can translate the words, sentence, or paragraph offline because of the Firebase translation process do in the device using models. No internet required.
Reference – https://firebase.google.com/docs/ml-kit/android/translate-text
Your email address will not be published. Required fields are marked*
Name*
Email*
Save my name email and website in this browser for the next time I comment.
If you just want to type the hindi spellings of the english words then this will not be the right tool as of now.
But if you want to completely translate the words with their meaning from one laguage to another, then this tool is defnitely for you.
We use cookies to personalize your experience. By continuing to visit this website you agree to our use of cookies. Learn more about privacy policy
Great Product, Great Team, and Great Support Service. And if you want to add more features to the product, they can submit any idea that comes to your mind. They really care about their clients and we are really happy and honored to deal with Webkul.
Osama
USA
India
Global
Name
Email
Enquiry or Requirement
If you have more details or questions, you can reply to the received confirmation email.