Package org.mozilla.geckoview
Class TranslationsController.SessionTranslation
Object
org.mozilla.geckoview.TranslationsController.SessionTranslation
- Enclosing class:
- TranslationsController
Session translation coordinates session messaging between the translations toolkit actor and
GeckoView.
Performs translations actions that are dependent on the page.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interface
The translations session delegate is used for receiving translation events and information.static class
DetectedLanguages is information that was detected about the page or user preferences.static class
Options available for translating.static class
Translation pair is the from language and to language set on the translation state.static class
The representation of the translation state. -
Constructor Summary
ConstructorsConstructorDescriptionSessionTranslation
(GeckoSession session) Construct a new translations session. -
Method Summary
Modifier and TypeMethodDescriptionorg.mozilla.geckoview.TranslationsController.SessionTranslation.Handler
Handler for receiving messages about translations.Gets the setting of the site for whether it should be translated or not.Restores a page to the original or pre-translated state.setNeverTranslateSiteSetting
(Boolean neverTranslate) Sets whether the site should be translated or not.translate
(String fromLanguage, String toLanguage, TranslationsController.SessionTranslation.TranslationOptions options) Translates the session's current page based on criteria.translate
(TranslationsController.SessionTranslation.TranslationPair translationPair, TranslationsController.SessionTranslation.TranslationOptions options) Convenience method for callingtranslate(String, String, TranslationOptions)
with a translation pair.
-
Constructor Details
-
SessionTranslation
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 criteria.Currently when translating, the necessary language models will be automatically downloaded.
ToDo: bug 1853055 will adjust this flow to add an option for automatic/non-automatic downloads.
- 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
- no-op, ToDo: bug 1853055 will add options- Returns:
- if 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 callingtranslate(String, String, TranslationOptions)
with a translation pair.- Parameters:
translationPair
- the object with a from and to languageoptions
- no-op, ToDo: bug 1853055 will add options- Returns:
- if translate process begins or exceptionally if an issue occurs.
-
restoreOriginalPage
Restores a page to the original or pre-translated state.- Returns:
- if page restoration process begins or exceptionally if an issue occurs.
-
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.
-