Bug 1457021 - Migrate the JS of Preferences::Fonts to Fluent. r?jaws,flod
MozReview-Commit-ID: A5yrLylYBjm
--- a/browser/components/preferences/fonts.js
+++ b/browser/components/preferences/fonts.js
@@ -85,32 +85,34 @@ var gFontsDialog = {
return preference.value == 1;
},
writeUseDocumentFonts() {
var useDocumentFonts = document.getElementById("useDocumentFonts");
return useDocumentFonts.checked ? 1 : 0;
},
- onBeforeAccept() {
- // It would be good if we could avoid touching languages the pref pages won't use, but
- // unfortunately the language group APIs (deducing language groups from language codes)
- // are C++ - only. So we just check all the things the user touched:
- // Don't care about anything up to 24px, or if this value is the same as set previously:
- let preferences = Preferences.getAll().filter(pref => {
- return pref.id.includes("font.minimum-size") && pref.value > 24 && pref.value != pref.valueFromPreferences;
- });
- if (!preferences.length) {
- return true;
+ async confirmMinSizeChange() {
+ let menulist = document.getElementById("minSize");
+ let preference = menulist.getAttribute("preference");
+ let defaultValue = Preferences.get(preference).valueFromPreferences;
+ let oldValue = Preferences.get(preference).value;
+ let newValue = menulist.value;
+
+ if (newValue <= 24 || newValue == defaultValue) {
+ return;
}
- let strings = document.getElementById("bundlePreferences");
- let title = strings.getString("veryLargeMinimumFontTitle");
- let confirmLabel = strings.getString("acceptVeryLargeMinimumFont");
- let warningMessage = strings.getString("veryLargeMinimumFontWarning");
+ let [title, warningMessage, confirmLabel] = await document.l10n.formatValues([
+ ["fonts-very-large-warning-title"],
+ ["fonts-very-large-warning-message"],
+ ["fonts-very-large-warning-accept"],
+ ]);
let {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm", {});
let flags = Services.prompt.BUTTON_POS_1 * Services.prompt.BUTTON_TITLE_CANCEL |
Services.prompt.BUTTON_POS_0 * Services.prompt.BUTTON_TITLE_IS_STRING |
Services.prompt.BUTTON_POS_1_DEFAULT;
let buttonChosen = Services.prompt.confirmEx(window, title, warningMessage, flags, confirmLabel, null, "", "", {});
- return buttonChosen == 0;
+ if (buttonChosen != 0) {
+ menulist.value = oldValue;
+ }
},
};
--- a/browser/components/preferences/fonts.xul
+++ b/browser/components/preferences/fonts.xul
@@ -11,32 +11,30 @@
<dialog id="FontsDialog" type="child" class="prefwindow"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
data-l10n-id="fonts-window"
data-l10n-attrs="title"
buttons="accept,cancel,help"
persist="lastSelected screenX screenY"
role="dialog"
helpTopic="prefs-fonts-and-colors"
- ondialoghelp="openPrefsHelp()"
- onbeforeaccept="return gFontsDialog.onBeforeAccept();">
+ ondialoghelp="openPrefsHelp()">
<link rel="localization" href="browser/preferences/fonts.ftl"/>
<script type="application/javascript" src="chrome://global/content/l10n.js"></script>
<script type="application/javascript" src="chrome://browser/content/utilityOverlay.js"/>
<script type="application/javascript" src="chrome://global/content/preferencesBindings.js"/>
<keyset>
<key data-l10n-id="fonts-window-close" modifiers="accel" oncommand="Preferences.close(event)"/>
</keyset>
<vbox id="FontsDialogPane" class="prefpane largeDialogContainer">
- <stringbundle id="bundlePreferences" src="chrome://browser/locale/preferences/preferences.properties"/>
<script type="application/javascript" src="chrome://mozapps/content/preferences/fontbuilder.js"/>
<script type="application/javascript" src="chrome://browser/content/preferences/fonts.js"/>
<!-- Fonts for: [ Language ] -->
<groupbox>
<caption>
<hbox align="center">
<label data-l10n-id="fonts-langgroup-header" control="selectLangs"/>
@@ -209,17 +207,17 @@
</grid>
<separator class="thin"/>
<hbox flex="1">
<spacer flex="1"/>
<hbox align="center" pack="end">
<label data-l10n-id="fonts-minsize" control="minSize"/>
<!-- Please don't remove the wrapping hbox/vbox/box for these elements. It's used to properly compute the search tooltip position. -->
<hbox>
- <menulist id="minSize">
+ <menulist id="minSize" oncommand="gFontsDialog.confirmMinSizeChange();">
<menupopup>
<menuitem value="0" data-l10n-id="fonts-minsize-none"/>
<menuitem value="9" label="9"/>
<menuitem value="10" label="10"/>
<menuitem value="11" label="11"/>
<menuitem value="12" label="12"/>
<menuitem value="13" label="13"/>
<menuitem value="14" label="14"/>
--- a/browser/components/preferences/in-content/preferences.xul
+++ b/browser/components/preferences/in-content/preferences.xul
@@ -35,23 +35,24 @@
xmlns:html="http://www.w3.org/1999/xhtml"
disablefastfind="true"
data-l10n-id="pref-page"
data-l10n-attrs="title">
<link rel="localization" href="branding/brand.ftl"/>
<link rel="localization" href="browser/branding/sync-brand.ftl"/>
<link rel="localization" href="browser/preferences/preferences.ftl"/>
+ <!-- Used by fontbuilder.js -->
+ <link rel="localization" href="browser/preferences/fonts.ftl"/>
<!-- Links below are only used for search-l10n-ids into subdialogs -->
<link rel="localization" href="browser/preferences/blocklists.ftl"/>
<link rel="localization" href="browser/preferences/clearSiteData.ftl"/>
<link rel="localization" href="browser/preferences/colors.ftl"/>
<link rel="localization" href="browser/preferences/connection.ftl"/>
- <link rel="localization" href="browser/preferences/fonts.ftl"/>
<link rel="localization" href="browser/preferences/languages.ftl"/>
<link rel="localization" href="browser/preferences/permissions.ftl"/>
<link rel="localization" href="browser/preferences/selectBookmark.ftl"/>
<link rel="localization" href="browser/preferences/siteDataSettings.ftl"/>
<script type="text/javascript" src="chrome://global/content/l10n.js"></script>
<html:link rel="shortcut icon"
--- a/browser/locales/en-US/browser/preferences/fonts.ftl
+++ b/browser/locales/en-US/browser/preferences/fonts.ftl
@@ -146,8 +146,19 @@ fonts-languages-fallback-name-korean =
fonts-languages-fallback-name-thai =
.label = Thai
fonts-languages-fallback-name-turkish =
.label = Turkish
fonts-languages-fallback-name-vietnamese =
.label = Vietnamese
fonts-languages-fallback-name-other =
.label = Other (incl. Western European)
+
+fonts-very-large-warning-title = Large minimum font size
+fonts-very-large-warning-message = You have selected a very large minimum font size (more than 24 pixels). This may make it difficult or impossible to use some important configuration pages like this one.
+fonts-very-large-warning-accept = Keep my changes anyway
+
+# Variables:
+# $name {string, "Arial"} - Name of the default font
+fonts-label-default =
+ .label = Default ({ $name })
+fonts-label-default-unnamed =
+ .label = Default
--- a/browser/locales/en-US/chrome/browser/preferences/preferences.properties
+++ b/browser/locales/en-US/chrome/browser/preferences/preferences.properties
@@ -4,25 +4,16 @@
#### Security
# LOCALIZATION NOTE: phishBefore uses %S to represent the name of the provider
# whose privacy policy must be accepted (for enabling
# check-every-page-as-I-load-it phishing protection).
phishBeforeText=Selecting this option will send the address of web pages you are viewing to %S. To continue, please review and accept the following terms of service.
-#### Fonts
-
-labelDefaultFont=Default (%S)
-labelDefaultFontUnnamed=Default
-
-veryLargeMinimumFontTitle=Large minimum font size
-veryLargeMinimumFontWarning=You have selected a very large minimum font size (more than 24 pixels). This may make it difficult or impossible to use some important configuration pages like this one.
-acceptVeryLargeMinimumFont=Keep my changes anyway
-
#### Master Password
pw_change2empty_in_fips_mode=You are currently in FIPS mode. FIPS requires a non-empty Master Password.
pw_change_failed_title=Password Change Failed
#### Fonts
# LOCALIZATION NOTE: The string represents a localized locale name
--- a/toolkit/mozapps/preferences/fontbuilder.js
+++ b/toolkit/mozapps/preferences/fontbuilder.js
@@ -36,22 +36,24 @@ var FontBuilder = {
if (!this._allFonts)
this._allFonts = await this.enumerator.EnumerateAllFontsAsync({});
// Build the UI for the Default Font and Fonts for this CSS type.
const popup = document.createElement("menupopup");
let separator;
if (fonts.length > 0) {
- const bundlePreferences = document.getElementById("bundlePreferences");
- let defaultLabel = defaultFont ?
- bundlePreferences.getFormattedString("labelDefaultFont", [defaultFont]) :
- bundlePreferences.getString("labelDefaultFontUnnamed");
let menuitem = document.createElement("menuitem");
- menuitem.setAttribute("label", defaultLabel);
+ if (defaultFont) {
+ document.l10n.setAttributes(menuitem, "fonts-label-default", {
+ name: defaultFont
+ });
+ } else {
+ document.l10n.setAttributes(menuitem, "fonts-label-default-unnamed");
+ }
menuitem.setAttribute("value", ""); // Default Font has a blank value
popup.appendChild(menuitem);
separator = document.createElement("menuseparator");
popup.appendChild(separator);
for (let font of fonts) {
menuitem = document.createElement("menuitem");