Class TranslationsController.SessionTranslation

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

public static class TranslationsController.SessionTranslation extends Object
Session translation coordinates session messaging between the translations toolkit actor and GeckoView.

Performs translations actions that are dependent on the page.

  • Constructor Details

    • SessionTranslation

      public SessionTranslation(GeckoSession session)
      Construct a new translations session.
      Parameters:
      session - that will be dispatching and receiving events.
  • Method Details

    • getHandler

      @AnyThread @NonNull public org.mozilla.geckoview.TranslationsController.SessionTranslation.Handler getHandler()
      Handler for receiving messages about translations.
      Returns:
      associated session handler
    • translate

      @AnyThread @NonNull public GeckoResult<Void> translate(@NonNull String fromLanguage, @NonNull String toLanguage, @Nullable TranslationsController.SessionTranslation.TranslationOptions options)
      Translates the session's current page based on given language and criteria specified in the options.
      Parameters:
      fromLanguage - BCP 47 language tag that the page should be translated from. Usually will be the suggested detected language or user specified.
      toLanguage - BCP 47 language tag that the page should be translated to. Usually will be the suggested preference language or user specified.
      options - If downloadModel is set to true, then any background downloads will occur automatically. If downloadModel is set to false, then if any background downloads are required, then the request will fail with an exception, but will continue if the model is already present.
      Returns:
      Void if the translate process begins or exceptionally if an issue occurs.
    • translate

      @AnyThread @NonNull public GeckoResult<Void> translate(@NonNull TranslationsController.SessionTranslation.TranslationPair translationPair, @Nullable TranslationsController.SessionTranslation.TranslationOptions options)
      Convenience method for calling translate(String, String, TranslationOptions) with a translation pair.
      Parameters:
      translationPair - the object with a from and to language
      options - If downloadModel is set to true, then any background downloads will occur automatically. If downloadModel is set to false, then if any background downloads are required, then the request will fail, but will continue if the model is already present.
      Returns:
      Void if the translate process begins or exceptionally if an issue occurs.
    • restoreOriginalPage

      @AnyThread @NonNull public GeckoResult<Void> restoreOriginalPage()
      Restores a page to the original or pre-translated state.
      Returns:
      if page restoration process begins or exceptionally if an issue occurs.
    • getNeverTranslateSiteSetting

      @AnyThread @NonNull public GeckoResult<Boolean> getNeverTranslateSiteSetting()
      Gets the setting of the site for whether it should be translated or not.
      Returns:
      The site setting for the page or exceptionally if an issue occurs.
    • setNeverTranslateSiteSetting

      @AnyThread @NonNull public GeckoResult<Void> setNeverTranslateSiteSetting(@NonNull Boolean neverTranslate)
      Sets whether the site should be translated or not.
      Parameters:
      neverTranslate - Should be set to true if the site should never be translated or false if it should be translated.
      Returns:
      Void if the operation to set the value completed or exceptionally if an issue occurred.