-
Notifications
You must be signed in to change notification settings - Fork 2
translation
With ML Kit's on-device translation API, you can dynamically translate text between more than 50 languages.
The following functions are provided to work with the translation API:
- mlkit_translation_create
- mlkit_translation_model_is_available
- mlkit_translation_translate
- mlkit_translation_close
- mlkit_translation_get_downloaded_list
- mlkit_translation_model_delete
- mlkit_translation_model_download
Creates a new translation unit for the given source and target languages and returns its unique identifier.
Note
This function is only supported on Android and iOS.
Syntax:
mlkit_translation_create(source, target)
| Argument | Type | Description |
|---|---|---|
| source | String | The source language tag (e.g. "en"). |
| target | String | The target language tag (e.g. "es"). |
Returns:
The translation unit's unique identifier, or -1 if the source|target language pair is not supported.
Example:
translator = mlkit_translation_create("en", "es");Checks whether the translation model for the given translation unit is available, downloading the required language packages if needed. The result is delivered to the callback.
Note
This function is only supported on Android and iOS.
This function operates asynchronously, which means that it does not immediately return the requested result. Instead, upon completion of the task, it will trigger the Callback.
Syntax:
mlkit_translation_model_is_available(translator, callback)
| Argument | Type | Description |
|---|---|---|
| translator | Real | The unique identifier of the translation unit to check. |
| callback | Function | The function called with the result (see below). |
Returns:
N/A
Triggers:
Triggered when the availability check completes.
| Key | Type | Description |
|---|---|---|
| success | Boolean | Whether a translation model is available for the language pair. |
| translator | Real | The translator unique identifier. |
| error | String or Undefined | The error message, or undefined if the request succeeded. |
Example:
mlkit_translation_model_is_available(translator, function(_success, _translator, _error) {
if (_success) show_debug_message("Model available");
});Requests the translation of the given text. The result is delivered to the callback.
Note
This function is only supported on Android and iOS.
This function operates asynchronously, which means that it does not immediately return the requested result. Instead, upon completion of the task, it will trigger the Callback.
Syntax:
mlkit_translation_translate(translator, text, callback)
| Argument | Type | Description |
|---|---|---|
| translator | Real | The unique identifier of the translation unit to use. |
| text | String | The text to be translated. |
| callback | Function | The function called with the result (see below). |
Returns:
N/A
Triggers:
Triggered when the translation request completes.
| Key | Type | Description |
|---|---|---|
| success | Boolean | Whether the translation succeeded. |
| translator | Real | The translator unique identifier. |
| text | String | The translated text (empty on failure). |
| error | String or Undefined | The error message, or undefined if the request succeeded. |
Example:
mlkit_translation_translate(translator, "Hello", function(_success, _translator, _text, _error) {
if (_success) show_debug_message(_text);
});Closes the translation unit and releases its resources.
Warning
Should be called when the translation unit is no longer needed.
Syntax:
mlkit_translation_close(translator)
| Argument | Type | Description |
|---|---|---|
| translator | Real | The unique identifier of the translation unit to close. |
Returns:
N/A
Example:
mlkit_translation_close(translator);Requests the list of all currently downloaded translation models. The result is delivered to the callback.
Note
This function is only supported on Android and iOS.
This function operates asynchronously, which means that it does not immediately return the requested result. Instead, upon completion of the task, it will trigger the Callback.
Syntax:
mlkit_translation_get_downloaded_list(callback)
| Argument | Type | Description |
|---|---|---|
| callback | Function | The function called with the result (see below). |
Returns:
N/A
Triggers:
Triggered when the request completes.
| Key | Type | Description |
|---|---|---|
| success | Boolean | Whether the request succeeded. |
| list | Array of String | An array of the downloaded models' language tags (empty on failure). |
| error | String or Undefined | The error message, or undefined if the request succeeded. |
Example:
mlkit_translation_get_downloaded_list(function(_success, _list, _error) {
if (_success) show_debug_message(_list);
});Requests the deletion of the provided translation model. The result is delivered to the callback.
Note
This function is only supported on Android and iOS.
This function operates asynchronously, which means that it does not immediately return the requested result. Instead, upon completion of the task, it will trigger the Callback.
Syntax:
mlkit_translation_model_delete(language, callback)
| Argument | Type | Description |
|---|---|---|
| language | String | The language model to be deleted. |
| callback | Function | The function called with the result (see below). |
Returns:
N/A
Triggers:
Triggered when the deletion request completes.
| Key | Type | Description |
|---|---|---|
| success | Boolean | Whether the deletion succeeded. |
| language | String | The language model that was targeted. |
| error | String or Undefined | The error message, or undefined if the request succeeded. |
Example:
mlkit_translation_model_delete("es", function(_success, _language, _error) {
show_debug_message("Delete " + _language + (_success ? ": ok" : ": " + _error));
});Requests the download of the provided translation model. The result is delivered to the callback.
Note
This function is only supported on Android and iOS.
This function operates asynchronously, which means that it does not immediately return the requested result. Instead, upon completion of the task, it will trigger the Callback.
Syntax:
mlkit_translation_model_download(language, callback)
| Argument | Type | Description |
|---|---|---|
| language | String | The language model to be downloaded. |
| callback | Function | The function called with the result (see below). |
Returns:
N/A
Triggers:
Triggered when the download request completes.
| Key | Type | Description |
|---|---|---|
| success | Boolean | Whether the download succeeded. |
| language | String | The language model that was targeted. |
| error | String or Undefined | The error message, or undefined if the request succeeded. |
Example:
mlkit_translation_model_download("es", function(_success, _language, _error) {
show_debug_message("Download " + _language + (_success ? ": ok" : ": " + _error));
});GameMaker 2026