Now, off to the actual stuff! Let’s see what the package can do for you.

The package can identify the language of a supplied String returning a list of LanguageLabel objects, or translate a supplied String into another language.

Using the LanguageIdentifier

Step 1 — Create an instance of a language identifier

final LanguageIdentifier languageIdentifier = FirebaseLanguage.instance.languageIdentifier()

Step 2 — Call processText(String) with languageIdentifier

final List<LanguageLabel> labels = await languageIdentifier.processText(‘Sample Text’);

This returns List<LanguageLabel> in decreasing order of probability of detected language.

Step 3 — Extract data

<LanguageLabel> contains the language names and confidence of the prediction, accessible like so —

for (LanguageLabel label in labels) {

final String text = label.text;

final double confidence = label.confidence;

}

Using the Language Translator

Note — Optionally, get an instance of ModelManager , and download the needed translation models beforehand to ensure a quick first-use.

FirebaseLanguage.instance.modelManager().downloadModel(SupportedLanguages.lang);

Step 1 — Create an instance of a language translator

final FirebaseLanguage.instance.languageTranslator(SupportedLanguages.lang, SupportedLanguages.lang);

Step 2 — Call processText(String) with languageTranslator

final String translatedString = await languageTranslator.processText(‘Sample Text’);

This returns a string containing the text translated to the target language.

Using the Model Manager

Step 1 — Create an instance of a model manager

final ModelManager modelManager = FirebaseLanguage.instance.modelManager()

Download Model

modelManager.downloadModel(SupportedLanguages.lang)

This downloads the specified model to the device’s local storage. It is recommended to download all the models needed to be used before translating to ensure a fast first-use. On a successful download, the string “Downloaded” will be returned.

Delete Model

modelManager.deleteModel(SupportedLanguages.lang)

This deletes the specified model from the device’s local storage. On a successful delete, the string “Deleted” will be returned. If the model specified is not present on the device, the string “Model not downloaded” will be returned.

View Models

modelManager.viewModels()

This returns a list of the BCP-47 language codes of all the language models downloaded onto the local storage of the device.

As always, feel free to open an issue there if you run into trouble or hit me up in the comments. Thanks again for listening!