Skip to content

Commit

Permalink
Bug 1710546 - Firefox Translations integration r=mossop,mixedpuppy,mhoye
Browse files Browse the repository at this point in the history
Bundle Firefox Translation as a builtin pref'd off addon in Nightly only

Differential Revision: https://phabricator.services.mozilla.com/D114810
  • Loading branch information
andrenatal committed May 27, 2021
1 parent 65c295f commit 3d8a198
Show file tree
Hide file tree
Showing 33 changed files with 50,309 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -218,3 +218,6 @@ tools/update-packaging/**/*refs.js

# Ignore backgroundtasks preferences files.
toolkit/components/backgroundtasks/defaults

# Ignore pre-generated webpack and typescript transpiled files for translations
browser/extensions/translations/extension/
5 changes: 5 additions & 0 deletions browser/app/profile/firefox.js
Original file line number Diff line number Diff line change
Expand Up @@ -2583,3 +2583,8 @@ pref("first-startup.timeout", 30000);
// are expected to go away once a standardized alternative becomes
// available.
pref("svg.context-properties.content.allowed-domains", "profile.accounts.firefox.com,profile.stage.mozaws.net");

// Preference that allows individual users to disable Firefox Translations.
#ifdef NIGHTLY_BUILD
pref("extensions.translations.disabled", true);
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ if (AppConstants.MOZ_BACKGROUNDTASKS) {
gExceptionPaths.push("resource://gre/modules/backgroundtasks/");
}

// Bug 1710546 https://bugzilla.mozilla.org/show_bug.cgi?id=1710546
if (AppConstants.NIGHTLY_BUILD) {
gExceptionPaths.push("resource://builtin-addons/translations/");
}

// Each whitelist entry should have a comment indicating which file is
// referencing the whitelisted file in a way that the test can't detect, or a
// bug number to remove or use the file if it is indeed currently unreferenced.
Expand Down
32 changes: 32 additions & 0 deletions browser/components/BrowserGlue.jsm
Original file line number Diff line number Diff line change
Expand Up @@ -1975,6 +1975,35 @@ BrowserGlue.prototype = {
});
},

// Set up a listener to enable/disable the translation extension
// based on its preference.
_monitorTranslationsPref() {
const PREF = "extensions.translations.disabled";
const ID = "[email protected]";
const _checkTranslationsPref = async () => {
let addon = await AddonManager.getAddonByID(ID);
let disabled = Services.prefs.getBoolPref(PREF, false);
if (!addon && disabled) {
// not installed, bail out early.
return;
}
if (!disabled) {
// first time install of addon and install on firefox update
addon =
(await AddonManager.maybeInstallBuiltinAddon(
ID,
"0.4.0",
"resource://builtin-addons/translations/"
)) || addon;
await addon.enable();
} else if (addon) {
await addon.disable();
}
};
Services.prefs.addObserver(PREF, _checkTranslationsPref);
_checkTranslationsPref();
},

_monitorHTTPSOnlyPref() {
const PREF_ENABLED = "dom.security.https_only_mode";
const PREF_WAS_ENABLED = "dom.security.https_only_mode_ever_enabled";
Expand Down Expand Up @@ -2172,6 +2201,9 @@ BrowserGlue.prototype = {
this._monitorHTTPSOnlyPref();
this._monitorIonPref();
this._monitorIonStudies();
if (AppConstants.NIGHTLY_BUILD) {
this._monitorTranslationsPref();
}

FirefoxMonitor.init();
},
Expand Down
5 changes: 5 additions & 0 deletions browser/extensions/moz.build
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,8 @@ DIRS += [
"report-site-issue",
"pictureinpicture",
]

if CONFIG["NIGHTLY_BUILD"]:
DIRS += [
"translations",
]
20 changes: 20 additions & 0 deletions browser/extensions/translations/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
This folder contains the source files for Firefox Translations, which utilizes
the proceedings from Project Bergamot [1].

The feature is developed as a webextension [2] which utilizes a neural machine
translation decoder [3] ported to WebAssembly in order to process the
in page translation. The translation models [4] are downloaded on-demand by the
extension, so there's no need to bundle them too.

The folder `extension_src` contains the entire code of the extension's xpi and
the wasm module (which lies inside the folder wasm), and is automatically
generated by the `import_xpi.py` script, which is responsibile for cloning
the extension repo [2], build it, and generate the `jar.mn` package containing
all the pertinent files necessary for running it.

For any questions, reach out to [email protected].

[1] https://browser.mt/
[2] https://github.com/mozilla-extensions/bergamot-browser-extension
[3] https://github.com/mozilla/bergamot-translator/
[4] https://github.com/mozilla-applied-ml/bergamot-models
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{
"extensionName": {
"message": "Firefox Translations",
"description": "Name of the extension"
},
"extensionDescription": {
"message": "Neural Machine Translation for the browser.",
"description": "Description of the extension."
},
"currentlyDownloadingLanguageModel": {
"message": "Currently downloading language model",
"description": "Informs the user that the translations feature is currently downloading the language model files."
},
"detailedDownloadProgress": {
"message": "$PERCENTAGE$% out of $MB$ mb downloaded",
"description": "Informs the user how the language model file downloading is progressing.",
"placeholders": {
"percentage": {
"content": "$1",
"example": "50"
},
"mb": {
"content": "$2",
"example": "22.2"
}
}
},
"currentlyLoadingLanguageModel": {
"message": "Currently loading language model",
"description": "Informs the user that the translations feature is currently loading the language model files into memory."
},
"loadedLanguageModel": {
"message": "Language model loaded",
"description": "Informs the user that the translations feature is has loaded the language model files into memory."
},
"partsLeftToTranslate": {
"message": "Parts left to translate: $NUM$",
"description": "Informs the user that the translations feature has $NUM$ parts left to translate.",
"placeholders": {
"num": {
"content": "$1",
"example": "3"
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{
"extensionName": {
"message": "Traducciones de Firefox",
"description": "Name of the extension"
},
"extensionDescription": {
"message": "Traducción de la Máquina Neural para el navegador.",
"description": "Description of the extension."
},
"currentlyDownloadingLanguageModel": {
"message": "Actualmente descargando el modelo de idioma",
"description": "Informs the user that the translations feature is currently downloading the language model files."
},
"detailedDownloadProgress": {
"message": "$PERCENTAGE$% de $MB$ mb descargado",
"description": "Informs the user how the language model file downloading is progressing.",
"placeholders": {
"percentage": {
"content": "$1",
"example": "50"
},
"mb": {
"content": "$2",
"example": "22.2"
}
}
},
"currentlyLoadingLanguageModel": {
"message": "Actualmente cargar el modelo de idioma",
"description": "Informs the user that the translations feature is currently loading the language model files into memory."
},
"loadedLanguageModel": {
"message": "Modelo de lenguaje cargado",
"description": "Informs the user that the translations feature is has loaded the language model files into memory."
},
"partsLeftToTranslate": {
"message": "Partes que quedan para traducir: $NUM$",
"description": "Informs the user that the translations feature has $NUM$ parts left to translate.",
"placeholders": {
"num": {
"content": "$1",
"example": "3"
}
}
}
}
Loading

0 comments on commit 3d8a198

Please sign in to comment.