Class TranslationsController.RuntimeTranslation

Object
org.mozilla.geckoview.TranslationsController.RuntimeTranslation
Enclosing class:
TranslationsController

public static class TranslationsController.RuntimeTranslation extends Object
Runtime translation coordinates runtime messaging between the translations toolkit actor and GeckoView.

Performs translations actions that are not dependent on the page. Typical usage is for setting preferences, managing downloads, and getting information on language models available.

  • Field Details

    • DOWNLOAD

      public static final String DOWNLOAD
      The download operation is for downloading models.
      See Also:
    • DELETE

      public static final String DELETE
      The delete operation is for deleting models.
      See Also:
    • LANGUAGE

      public static final String LANGUAGE
      The language type indicates the operation should be performed only on the specified language.
      See Also:
    • CACHE

      public static final String CACHE
      The cache type indicates that the operation should be performed on model files that do not make up a suit.
      See Also:
    • ALL

      public static final String ALL
      The all type indicates that the operation should be performed on all model files
      See Also:
    • ALWAYS

      public static final String ALWAYS
      The translations engine should always expect this language to be translated and automatically translate on page load.
      See Also:
    • OFFER

      public static final String OFFER
      The translations engine should offer this language to be translated. This is the default state, i.e., no user selection was made.
      See Also:
    • NEVER

      public static final String NEVER
      The translations engine should never offer to translate this language.
      See Also:
  • Constructor Details

    • RuntimeTranslation

      public RuntimeTranslation()
  • Method Details

    • isTranslationsEngineSupported

      @AnyThread @NonNull public static GeckoResult<Boolean> isTranslationsEngineSupported()
      Checks if the device can use the supplied model binary files for translations.

      Use to check if translations are ever possible.

      Returns:
      true if translations are supported on the device, or false if not.
    • preferredLanguages

      @AnyThread @NonNull public static GeckoResult<List<String>> preferredLanguages()
      Returns the preferred languages of the user in the following order: 1. App languages 2. Web requested languages 3. OS language
      Returns:
      a GeckoResult with a user's preferred language(s) or null or an exception
    • manageLanguageModel

      @AnyThread @NonNull public static GeckoResult<Void> manageLanguageModel(@NonNull TranslationsController.RuntimeTranslation.ModelManagementOptions options)
      Manage the language model or models. Options are to download or delete a BCP 47 language or all or cache.

      Bug 1854691 will add an option for deleting translations model "cache".

      Parameters:
      options - contain language, operation, and operation level to perform on the model
      Returns:
      the request proceeded as expected or an exception.
    • listSupportedLanguages

      @AnyThread @NonNull public static GeckoResult<TranslationsController.RuntimeTranslation.TranslationSupport> listSupportedLanguages()
      List languages that can be translated to and from. Use is populating language selection.
      Returns:
      a GeckoResult with a TranslationSupport object with "to" and "from" languages or an exception.
    • checkPairDownloadSize

      @AnyThread @NonNull public static GeckoResult<Long> checkPairDownloadSize(@NonNull String fromLanguage, @NonNull String toLanguage)
      When `translate()` is called on a given pair, then the system will downloaded the necessary models to complete the translation. This method is to check the exact size of those downloads. Typical case is informing the user of the download size for users in a low-data mode.

      If no download is required, will return 0.

      Will be implemented in bug 1854691.

      Parameters:
      fromLanguage - from BCP 47 code
      toLanguage - from BCP 47 code
      Returns:
      The size of the file size in bytes. If no download is required, will return 0.
    • checkPairDownloadSize

      @AnyThread @NonNull public static GeckoResult<Long> checkPairDownloadSize(@NonNull TranslationsController.SessionTranslation.TranslationPair pair)
      Parameters:
      pair - language pair that will be used by `translate()`
      Returns:
      The size of the necessary file size in bytes. If no download is required, will return 0.
    • listModelDownloadStates

      @AnyThread @NonNull public static GeckoResult<List<TranslationsController.RuntimeTranslation.LanguageModel>> listModelDownloadStates()
      Creates a list of all of the available language models, their size for a full download, and download state. Expected use is for displaying model state for user management.
      Returns:
      A GeckoResult with a list of the available language model's and their states or an exception.
    • getLanguageSetting

      @AnyThread @NonNull public static GeckoResult<String> getLanguageSetting(@NonNull String languageCode)
      Returns the given language setting for the corresponding language.
      Parameters:
      languageCode - The BCP 47 language portion of the code to check the settings for. For example, es, en, de, etc.
      Returns:
      The TranslationsController.RuntimeTranslation.LanguageSetting string for the language.
    • getLanguageSettings

      @AnyThread @NonNull public static GeckoResult<Map<String,String>> getLanguageSettings()
      Creates a map of known language codes with their corresponding language setting.
      Returns:
      A GeckoResult with a map of each BCP 47 language portion of the code (key) and its corresponding TranslationsController.RuntimeTranslation.LanguageSetting string (value).
    • setLanguageSettings

      @AnyThread @NonNull public static GeckoResult<Void> setLanguageSettings(@NonNull String languageCode, @NonNull String languageSetting)
      Sets the language state for a given language.
      Parameters:
      languageCode - - The specified BCP 47 language portion of the code to update. For example, es, en, de, etc.
      languageSetting - - The specified setting for a given language.
      Returns:
      A GeckoResult that will return void if successful or else will complete exceptionally.