Disables translation of forms if not supported by the model set (#432)
This commit is contained in:
Родитель
6ab1fe6e04
Коммит
c5970ade50
|
@ -1,3 +1,4 @@
|
|||
/* eslint-disable no-case-declarations */
|
||||
/* eslint-disable max-lines */
|
||||
/* global LanguageDetection, browser, PingSender, BERGAMOT_VERSION_FULL,
|
||||
Telemetry, loadFastText, FastText, Sentry, settings, deserializeError,
|
||||
|
@ -213,6 +214,14 @@ const messageListener = function(message, sender) {
|
|||
/*
|
||||
* request the experiments API do display the infobar
|
||||
*/
|
||||
|
||||
let from = "en".concat(message.languageDetection.pageLanguage);
|
||||
let to = message.languageDetection.navigatorLanguage.substring(0,2).concat("en");
|
||||
if (from === "enen") from = to;
|
||||
if (to === "enen") to = from;
|
||||
const isOutboundTranslationSupported = message.languageDetection.languagePairsSupportedSet.has(from) &&
|
||||
message.languageDetection.languagePairsSupportedSet.has(to);
|
||||
|
||||
await browser.experiments.translationbar.show(
|
||||
sender.tab.id,
|
||||
message.languageDetection.pageLanguage,
|
||||
|
@ -230,7 +239,8 @@ const messageListener = function(message, sender) {
|
|||
outboundtranslations: await browser.storage.local.get("outboundtranslations-check"),
|
||||
qualityestimations: await browser.storage.local.get("qualityestimations-check")
|
||||
},
|
||||
translateAsBrowseMap.get(sender.tab.id)?.translatingAsBrowse
|
||||
translateAsBrowseMap.get(sender.tab.id)?.translatingAsBrowse,
|
||||
isOutboundTranslationSupported
|
||||
);
|
||||
|
||||
// we then ask the api for the localized version of the language codes
|
||||
|
|
|
@ -82,7 +82,7 @@ const translationNotificationManagers = new Map();
|
|||
return {
|
||||
experiments: {
|
||||
translationbar: {
|
||||
show: function show(tabId, detectedLanguage, navigatorLanguage, localizedLabels, pageActionRequest, infobarSettings, autoTranslate) {
|
||||
show: function show(tabId, detectedLanguage, navigatorLanguage, localizedLabels, pageActionRequest, infobarSettings, autoTranslate, otSupported) {
|
||||
try {
|
||||
|
||||
const { tabManager } = context.extension;
|
||||
|
@ -173,6 +173,7 @@ const translationNotificationManagers = new Map();
|
|||
translationNotificationManager.localizedLabels = localizedLabels;
|
||||
translationNotificationManager.infobarSettings = infobarSettings;
|
||||
translationNotificationManager.autoTranslate = autoTranslate;
|
||||
translationNotificationManager.otSupported = otSupported;
|
||||
|
||||
notif.init(translationNotificationManager);
|
||||
translationNotificationManagers.set(tabId, translationNotificationManager);
|
||||
|
|
|
@ -42,6 +42,11 @@
|
|||
"name": "autoTranslate",
|
||||
"type": "any",
|
||||
"description": "determines if the auto translate is set"
|
||||
},
|
||||
{
|
||||
"name": "otSupported",
|
||||
"type": "any",
|
||||
"description": "represents if outbound translations is supported"
|
||||
}
|
||||
]
|
||||
},
|
||||
|
|
|
@ -60,12 +60,16 @@ window.MozTranslationNotification = class extends MozElements.Notification {
|
|||
init(translationNotificationManager) {
|
||||
// set icon in the infobar. we should move this to a css file.
|
||||
this._getAnonElt("logoIcon").setAttribute("src", translationNotificationManager.logoIcon);
|
||||
this._getAnonElt("outboundtranslations-check").setAttribute("label", translationNotificationManager.localizedLabels.outboundTranslationsMessage);
|
||||
this._getAnonElt("qualityestimations-check").setAttribute("label", translationNotificationManager.localizedLabels.qualityEstimationMessage);
|
||||
this._getAnonElt("displayStatistics").setAttribute("label", translationNotificationManager.localizedLabels.displayStatisticsMessage);
|
||||
this._getAnonElt("outboundtranslations-check").checked = translationNotificationManager.infobarSettings.outboundtranslations["outboundtranslations-check"];
|
||||
this._getAnonElt("qualityestimations-check").checked = translationNotificationManager.infobarSettings.qualityestimations["qualityestimations-check"];
|
||||
this._getAnonElt("translateAsBrowse").setAttribute("label", translationNotificationManager.localizedLabels.translateAsBrowseOn);
|
||||
if (translationNotificationManager.otSupported) {
|
||||
this._getAnonElt("outboundtranslations-check").setAttribute("label", translationNotificationManager.localizedLabels.outboundTranslationsMessage);
|
||||
this._getAnonElt("outboundtranslations-check").checked = translationNotificationManager.infobarSettings.outboundtranslations["outboundtranslations-check"];
|
||||
} else {
|
||||
this._getAnonElt("outboundtranslations-check").style.display = "none";
|
||||
}
|
||||
|
||||
this.translationNotificationManager = translationNotificationManager;
|
||||
this.localizedLanguagesByCode = {};
|
||||
|
|
Загрузка…
Ссылка в новой задаче