Huawei Ml Kit Text Translation

Umit Kose
Huawei Developers
Published in
3 min readJan 28, 2021

Hi friends,

In this article, I will explain Huawei Ml Kit Text Translation service and how to use other functions.

If you have any questions about how you can integrate HMS Core into your project, please take a look at below post before beginning.

Real Time Translation

The real-time translation service can translate text from the source language into the target language through the server on the cloud. Currently, real-time translation supports 38 languages.

Development Process

First of all, we should create real-time translator by using MLRemoteTranslateSetting class.

We are able to change source and target language code. It should be generic ISO language code. For example; we chose Chinese and English.

Getting Cloud Languages

With this code snippet, we translate the text we have entered into the target language:

Release resources after the translation is complete.

Important Note

We have a monthly limit of 10 thousand in real-time translation. If it exceeds 10 thousand, the application starts to give an exception.

Therefore, in some cases it will make more sense to use on-device text translation.

On-device Translation

With the support of an on-device model, the on-device translation service can translate text from the source language into the target language when no Internet service is available. Currently, this service supports on-device translation of text in 37 languages.

Development Process

First of all, we should create local offline translator by using MLLocalTranslateSetting class.

It is quite similar to Real-time translator. We defined source and target language code.

Getting Local Languages

Download Required Language Model

With this model download class, we download the language code model we specified to our phone. Language models are about 25–30 mb in size. For this process, we can show the user a dialog progress.

Show Model Downloading Progress

With this method, we show the user what percentage of the model has been downloaded and how many mb the model size is on the screen as a dialog. I’ll share the screenshots soon.

Translate Input Text

Delete Language Model

With this method, we can delete the downloaded language pack at any time. We just need to enter the correct language code.

Results

Download Model
Delete Model
Text Translation

Unfortunately, we cannot share the source codes of the project. But I will update our Huawei Lens application as soon as it becomes public.

--

--