forked from mirrors/gecko-dev
Bug 1791178 - Convert DownloadUIHelper.sys.mjs to Fluent. r=Gijs,fluent-reviewers,flod
The downloadsFolder string is left in the downloads.properties file, at least for now, as it's also used from C++ code. Differential Revision: https://phabricator.services.mozilla.com/D158468
This commit is contained in:
parent
043b6e3eb8
commit
cfa546ca80
5 changed files with 279 additions and 104 deletions
187
python/l10n/fluent_migrations/bug_1791178_downloadUI.py
Normal file
187
python/l10n/fluent_migrations/bug_1791178_downloadUI.py
Normal file
|
|
@ -0,0 +1,187 @@
|
|||
# Any copyright is dedicated to the Public Domain.
|
||||
# http://creativecommons.org/publicdomain/zero/1.0/
|
||||
|
||||
import fluent.syntax.ast as FTL
|
||||
from fluent.migrate.helpers import VARIABLE_REFERENCE
|
||||
from fluent.migrate.transforms import COPY, REPLACE, Transform
|
||||
|
||||
|
||||
def migrate(ctx):
|
||||
"""Bug 1791178 - Convert DownloadUIHelper.jsm to Fluent, part {index}."""
|
||||
|
||||
source = "toolkit/chrome/mozapps/downloads/downloads.properties"
|
||||
target = "toolkit/toolkit/downloads/downloadUI.ftl"
|
||||
ctx.add_transforms(
|
||||
target,
|
||||
target,
|
||||
[
|
||||
FTL.Message(
|
||||
id=FTL.Identifier("download-ui-confirm-title"),
|
||||
value=COPY(source, "quitCancelDownloadsAlertTitle"),
|
||||
),
|
||||
FTL.Message(
|
||||
id=FTL.Identifier("download-ui-confirm-quit-cancel-downloads"),
|
||||
value=Transform.pattern_of(
|
||||
FTL.SelectExpression(
|
||||
selector=VARIABLE_REFERENCE("downloadsCount"),
|
||||
variants=[
|
||||
FTL.Variant(
|
||||
key=FTL.Identifier("1"),
|
||||
value=COPY(source, "quitCancelDownloadsAlertMsg"),
|
||||
),
|
||||
FTL.Variant(
|
||||
key=FTL.Identifier("other"),
|
||||
default=True,
|
||||
value=REPLACE(
|
||||
source,
|
||||
"quitCancelDownloadsAlertMsgMultiple",
|
||||
{"%1$S": VARIABLE_REFERENCE("downloadsCount")},
|
||||
),
|
||||
),
|
||||
],
|
||||
)
|
||||
),
|
||||
),
|
||||
FTL.Message(
|
||||
id=FTL.Identifier("download-ui-confirm-quit-cancel-downloads-mac"),
|
||||
value=Transform.pattern_of(
|
||||
FTL.SelectExpression(
|
||||
selector=VARIABLE_REFERENCE("downloadsCount"),
|
||||
variants=[
|
||||
FTL.Variant(
|
||||
key=FTL.Identifier("1"),
|
||||
value=COPY(source, "quitCancelDownloadsAlertMsgMac"),
|
||||
),
|
||||
FTL.Variant(
|
||||
key=FTL.Identifier("other"),
|
||||
default=True,
|
||||
value=REPLACE(
|
||||
source,
|
||||
"quitCancelDownloadsAlertMsgMacMultiple",
|
||||
{"%1$S": VARIABLE_REFERENCE("downloadsCount")},
|
||||
),
|
||||
),
|
||||
],
|
||||
)
|
||||
),
|
||||
),
|
||||
FTL.Message(
|
||||
id=FTL.Identifier("download-ui-confirm-offline-cancel-downloads"),
|
||||
value=Transform.pattern_of(
|
||||
FTL.SelectExpression(
|
||||
selector=VARIABLE_REFERENCE("downloadsCount"),
|
||||
variants=[
|
||||
FTL.Variant(
|
||||
key=FTL.Identifier("1"),
|
||||
value=COPY(source, "offlineCancelDownloadsAlertMsg"),
|
||||
),
|
||||
FTL.Variant(
|
||||
key=FTL.Identifier("other"),
|
||||
default=True,
|
||||
value=REPLACE(
|
||||
source,
|
||||
"offlineCancelDownloadsAlertMsgMultiple",
|
||||
{"%1$S": VARIABLE_REFERENCE("downloadsCount")},
|
||||
),
|
||||
),
|
||||
],
|
||||
)
|
||||
),
|
||||
),
|
||||
FTL.Message(
|
||||
id=FTL.Identifier(
|
||||
"download-ui-confirm-leave-private-browsing-windows-cancel-downloads"
|
||||
),
|
||||
value=Transform.pattern_of(
|
||||
FTL.SelectExpression(
|
||||
selector=VARIABLE_REFERENCE("downloadsCount"),
|
||||
variants=[
|
||||
FTL.Variant(
|
||||
key=FTL.Identifier("1"),
|
||||
value=COPY(
|
||||
source,
|
||||
"leavePrivateBrowsingWindowsCancelDownloadsAlertMsg2",
|
||||
),
|
||||
),
|
||||
FTL.Variant(
|
||||
key=FTL.Identifier("other"),
|
||||
default=True,
|
||||
value=REPLACE(
|
||||
source,
|
||||
"leavePrivateBrowsingWindowsCancelDownloadsAlertMsgMultiple2",
|
||||
{"%1$S": VARIABLE_REFERENCE("downloadsCount")},
|
||||
),
|
||||
),
|
||||
],
|
||||
)
|
||||
),
|
||||
),
|
||||
FTL.Message(
|
||||
id=FTL.Identifier("download-ui-cancel-downloads-ok"),
|
||||
value=Transform.pattern_of(
|
||||
FTL.SelectExpression(
|
||||
selector=VARIABLE_REFERENCE("downloadsCount"),
|
||||
variants=[
|
||||
FTL.Variant(
|
||||
key=FTL.Identifier("1"),
|
||||
value=COPY(source, "cancelDownloadsOKText"),
|
||||
),
|
||||
FTL.Variant(
|
||||
key=FTL.Identifier("other"),
|
||||
default=True,
|
||||
value=REPLACE(
|
||||
source,
|
||||
"cancelDownloadsOKTextMultiple",
|
||||
{"%1$S": VARIABLE_REFERENCE("downloadsCount")},
|
||||
),
|
||||
),
|
||||
],
|
||||
)
|
||||
),
|
||||
),
|
||||
FTL.Message(
|
||||
id=FTL.Identifier("download-ui-dont-quit-button"),
|
||||
value=Transform.pattern_of(
|
||||
FTL.SelectExpression(
|
||||
selector=FTL.FunctionReference(
|
||||
id=FTL.Identifier("PLATFORM"), arguments=FTL.CallArguments()
|
||||
),
|
||||
variants=[
|
||||
FTL.Variant(
|
||||
key=FTL.Identifier("mac"),
|
||||
value=COPY(source, "dontQuitButtonMac"),
|
||||
),
|
||||
FTL.Variant(
|
||||
key=FTL.Identifier("other"),
|
||||
default=True,
|
||||
value=COPY(source, "dontQuitButtonWin"),
|
||||
),
|
||||
],
|
||||
)
|
||||
),
|
||||
),
|
||||
FTL.Message(
|
||||
id=FTL.Identifier("download-ui-dont-go-offline-button"),
|
||||
value=COPY(source, "dontGoOfflineButton"),
|
||||
),
|
||||
FTL.Message(
|
||||
id=FTL.Identifier("download-ui-dont-leave-private-browsing-button"),
|
||||
value=COPY(source, "dontLeavePrivateBrowsingButton2"),
|
||||
),
|
||||
FTL.Message(
|
||||
id=FTL.Identifier("download-ui-file-executable-security-warning-title"),
|
||||
value=COPY(source, "fileExecutableSecurityWarningTitle"),
|
||||
),
|
||||
FTL.Message(
|
||||
id=FTL.Identifier("download-ui-file-executable-security-warning"),
|
||||
value=REPLACE(
|
||||
source,
|
||||
"fileExecutableSecurityWarning",
|
||||
{
|
||||
"%1$S": VARIABLE_REFERENCE("executable"),
|
||||
"%2$S": VARIABLE_REFERENCE("executable"),
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
)
|
||||
|
|
@ -83,6 +83,12 @@ XPCOMUtils.defineLazyGetter(lazy, "gCombinedDownloadIntegration", () => {
|
|||
return lazy.DownloadIntegration;
|
||||
});
|
||||
|
||||
XPCOMUtils.defineLazyGetter(lazy, "stringBundle", () =>
|
||||
Services.strings.createBundle(
|
||||
"chrome://mozapps/locale/downloads/downloads.properties"
|
||||
)
|
||||
);
|
||||
|
||||
const Timer = Components.Constructor(
|
||||
"@mozilla.org/timer;1",
|
||||
"nsITimer",
|
||||
|
|
@ -887,7 +893,7 @@ export var DownloadIntegration = {
|
|||
// displayed in the user interface.
|
||||
let directoryPath = PathUtils.join(
|
||||
this._getDirectory(aName),
|
||||
lazy.DownloadUIHelper.strings.downloadsFolder
|
||||
lazy.stringBundle.GetStringFromName("downloadsFolder")
|
||||
);
|
||||
|
||||
// Create the Downloads folder and ignore if it already exists.
|
||||
|
|
|
|||
|
|
@ -11,8 +11,6 @@ import { AppConstants } from "resource://gre/modules/AppConstants.sys.mjs";
|
|||
|
||||
const lazy = {};
|
||||
|
||||
ChromeUtils.defineModuleGetter(lazy, "OS", "resource://gre/modules/osfile.jsm");
|
||||
|
||||
// BrowserWindowTracker and PrivateBrowsingUtils are only used when opening downloaded files into a browser window
|
||||
ChromeUtils.defineESModuleGetters(lazy, {
|
||||
PrivateBrowsingUtils: "resource://gre/modules/PrivateBrowsingUtils.sys.mjs",
|
||||
|
|
@ -22,17 +20,11 @@ XPCOMUtils.defineLazyModuleGetters(lazy, {
|
|||
BrowserWindowTracker: "resource:///modules/BrowserWindowTracker.jsm",
|
||||
});
|
||||
|
||||
const kStringBundleUrl =
|
||||
"chrome://mozapps/locale/downloads/downloads.properties";
|
||||
|
||||
const kStringsRequiringFormatting = {
|
||||
fileExecutableSecurityWarning: true,
|
||||
cancelDownloadsOKTextMultiple: true,
|
||||
quitCancelDownloadsAlertMsgMultiple: true,
|
||||
quitCancelDownloadsAlertMsgMacMultiple: true,
|
||||
offlineCancelDownloadsAlertMsgMultiple: true,
|
||||
leavePrivateBrowsingWindowsCancelDownloadsAlertMsgMultiple2: true,
|
||||
};
|
||||
XPCOMUtils.defineLazyGetter(
|
||||
lazy,
|
||||
"l10n",
|
||||
() => new Localization(["toolkit/downloads/downloadUI.ftl"], true)
|
||||
);
|
||||
|
||||
/**
|
||||
* Provides functions to handle status and messages in the user interface.
|
||||
|
|
@ -127,28 +119,6 @@ export var DownloadUIHelper = {
|
|||
},
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns an object whose keys are the string names from the downloads string
|
||||
* bundle, and whose values are either the translated strings or functions
|
||||
* returning formatted strings.
|
||||
*/
|
||||
XPCOMUtils.defineLazyGetter(DownloadUIHelper, "strings", function() {
|
||||
let strings = {};
|
||||
let sb = Services.strings.createBundle(kStringBundleUrl);
|
||||
for (let string of sb.getSimpleEnumeration()) {
|
||||
let stringName = string.key;
|
||||
if (stringName in kStringsRequiringFormatting) {
|
||||
strings[stringName] = function() {
|
||||
// Convert "arguments" to a real array before calling into XPCOM.
|
||||
return sb.formatStringFromName(stringName, Array.from(arguments));
|
||||
};
|
||||
} else {
|
||||
strings[stringName] = string.value;
|
||||
}
|
||||
}
|
||||
return strings;
|
||||
});
|
||||
|
||||
/**
|
||||
* Allows displaying prompts related to downloads.
|
||||
*
|
||||
|
|
@ -198,13 +168,14 @@ DownloadPrompter.prototype = {
|
|||
// If the preference does not exist, continue with the prompt.
|
||||
}
|
||||
|
||||
let leafName = lazy.OS.Path.basename(path);
|
||||
|
||||
let s = DownloadUIHelper.strings;
|
||||
return this._prompter.confirm(
|
||||
s.fileExecutableSecurityWarningTitle,
|
||||
s.fileExecutableSecurityWarning(leafName, leafName)
|
||||
const title = lazy.l10n.formatValueSync(
|
||||
"download-ui-file-executable-security-warning-title"
|
||||
);
|
||||
const message = lazy.l10n.formatValueSync(
|
||||
"download-ui-file-executable-security-warning",
|
||||
{ executable: PathUtils.filename(path) }
|
||||
);
|
||||
return this._prompter.confirm(title, message);
|
||||
},
|
||||
|
||||
/**
|
||||
|
|
@ -229,59 +200,41 @@ DownloadPrompter.prototype = {
|
|||
return false;
|
||||
}
|
||||
|
||||
let s = DownloadUIHelper.strings;
|
||||
let buttonFlags =
|
||||
Ci.nsIPrompt.BUTTON_TITLE_IS_STRING * Ci.nsIPrompt.BUTTON_POS_0 +
|
||||
Ci.nsIPrompt.BUTTON_TITLE_IS_STRING * Ci.nsIPrompt.BUTTON_POS_1;
|
||||
let okButton =
|
||||
aDownloadsCount > 1
|
||||
? s.cancelDownloadsOKTextMultiple(aDownloadsCount)
|
||||
: s.cancelDownloadsOKText;
|
||||
let title, message, cancelButton;
|
||||
let message, cancelButton;
|
||||
|
||||
switch (aPromptType) {
|
||||
case this.ON_QUIT:
|
||||
title = s.quitCancelDownloadsAlertTitle;
|
||||
if (AppConstants.platform != "macosx") {
|
||||
message =
|
||||
aDownloadsCount > 1
|
||||
? s.quitCancelDownloadsAlertMsgMultiple(aDownloadsCount)
|
||||
: s.quitCancelDownloadsAlertMsg;
|
||||
cancelButton = s.dontQuitButtonWin;
|
||||
} else {
|
||||
message =
|
||||
aDownloadsCount > 1
|
||||
? s.quitCancelDownloadsAlertMsgMacMultiple(aDownloadsCount)
|
||||
: s.quitCancelDownloadsAlertMsgMac;
|
||||
cancelButton = s.dontQuitButtonMac;
|
||||
}
|
||||
AppConstants.platform == "macosx"
|
||||
? "download-ui-confirm-quit-cancel-downloads-mac"
|
||||
: "download-ui-confirm-quit-cancel-downloads";
|
||||
cancelButton = "download-ui-dont-quit-button";
|
||||
break;
|
||||
|
||||
case this.ON_OFFLINE:
|
||||
title = s.offlineCancelDownloadsAlertTitle;
|
||||
message =
|
||||
aDownloadsCount > 1
|
||||
? s.offlineCancelDownloadsAlertMsgMultiple(aDownloadsCount)
|
||||
: s.offlineCancelDownloadsAlertMsg;
|
||||
cancelButton = s.dontGoOfflineButton;
|
||||
message = "download-ui-confirm-offline-cancel-downloads";
|
||||
cancelButton = "download-ui-dont-go-offline-button";
|
||||
break;
|
||||
|
||||
case this.ON_LEAVE_PRIVATE_BROWSING:
|
||||
title = s.leavePrivateBrowsingCancelDownloadsAlertTitle;
|
||||
message =
|
||||
aDownloadsCount > 1
|
||||
? s.leavePrivateBrowsingWindowsCancelDownloadsAlertMsgMultiple2(
|
||||
aDownloadsCount
|
||||
)
|
||||
: s.leavePrivateBrowsingWindowsCancelDownloadsAlertMsg2;
|
||||
cancelButton = s.dontLeavePrivateBrowsingButton2;
|
||||
"download-ui-confirm-leave-private-browsing-windows-cancel-downloads";
|
||||
cancelButton = "download-ui-dont-leave-private-browsing-button";
|
||||
break;
|
||||
}
|
||||
|
||||
const buttonFlags =
|
||||
Ci.nsIPrompt.BUTTON_TITLE_IS_STRING * Ci.nsIPrompt.BUTTON_POS_0 +
|
||||
Ci.nsIPrompt.BUTTON_TITLE_IS_STRING * Ci.nsIPrompt.BUTTON_POS_1;
|
||||
|
||||
let rv = this._prompter.confirmEx(
|
||||
title,
|
||||
message,
|
||||
lazy.l10n.formatValueSync("download-ui-confirm-title"),
|
||||
lazy.l10n.formatValueSync(message, { downloadsCount: aDownloadsCount }),
|
||||
buttonFlags,
|
||||
okButton,
|
||||
cancelButton,
|
||||
lazy.l10n.formatValueSync("download-ui-cancel-downloads-ok", {
|
||||
downloadsCount: aDownloadsCount,
|
||||
}),
|
||||
lazy.l10n.formatValueSync(cancelButton),
|
||||
null,
|
||||
null,
|
||||
{}
|
||||
|
|
|
|||
|
|
@ -2,27 +2,5 @@
|
|||
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
|
||||
# LOCALIZATION NOTE: we don't have proper plural support in the CPP code; bug 463102
|
||||
quitCancelDownloadsAlertTitle=Cancel All Downloads?
|
||||
quitCancelDownloadsAlertMsg=If you exit now, 1 download will be canceled. Are you sure you want to exit?
|
||||
quitCancelDownloadsAlertMsgMultiple=If you exit now, %S downloads will be canceled. Are you sure you want to exit?
|
||||
quitCancelDownloadsAlertMsgMac=If you quit now, 1 download will be canceled. Are you sure you want to quit?
|
||||
quitCancelDownloadsAlertMsgMacMultiple=If you quit now, %S downloads will be canceled. Are you sure you want to quit?
|
||||
offlineCancelDownloadsAlertTitle=Cancel All Downloads?
|
||||
offlineCancelDownloadsAlertMsg=If you go offline now, 1 download will be canceled. Are you sure you want to go offline?
|
||||
offlineCancelDownloadsAlertMsgMultiple=If you go offline now, %S downloads will be canceled. Are you sure you want to go offline?
|
||||
leavePrivateBrowsingCancelDownloadsAlertTitle=Cancel All Downloads?
|
||||
leavePrivateBrowsingWindowsCancelDownloadsAlertMsg2=If you close all Private Browsing windows now, 1 download will be canceled. Are you sure you want to leave Private Browsing?
|
||||
leavePrivateBrowsingWindowsCancelDownloadsAlertMsgMultiple2=If you close all Private Browsing windows now, %S downloads will be canceled. Are you sure you want to leave Private Browsing?
|
||||
cancelDownloadsOKText=Cancel 1 Download
|
||||
cancelDownloadsOKTextMultiple=Cancel %S Downloads
|
||||
dontQuitButtonWin=Don’t Exit
|
||||
dontQuitButtonMac=Don’t Quit
|
||||
dontGoOfflineButton=Stay Online
|
||||
dontLeavePrivateBrowsingButton2=Stay in Private Browsing
|
||||
|
||||
fileExecutableSecurityWarning=“%S” is an executable file. Executable files may contain viruses or other malicious code that could harm your computer. Use caution when opening this file. Are you sure you want to launch “%S”?
|
||||
fileExecutableSecurityWarningTitle=Open Executable File?
|
||||
|
||||
# Desktop folder name for downloaded files
|
||||
downloadsFolder=Downloads
|
||||
|
|
|
|||
51
toolkit/locales/en-US/toolkit/downloads/downloadUI.ftl
Normal file
51
toolkit/locales/en-US/toolkit/downloads/downloadUI.ftl
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
# This Source Code Form is subject to the terms of the Mozilla Public
|
||||
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
|
||||
download-ui-confirm-title = Cancel All Downloads?
|
||||
|
||||
## Variables:
|
||||
## $downloadsCount (Number): The current downloads count.
|
||||
|
||||
download-ui-confirm-quit-cancel-downloads =
|
||||
{ $downloadsCount ->
|
||||
[1] If you exit now, 1 download will be canceled. Are you sure you want to exit?
|
||||
*[other] If you exit now, { $downloadsCount } downloads will be canceled. Are you sure you want to exit?
|
||||
}
|
||||
download-ui-confirm-quit-cancel-downloads-mac =
|
||||
{ $downloadsCount ->
|
||||
[1] If you quit now, 1 download will be canceled. Are you sure you want to quit?
|
||||
*[other] If you quit now, { $downloadsCount } downloads will be canceled. Are you sure you want to quit?
|
||||
}
|
||||
download-ui-dont-quit-button =
|
||||
{ PLATFORM() ->
|
||||
[mac] Don’t Quit
|
||||
*[other] Don’t Exit
|
||||
}
|
||||
|
||||
download-ui-confirm-offline-cancel-downloads =
|
||||
{ $downloadsCount ->
|
||||
[1] If you go offline now, 1 download will be canceled. Are you sure you want to go offline?
|
||||
*[other] If you go offline now, { $downloadsCount } downloads will be canceled. Are you sure you want to go offline?
|
||||
}
|
||||
download-ui-dont-go-offline-button = Stay Online
|
||||
|
||||
download-ui-confirm-leave-private-browsing-windows-cancel-downloads =
|
||||
{ $downloadsCount ->
|
||||
[1] If you close all Private Browsing windows now, 1 download will be canceled. Are you sure you want to leave Private Browsing?
|
||||
*[other] If you close all Private Browsing windows now, { $downloadsCount } downloads will be canceled. Are you sure you want to leave Private Browsing?
|
||||
}
|
||||
download-ui-dont-leave-private-browsing-button = Stay in Private Browsing
|
||||
|
||||
download-ui-cancel-downloads-ok =
|
||||
{ $downloadsCount ->
|
||||
[1] Cancel 1 Download
|
||||
*[other] Cancel { $downloadsCount } Downloads
|
||||
}
|
||||
|
||||
##
|
||||
|
||||
download-ui-file-executable-security-warning-title = Open Executable File?
|
||||
# Variables:
|
||||
# $executable (String): The executable file to be opened.
|
||||
download-ui-file-executable-security-warning = “{ $executable }” is an executable file. Executable files may contain viruses or other malicious code that could harm your computer. Use caution when opening this file. Are you sure you want to launch “{ $executable }”?
|
||||
Loading…
Reference in a new issue