Bug 1760029 - Migrate tabbrowser.properties strings used by tabbrowser.js to Fluent. r=dao,fluent-reviewers,flod

Differential Revision: https://phabricator.services.mozilla.com/D159016
This commit is contained in:
Eemeli Aro 2022-11-22 17:12:21 +00:00
parent 1b39667206
commit d413d67601
4 changed files with 336 additions and 147 deletions

View File

@ -35,6 +35,9 @@
"nsIMacSharingService",
],
});
XPCOMUtils.defineLazyGetter(this, "tabLocalization", () => {
return new Localization(["browser/tabbrowser.ftl"], true);
});
if (AppConstants.MOZ_CRASHREPORTER) {
ChromeUtils.defineModuleGetter(
@ -3194,26 +3197,25 @@
// solve the problem of windows "obscuring" the prompt.
// see bug #350299 for more details
window.focus();
let warningTitle = gTabBrowserBundle.GetStringFromName(
"tabs.closeTabsTitle"
);
warningTitle = PluralForm.get(tabsToClose, warningTitle).replace(
"#1",
tabsToClose
);
const [title, button, checkbox] = this.tabLocalization.formatValuesSync([
{
id: "tabbrowser-confirm-close-tabs-title",
args: { tabCount: tabsToClose },
},
{ id: "tabbrowser-confirm-close-tabs-button" },
{ id: "tabbrowser-confirm-close-tabs-checkbox" },
]);
let flags =
ps.BUTTON_TITLE_IS_STRING * ps.BUTTON_POS_0 +
ps.BUTTON_TITLE_CANCEL * ps.BUTTON_POS_1;
let checkboxLabel =
aCloseTabs == this.closingTabsEnum.ALL
? gTabBrowserBundle.GetStringFromName("tabs.closeTabsConfirmCheckbox")
: null;
aCloseTabs == this.closingTabsEnum.ALL ? checkbox : null;
var buttonPressed = ps.confirmEx(
window,
warningTitle,
title,
null,
flags,
gTabBrowserBundle.GetStringFromName("tabs.closeButtonMultiple"),
button,
null,
null,
checkboxLabel,
@ -5463,19 +5465,26 @@
try {
this._awaitingToggleCaretBrowsingPrompt = true;
const [
title,
message,
checkbox,
] = this.tabLocalization.formatValuesSync([
"tabbrowser-confirm-caretbrowsing-title",
"tabbrowser-confirm-caretbrowsing-message",
"tabbrowser-confirm-caretbrowsing-checkbox",
]);
var buttonPressed = promptService.confirmEx(
window,
gTabBrowserBundle.GetStringFromName(
"browsewithcaret.checkWindowTitle"
),
gTabBrowserBundle.GetStringFromName("browsewithcaret.checkLabel"),
title,
message,
// Make "No" the default:
promptService.STD_YES_NO_BUTTONS |
promptService.BUTTON_POS_1_DEFAULT,
null,
null,
null,
gTabBrowserBundle.GetStringFromName("browsewithcaret.checkMsg"),
checkbox,
checkValue
);
} catch (ex) {
@ -5576,12 +5585,12 @@
}
}
if (tab.userContextId) {
label = gTabBrowserBundle.formatStringFromName(
"tabs.containers.tooltip",
[
label,
ContextualIdentityService.getUserContextLabel(tab.userContextId),
]
const containerName = ContextualIdentityService.getUserContextLabel(
tab.userContextId
);
label = this.tabLocalization.formatValueSync(
"tabbrowser-container-tab-title",
{ title: label, containerName }
);
}
return label;
@ -5595,64 +5604,34 @@
return;
}
let stringWithShortcut = (stringId, keyElemId, pluralCount) => {
let keyElem = document.getElementById(keyElemId);
let shortcut = ShortcutUtils.prettifyShortcut(keyElem);
return PluralForm.get(
pluralCount,
gTabBrowserBundle.GetStringFromName(stringId)
)
.replace("%S", shortcut)
.replace("#1", pluralCount);
};
let label;
const selectedTabs = this.selectedTabs;
const contextTabInSelection = selectedTabs.includes(tab);
const affectedTabsLength = contextTabInSelection
? selectedTabs.length
let l10nId, l10nArgs;
const tabCount = this.selectedTabs.includes(tab)
? this.selectedTabs.length
: 1;
if (tab.mOverCloseButton) {
label = tab.selected
? stringWithShortcut(
"tabs.closeTabs.tooltip",
"key_close",
affectedTabsLength
)
: PluralForm.get(
affectedTabsLength,
gTabBrowserBundle.GetStringFromName("tabs.closeTabs.tooltip")
).replace("#1", affectedTabsLength);
l10nId = "tabbrowser-close-tabs-tooltip";
l10nArgs = { tabCount };
} else if (tab._overPlayingIcon) {
let stringID;
l10nArgs = { tabCount };
if (tab.selected) {
stringID = tab.linkedBrowser.audioMuted
? "tabs.unmuteAudio2.tooltip"
: "tabs.muteAudio2.tooltip";
label = stringWithShortcut(
stringID,
"key_toggleMute",
affectedTabsLength
);
l10nId = tab.linkedBrowser.audioMuted
? "tabbrowser-unmute-tab-audio-tooltip"
: "tabbrowser-mute-tab-audio-tooltip";
const keyElem = document.getElementById("key_toggleMute");
l10nArgs.shortcut = ShortcutUtils.prettifyShortcut(keyElem);
} else if (tab.hasAttribute("activemedia-blocked")) {
l10nId = "tabbrowser-unblock-tab-audio-tooltip";
} else {
if (tab.hasAttribute("activemedia-blocked")) {
stringID = "tabs.unblockAudio2.tooltip";
} else {
stringID = tab.linkedBrowser.audioMuted
? "tabs.unmuteAudio2.background.tooltip"
: "tabs.muteAudio2.background.tooltip";
}
label = PluralForm.get(
affectedTabsLength,
gTabBrowserBundle.GetStringFromName(stringID)
).replace("#1", affectedTabsLength);
l10nId = tab.linkedBrowser.audioMuted
? "tabbrowser-unmute-tab-audio-background-tooltip"
: "tabbrowser-mute-tab-audio-background-tooltip";
}
} else {
label = this.getTabTooltip(tab);
l10nId = "tabbrowser-tab-tooltip";
l10nArgs = { title: this.getTabTooltip(tab, true) };
}
event.target.setAttribute("label", label);
document.l10n.setAttributes(event.target, l10nId, l10nArgs);
},
handleEvent(aEvent) {
@ -7066,14 +7045,10 @@ var TabBarVisibility = {
navbar.setAttribute("tabs-hidden", collapse);
document.getElementById("menu_closeWindow").hidden = collapse;
document
.getElementById("menu_close")
.setAttribute(
"label",
gTabBrowserBundle.GetStringFromName(
collapse ? "tabs.close" : "tabs.closeTab"
)
);
document.l10n.setAttributes(
document.getElementById("menu_close"),
collapse ? "tabbrowser-menuitem-close" : "tabbrowser-menuitem-close-tab"
);
TabsInTitlebar.allowedBy("tabs-visible", !collapse);
},

View File

@ -2,6 +2,91 @@
# 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/.
tabbrowser-menuitem-close-tab =
.label = Close Tab
tabbrowser-menuitem-close =
.label = Close
# Displayed as a tooltip on container tabs
# Variables:
# $title (String): the title of the current tab.
# $containerName (String): the name of the current container.
tabbrowser-container-tab-title = { $title } — { $containerName }
# Variables:
# $title (String): the title of the current tab.
tabbrowser-tab-tooltip =
.label = { $title }
# Variables:
# $tabCount (Number): The number of tabs that will be closed.
tabbrowser-close-tabs-tooltip =
.label =
{ $tabCount ->
[one] Close tab
*[other] Close { $tabCount } tabs
}
## Tooltips for tab audio control
## Variables:
## $tabCount (Number): The number of tabs that will be affected.
# Variables:
# $shortcut (String): The keyboard shortcut for "Mute tab".
tabbrowser-mute-tab-audio-tooltip =
.label =
{ $tabCount ->
[one] Mute tab ({ $shortcut })
*[other] Mute { $tabCount } tabs ({ $shortcut })
}
# Variables:
# $shortcut (String): The keyboard shortcut for "Unmute tab".
tabbrowser-unmute-tab-audio-tooltip =
.label =
{ $tabCount ->
[one] Unmute tab ({ $shortcut })
*[other] Unmute { $tabCount } tabs ({ $shortcut })
}
tabbrowser-mute-tab-audio-background-tooltip =
.label =
{ $tabCount ->
[one] Mute tab
*[other] Mute { $tabCount } tabs
}
tabbrowser-unmute-tab-audio-background-tooltip =
.label =
{ $tabCount ->
[one] Unmute tab
*[other] Unmute { $tabCount } tabs
}
tabbrowser-unblock-tab-audio-tooltip =
.label =
{ $tabCount ->
[one] Play tab
*[other] Play { $tabCount } tabs
}
## Confirmation dialog when closing a window with more than one tab open,
## or when quitting when only one window is open.
# The singular form is not considered since this string is used only for multiple tabs.
# Variables:
# $tabCount (Number): The number of tabs that will be closed.
tabbrowser-confirm-close-tabs-title =
{ $tabCount ->
*[other] Close { $tabCount } tabs?
}
tabbrowser-confirm-close-tabs-button = Close tabs
tabbrowser-confirm-close-tabs-checkbox = Confirm before closing multiple tabs
## Confirmation dialog for enabling caret browsing
tabbrowser-confirm-caretbrowsing-title = Caret Browsing
tabbrowser-confirm-caretbrowsing-message = Pressing F7 turns Caret Browsing on or off. This feature places a moveable cursor in web pages, allowing you to select text with the keyboard. Do you want to turn Caret Browsing on?
tabbrowser-confirm-caretbrowsing-checkbox = Do not show me this dialog box again.
##
# Variables:
# $domain (String): URL of the page that is trying to steal focus.
tabbrowser-allow-dialogs-to-get-focus =

View File

@ -4,19 +4,6 @@
tabs.emptyTabTitle=New Tab
tabs.emptyPrivateTabTitle2=New Private Tab
tabs.closeTab=Close Tab
tabs.close=Close
# This section applies when closing a window with more than one tab open,
# or when quitting when only one window is open.
# LOCALIZATION NOTE (tabs.closeTabsTitle):
# Semicolon-separated list of plural forms. See:
# http://developer.mozilla.org/en/docs/Localization_and_Plurals
# The singular form is not considered since this string is used only for
# multiple tabs.
tabs.closeTabsTitle=;Close #1 tabs?
tabs.closeTabsConfirmCheckbox=Confirm before closing multiple tabs
tabs.closeButtonMultiple=Close tabs
# This section applies when quitting using the menu and multiple windows are open.
# LOCALIZATION NOTE (tabs.closeTitleTabs):
@ -42,56 +29,6 @@ tabs.closeTabsWithKeyButton=Quit %S
# %S is replaced with the text of the keyboard shortcut for quitting.
tabs.closeTabsWithKeyConfirmCheckbox=Confirm before quitting with %S
# LOCALIZATION NOTE (tabs.closeTabs.tooltip):
# Semicolon-separated list of plural forms. See:
# http://developer.mozilla.org/en/docs/Localization_and_Plurals
# #1 is the number of tabs that will be closed. This is ignored for the
# single tab case in English, but can be used by other locales as necessary.
tabs.closeTabs.tooltip=Close tab;Close #1 tabs
# LOCALIZATION NOTE (tabs.muteAudio2.tooltip):
# Semicolon-separated list of plural forms. See:
# http://developer.mozilla.org/en/docs/Localization_and_Plurals
# %S is the keyboard shortcut for "Mute tab".
# #1 is the number of tabs that will be muted. This is ignored for the
# single tab case in English, but can be used by other locales as necessary.
tabs.muteAudio2.tooltip=Mute tab (%S);Mute #1 tabs (%S)
# LOCALIZATION NOTE (tabs.unmuteAudio2.tooltip):
# Semicolon-separated list of plural forms. See:
# http://developer.mozilla.org/en/docs/Localization_and_Plurals
# %S is the keyboard shortcut for "Unmute tab".
# #1 is the number of tabs that will be unmuted. This is ignored for the
# single tab case in English, but can be used by other locales as necessary.
tabs.unmuteAudio2.tooltip=Unmute tab (%S);Unmute #1 tabs (%S)
# LOCALIZATION NOTE (tabs.muteAudio2.background.tooltip):
# Semicolon-separated list of plural forms. See:
# http://developer.mozilla.org/en/docs/Localization_and_Plurals
# #1 is the number of tabs that will be muted. This is ignored for the
# single tab case in English, but can be used by other locales as necessary.
tabs.muteAudio2.background.tooltip=Mute tab;Mute #1 tabs
# LOCALIZATION NOTE (tabs.unmuteAudio2.background.tooltip):
# Semicolon-separated list of plural forms. See:
# http://developer.mozilla.org/en/docs/Localization_and_Plurals
# #1 is the number of tabs that will be unmuted. This is ignored for the
# single tab case in English, but can be used by other locales as necessary.
tabs.unmuteAudio2.background.tooltip=Unmute tab;Unmute #1 tabs
# LOCALIZATION NOTE (tabs.unblockAudio2.tooltip):
# Semicolon-separated list of plural forms. See:
# http://developer.mozilla.org/en/docs/Localization_and_Plurals
# #1 is the number of tabs that will have their audio unblocked. This is ignored for the
# single tab case in English, but can be used by other locales as necessary.
tabs.unblockAudio2.tooltip=Play tab;Play #1 tabs
# LOCALIZATION NOTE (tabs.containers.tooltip):
# Displayed as a tooltip on container tabs
# %1$S is the title of the current tab
# %2$S is the name of the current container
tabs.containers.tooltip=%1$S — %2$S
# LOCALIZATION NOTE (tabs.openWarningTitle, tabs.openWarningMultipleBranded, tabs.openButtonMultiple, tabs.openWarningPromptMeBranded):
# These items are moved from chrome/browser/places/places.properties
# Now they are not specific to bookmark.
@ -99,7 +36,3 @@ tabs.openWarningTitle=Confirm open
tabs.openWarningMultipleBranded=You are about to open %S tabs. This might slow down %S while the pages are loading. Are you sure you want to continue?
tabs.openButtonMultiple=Open tabs
tabs.openWarningPromptMeBranded=Warn me when opening multiple tabs might slow down %S
browsewithcaret.checkMsg=Do not show me this dialog box again.
browsewithcaret.checkWindowTitle=Caret Browsing
browsewithcaret.checkLabel=Pressing F7 turns Caret Browsing on or off. This feature places a moveable cursor in web pages, allowing you to select text with the keyboard. Do you want to turn Caret Browsing on?

View File

@ -0,0 +1,196 @@
# 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 TERM_REFERENCE, VARIABLE_REFERENCE
from fluent.migrate.transforms import COPY, PLURALS, REPLACE, REPLACE_IN_TEXT
def migrate(ctx):
"""Bug 1760029 - Migrate tabbrowser to Fluent, part {index}."""
source = "browser/chrome/browser/tabbrowser.properties"
target = "browser/browser/tabbrowser.ftl"
ctx.add_transforms(
target,
target,
[
FTL.Message(
id=FTL.Identifier("tabbrowser-menuitem-close-tab"),
attributes=[
FTL.Attribute(
id=FTL.Identifier("label"), value=COPY(source, "tabs.closeTab")
)
],
),
FTL.Message(
id=FTL.Identifier("tabbrowser-menuitem-close"),
attributes=[
FTL.Attribute(
id=FTL.Identifier("label"), value=COPY(source, "tabs.close")
)
],
),
FTL.Message(
id=FTL.Identifier("tabbrowser-container-tab-title"),
value=REPLACE(
source,
"tabs.containers.tooltip",
{
"%1$S": VARIABLE_REFERENCE("title"),
"%2$S": VARIABLE_REFERENCE("containerName"),
},
),
),
FTL.Message(
id=FTL.Identifier("tabbrowser-tab-tooltip"),
attributes=[
FTL.Attribute(
id=FTL.Identifier("label"),
value=FTL.Pattern([FTL.Placeable(VARIABLE_REFERENCE("title"))]),
)
],
),
FTL.Message(
id=FTL.Identifier("tabbrowser-close-tabs-tooltip"),
attributes=[
FTL.Attribute(
id=FTL.Identifier("label"),
value=PLURALS(
source,
"tabs.closeTabs.tooltip",
VARIABLE_REFERENCE("tabCount"),
foreach=lambda n: REPLACE_IN_TEXT(
n,
{"#1": VARIABLE_REFERENCE("tabCount")},
),
),
)
],
),
FTL.Message(
id=FTL.Identifier("tabbrowser-mute-tab-audio-tooltip"),
attributes=[
FTL.Attribute(
id=FTL.Identifier("label"),
value=PLURALS(
source,
"tabs.muteAudio2.tooltip",
VARIABLE_REFERENCE("tabCount"),
foreach=lambda text: REPLACE_IN_TEXT(
text,
{
"#1": VARIABLE_REFERENCE("tabCount"),
"%S": VARIABLE_REFERENCE("shortcut"),
},
),
),
)
],
),
FTL.Message(
id=FTL.Identifier("tabbrowser-unmute-tab-audio-tooltip"),
attributes=[
FTL.Attribute(
id=FTL.Identifier("label"),
value=PLURALS(
source,
"tabs.unmuteAudio2.tooltip",
VARIABLE_REFERENCE("tabCount"),
foreach=lambda text: REPLACE_IN_TEXT(
text,
{
"#1": VARIABLE_REFERENCE("tabCount"),
"%S": VARIABLE_REFERENCE("shortcut"),
},
),
),
)
],
),
FTL.Message(
id=FTL.Identifier("tabbrowser-mute-tab-audio-background-tooltip"),
attributes=[
FTL.Attribute(
id=FTL.Identifier("label"),
value=PLURALS(
source,
"tabs.muteAudio2.background.tooltip",
VARIABLE_REFERENCE("tabCount"),
foreach=lambda n: REPLACE_IN_TEXT(
n,
{"#1": VARIABLE_REFERENCE("tabCount")},
),
),
)
],
),
FTL.Message(
id=FTL.Identifier("tabbrowser-unmute-tab-audio-background-tooltip"),
attributes=[
FTL.Attribute(
id=FTL.Identifier("label"),
value=PLURALS(
source,
"tabs.unmuteAudio2.background.tooltip",
VARIABLE_REFERENCE("tabCount"),
foreach=lambda n: REPLACE_IN_TEXT(
n,
{"#1": VARIABLE_REFERENCE("tabCount")},
),
),
)
],
),
FTL.Message(
id=FTL.Identifier("tabbrowser-unblock-tab-audio-tooltip"),
attributes=[
FTL.Attribute(
id=FTL.Identifier("label"),
value=PLURALS(
source,
"tabs.unblockAudio2.tooltip",
VARIABLE_REFERENCE("tabCount"),
foreach=lambda n: REPLACE_IN_TEXT(
n,
{"#1": VARIABLE_REFERENCE("tabCount")},
),
),
)
],
),
FTL.Message(
id=FTL.Identifier("tabbrowser-confirm-close-tabs-title"),
value=PLURALS(
source,
"tabs.closeTabsTitle",
VARIABLE_REFERENCE("tabCount"),
foreach=lambda n: REPLACE_IN_TEXT(
n,
{"#1": VARIABLE_REFERENCE("tabCount")},
),
),
),
FTL.Message(
id=FTL.Identifier("tabbrowser-confirm-close-tabs-button"),
value=COPY(source, "tabs.closeButtonMultiple"),
),
FTL.Message(
id=FTL.Identifier("tabbrowser-confirm-close-tabs-checkbox"),
value=COPY(source, "tabs.closeTabsConfirmCheckbox"),
),
FTL.Message(
id=FTL.Identifier("tabbrowser-confirm-caretbrowsing-title"),
value=COPY(source, "browsewithcaret.checkWindowTitle"),
),
FTL.Message(
id=FTL.Identifier("tabbrowser-confirm-caretbrowsing-message"),
value=COPY(source, "browsewithcaret.checkLabel"),
),
FTL.Message(
id=FTL.Identifier("tabbrowser-confirm-caretbrowsing-checkbox"),
value=COPY(source, "browsewithcaret.checkMsg"),
),
],
)