Class TranslationsController.RuntimeTranslation

Enclosing class:

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


      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:

      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.

      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
      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 1869404 will add an option for deleting translations model "cache".

      options - contain language, operation, and operation level to perform on the model
      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.
      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 detected, it will return 0. Note, if the model is not present, this will also result in a value of 0 bytes.

      fromLanguage - from BCP 47 code
      toLanguage - from BCP 47 code
      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)
      pair - language pair that will be used by `translate()`
      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.
      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.
      languageCode - The BCP 47 language portion of the code to check the settings for. For example, es, en, de, etc.
      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.
      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.
      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.
      A GeckoResult that will return void if successful or else will complete exceptionally.
    • getNeverTranslateSiteList

      @AnyThread @NonNull public static GeckoResult<List<String>> getNeverTranslateSiteList()
      Gets the list of sites that have a never translate site preference set. Should be used for retrieving a list for global preference setting outside of a specific site.

      Recommend using: TranslationsController.SessionTranslation.getNeverTranslateSiteSetting() to query the current session's site's never translate preferences.

      A list of display ready site URIs to set preferences for.
    • setNeverTranslateSpecifiedSite

      @AnyThread @NonNull public static GeckoResult<Void> setNeverTranslateSpecifiedSite(@NonNull Boolean neverTranslate, @NonNull String origin)
      Sets whether the specified site should be translated or not. This function should be used for global updates to the never translate list.

      Please use: TranslationsController.SessionTranslation.setNeverTranslateSiteSetting(Boolean) when the session is currently on the site to adjust the permissions for.

      origin - A site origin URI that will have the specified never translate permission set. Recommend using URI values returned from getNeverTranslateSiteList() and using the session to set a given site to ensure proper scope when possible.
      neverTranslate - Should be set to true if the site should never be translated or false if it should be translated.
      Void if the operation to set the value completed or exceptionally if an issue occurred.