Game Maker Firebase ML Kit – Translate Extension

Game Maker Firebase ML Kit – Translate Extension allows you to translate sentences from one language to another by using Google’s Machine Learning Kit.

Since the AI models are downloaded into devices, they work offline as well; requiring NO internet connection.

Setup Firebase Tools for Game Maker Studio

Get Firebase Natural Languages Extension (Must be included)

To be able to use the extension, you must prepare Game Maker Studio 2 to be able to compile for it. Click the link above to complete it.
You must include Firebase ML Kit – Natural Languages Extension into your project! Without it, you cannot use any Natural Language based extension!

DOCUMENTATION

firebase_ml_translator_debug_mode(True/False debugMode);
Description
: Enables/Disables debug mode for the extension.
Returns : N/A

firebase_ml_translator_init();
Description
: Initializes Translator Extension
Returns : N/A

firebase_ml_translator_create(String translatorID, String sourceLanguageCode, String targetLanguageCode);
Description : Creates a Translator, which then be used for translating sentences. LanguageCodes here are provided as ISO 639-1 format. (DE, TR, EN, RU, FR etc..);
Returns : A Social Async Event
“category” = “ml_translator_create” (String)
“status” = true or false (Boolean)

If status returns as true, you can use translatorID in other functions. If it returns false, you cannot!
Notice that translation works on your the device, and it must download “Language Models” to the device. This function will check if the language model is downloaded before, otherwise automatically starts downloading them for you if you.If you wish to download them before, check the section below
firebase_ml_translator_init();
firebase_ml_translator_create("myTurkishEnglishTranslator","TR","EN");

firebase_ml_translator_remove(String translatorID);
Description
: Removes a translator from the memory.
Returns : N/A

firebase_ml_translator_translate(String translatorID, String text);
Description : Translates a text
Returns : A Social Async Event
“category” = “ml_translator_translate” (String)
“status” = true or false (Boolean)
“result” = Translation of the string (String)

firebase_ml_translator_translate("myTurkishEnglishTranslator","Bugün sana bir süpriz yapacağım. Seni çok seviyorum.");
//The above function will fire off a social async event with something like "I will make a suprise for you today. I love you very much" XD

In Social Async Event

var category = async_load[? "category"];

switch(category) 
{ 
	case "ml_translator_translate":
	var status = async_load[? "status"];
	
	if (status==true)	//Yes it is translated!
	{
		var result = async_load[? "result"];
		show_message_async("The text is translated as : " + 
string(result));
	}
	break;	
}

Predownloading Models

Remember that you must have language models downloaded before being able to use them. When you create a translator via firebase_ml_translator_create the extension automatically downloads them for you. However, you don’t want to keep your player on hold for this download process right? So you can predownload them.

firebase_ml_translator_predownload_model(String langCodeString);
Description
: Downloads a language model and stores it on the device.
Returns : A Social Async Event
“category” = “ml_translator_predownload” (String)
“language” = Language code of the model that’s downloaded. (String)
“status” = true of false (Boolean)

firebase_ml_translator_delete_model(String langCodeString);
Description
: Deletes a model from the device.
Returns : A Social Async Event
“category” = “ml_translator_predownload” (String)
“language” = Language code of the model that’s downloaded. (String) “status” = true of false (Boolean)

firebase_ml_translator_get_downloaded_models();
Description
: Returns all the available models on the device. All downloaded models are returned.
Returns : A Social Async Event
“category” = “ml_translator_downloaded_models” (String)
“total” = The total number of available models (Real)
“language[n]” = A language code. language[0], language[1], language[2] … (String)
“status” = true or false (Boolean)

GET THE EXTENSION
Share

Marty

Truely speaking, I don't know what am I doing most of the time.

Leave a Reply