Skip to content

Provides easier access to Google ML Kits Translation API for .NET MAUI.

License

Notifications You must be signed in to change notification settings

Jake-Derrick/MLKit.Maui.Translate

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MLKit.Maui.Translate

Provides easier access to Google ML Kits Translation API for .NET MAUI.

TranslationExample

How to use it?

  1. Install the NuGet package
Install-Package MLKit.Maui.Translate
  1. Initialize the Translation Service in MauiProgram.cs.
var builder = MauiApp.CreateBuilder()
    .UseMauiApp<App>()

builder.Services.AddTranslationService();
  1. Use the service to download language models and translate text.
private readonly ITranslationService _translationService;

public TranslationExampleViewModel(ITranslationService translationService)
{
    _translationService = translationService;
}

public async Task DownloadModel()
{
    // The language models need to be downloaded before calling Translate
    DownloadResult result = await _translationService.DownloadLanguageModel(Languages.Spanish, DownloadOptions.Default);
}

public async Task TranslateText()
{
    TranslationResult translationResult = await _translationService.Translate("The text to translate", sourceLanguage: Languages.English, targetLanguage: Languages.Spanish);
    string translatedText = translationResult.TranslatedText;
}
  1. Deleting Language Models
public async Task DeleteModel()
{
    List<Language> downloadedLanguages = await _translationService.GetDownloadedLanguageModels();

    if (downloadedLanguages.Contains(Languages.Spanish))
      DeleteResult deleteResult = await _translationService.DeleteLanguageModel(Languages.Spanish);
}

More Info

About

Provides easier access to Google ML Kits Translation API for .NET MAUI.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages