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
Modifier 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
ConstructorDescriptionSessionTranslation
(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 given language and criteria specified in the options.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 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 callingtranslate(String, String, TranslationOptions)
with a translation pair.- Parameters:
translationPair
- the object with a from and to languageoptions
- 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
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.
-