From dded25327a665db45cf27fcaf7ba9b44e7938704 Mon Sep 17 00:00:00 2001 From: Alexis Deschamps Date: Wed, 1 Aug 2018 10:31:14 +0300 Subject: [PATCH 01/33] Bug 1476034 - about:crashes: switched to fluent. r=flod,Pike Summary: The about:crashes page is being updated (bug 1463515). To facilitate these changes, this patch changes the about:crashes page to use Fluent for localization instead of the old systems. This also includes a script to migrate strings from the old .DTD and .properties files to the new .ftl one. Test Plan: 1. build Firefox with the changes 2. run Firefox 3. go to the about:crashes page 4. expect nothing to be different This extension: https://github.com/rhelmer/webext-experiment-crashme can be used to add local crash reports for verifying the different states of the about:crashes page. Reviewers: flod, Pike, jchen, snorp Reviewed By: flod, Pike, jchen, snorp Subscribers: nalexander, reviewbot Bug #: 1476034 Differential Revision: https://phabricator.services.mozilla.com/D2225 --HG-- extra : rebase_source : 0ca9516b4df78e735fd03907f2ea324bc72ca893 --- .../static/browser_all_files_referenced.js | 5 --- mobile/android/chrome/content/browser.js | 6 ++++ mobile/android/chrome/jar.mn | 2 -- .../components/geckoview/GeckoViewStartup.js | 7 ++++ mobile/android/installer/package-manifest.in | 1 + mobile/android/locales/filter.py | 8 +++-- mobile/android/locales/jar.mn | 16 +++++++-- mobile/android/locales/l10n.toml | 4 +++ mobile/locales/filter.py | 10 +++--- .../bug_1476034_aboutcrashes.py | 35 +++++++++++++++++++ toolkit/crashreporter/content/crashes.css | 4 +-- toolkit/crashreporter/content/crashes.js | 11 +++--- toolkit/crashreporter/content/crashes.xhtml | 33 ++++++++--------- .../en-US/chrome/global/aboutSupport.dtd | 2 +- .../en-US/crashreporter/aboutcrashes.ftl | 19 ++++++++++ .../locales/en-US/crashreporter/crashes.dtd | 13 ------- .../en-US/crashreporter/crashes.properties | 7 ---- toolkit/locales/jar.mn | 3 +- 18 files changed, 119 insertions(+), 67 deletions(-) create mode 100644 python/l10n/fluent_migrations/bug_1476034_aboutcrashes.py create mode 100644 toolkit/locales/en-US/crashreporter/aboutcrashes.ftl delete mode 100644 toolkit/locales/en-US/crashreporter/crashes.dtd delete mode 100644 toolkit/locales/en-US/crashreporter/crashes.properties diff --git a/browser/base/content/test/static/browser_all_files_referenced.js b/browser/base/content/test/static/browser_all_files_referenced.js index fbd98ade862c..d2b9c2e36eb0 100644 --- a/browser/base/content/test/static/browser_all_files_referenced.js +++ b/browser/base/content/test/static/browser_all_files_referenced.js @@ -169,11 +169,6 @@ whitelist = new Set(whitelist.filter(item => ).map(item => item.file)); const ignorableWhitelist = new Set([ - // These 2 files are unreferenced only when building without the crash - // reporter (eg. Linux x64 asan builds on treeherder) - "chrome://global/locale/crashes.dtd", - "chrome://global/locale/crashes.properties", - // The following files are outside of the omni.ja file, so we only catch them // when testing on a non-packaged build. diff --git a/mobile/android/chrome/content/browser.js b/mobile/android/chrome/content/browser.js index d31d393a15ec..c0945a079cfc 100644 --- a/mobile/android/chrome/content/browser.js +++ b/mobile/android/chrome/content/browser.js @@ -7,6 +7,7 @@ ChromeUtils.import("resource://gre/modules/AddonManager.jsm"); ChromeUtils.import("resource://gre/modules/AppConstants.jsm"); ChromeUtils.import("resource://gre/modules/DelayedInit.jsm"); +ChromeUtils.import("resource://gre/modules/L10nRegistry.jsm"); ChromeUtils.import("resource://gre/modules/Messaging.jsm"); ChromeUtils.import("resource://gre/modules/Services.jsm"); ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm"); @@ -389,6 +390,11 @@ var BrowserApp = { "Telemetry:CustomTabsPing", ]); + // Initialize the default l10n resource sources for L10nRegistry. + let locales = Services.locale.getPackagedLocales(); + const greSource = new FileSource("toolkit", locales, "resource://gre/localization/{locale}/"); + L10nRegistry.registerSource(greSource); + // Provide compatibility for add-ons like QuitNow that send "Browser:Quit" // as an observer notification. Services.obs.addObserver((subject, topic, data) => diff --git a/mobile/android/chrome/jar.mn b/mobile/android/chrome/jar.mn index a54c1bcf04ec..6694d34aba79 100644 --- a/mobile/android/chrome/jar.mn +++ b/mobile/android/chrome/jar.mn @@ -72,8 +72,6 @@ chrome.jar: % override chrome://pluginproblem/locale/pluginproblem.dtd chrome://browser/locale/overrides/plugins/pluginproblem.dtd % override chrome://global/locale/aboutSupport.dtd chrome://browser/locale/overrides/global/aboutSupport.dtd % override chrome://global/locale/aboutSupport.properties chrome://browser/locale/overrides/global/aboutSupport.properties -% override chrome://global/locale/crashes.dtd chrome://browser/locale/overrides/crashreporter/crashes.dtd -% override chrome://global/locale/crashes.properties chrome://browser/locale/overrides/crashreporter/crashes.properties % override chrome://global/locale/mozilla.dtd chrome://browser/locale/overrides/global/mozilla.dtd % override chrome://global/locale/aboutTelemetry.dtd chrome://browser/locale/overrides/global/aboutTelemetry.dtd % override chrome://global/locale/aboutTelemetry.properties chrome://browser/locale/overrides/global/aboutTelemetry.properties diff --git a/mobile/android/components/geckoview/GeckoViewStartup.js b/mobile/android/components/geckoview/GeckoViewStartup.js index d413550f19e5..484a5e968123 100644 --- a/mobile/android/components/geckoview/GeckoViewStartup.js +++ b/mobile/android/components/geckoview/GeckoViewStartup.js @@ -5,8 +5,10 @@ ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm"); XPCOMUtils.defineLazyModuleGetters(this, { + FileSource: "resource://gre/modules/L10nRegistry.jsm", GeckoViewTelemetryController: "resource://gre/modules/GeckoViewTelemetryController.jsm", GeckoViewUtils: "resource://gre/modules/GeckoViewUtils.jsm", + L10nRegistry: "resource://gre/modules/L10nRegistry.jsm", Services: "resource://gre/modules/Services.jsm", }); @@ -111,6 +113,11 @@ GeckoViewStartup.prototype = { // The Telemetry initialization for the content process is performed in // ContentProcessSingleton.js for consistency with Desktop Telemetry. GeckoViewTelemetryController.setup(); + + // Initialize the default l10n resource sources for L10nRegistry. + let locales = Services.locale.getPackagedLocales(); + const greSource = new FileSource("toolkit", locales, "resource://gre/localization/{locale}/"); + L10nRegistry.registerSource(greSource); break; } } diff --git a/mobile/android/installer/package-manifest.in b/mobile/android/installer/package-manifest.in index a3cfe03abacd..73afe5565290 100644 --- a/mobile/android/installer/package-manifest.in +++ b/mobile/android/installer/package-manifest.in @@ -22,6 +22,7 @@ #endif @BINPATH@/dictionaries/* @BINPATH@/hyphenation/* +@BINPATH@/localization/* [assets destdir="assets/@ANDROID_CPU_ARCH@"] #ifndef MOZ_STATIC_JS diff --git a/mobile/android/locales/filter.py b/mobile/android/locales/filter.py index 543282c6ac8d..c41c5f525f13 100644 --- a/mobile/android/locales/filter.py +++ b/mobile/android/locales/filter.py @@ -29,12 +29,14 @@ def test(mod, path, entity=None): "chrome/pluginproblem/pluginproblem.dtd", "chrome/global/aboutSupport.dtd", "chrome/global/aboutSupport.properties", - "crashreporter/crashes.dtd", - "crashreporter/crashes.properties", "chrome/global/mozilla.dtd", "chrome/global/aboutTelemetry.dtd", "chrome/global/aboutTelemetry.properties", - "chrome/global/aboutWebrtc.properties"): + "chrome/global/aboutWebrtc.properties", + ): + return "error" + if re.match(r"crashreporter/[^/]*.ftl", path): + # error on crashreporter/*.ftl return "error" return "ignore" diff --git a/mobile/android/locales/jar.mn b/mobile/android/locales/jar.mn index 1c5a345f2710..f6b305119525 100644 --- a/mobile/android/locales/jar.mn +++ b/mobile/android/locales/jar.mn @@ -50,9 +50,6 @@ relativesrcdir toolkit/locales: # about:support locale/@AB_CD@/browser/overrides/global/aboutSupport.dtd (%chrome/global/aboutSupport.dtd) locale/@AB_CD@/browser/overrides/global/aboutSupport.properties (%chrome/global/aboutSupport.properties) -#about:crashes - locale/@AB_CD@/browser/overrides/crashreporter/crashes.dtd (%crashreporter/crashes.dtd) - locale/@AB_CD@/browser/overrides/crashreporter/crashes.properties (%crashreporter/crashes.properties) #about:mozilla locale/@AB_CD@/browser/overrides/global/mozilla.dtd (%chrome/global/mozilla.dtd) #about:telemetry @@ -69,3 +66,16 @@ relativesrcdir dom/locales: locale/@AB_CD@/browser/overrides/dom/dom.properties (%chrome/dom/dom.properties) #about:plugins locale/@AB_CD@/browser/overrides/plugins.properties (%chrome/plugins.properties) + +# Fluent files +# Note: All rules must be wildcards, as localized files are optional +# Only run this if we're not en-US, as en-US is already built +# by toolkit/locales/jar.mn. + +#define EN_US en-US +#if AB_CD != EN_US +[localization] @AB_CD@.jar: +relativesrcdir toolkit/locales: +#about:crashes + crashreporter (%crashreporter/**/*.ftl) +#endif diff --git a/mobile/android/locales/l10n.toml b/mobile/android/locales/l10n.toml index f092a7f14064..351a223d22f2 100644 --- a/mobile/android/locales/l10n.toml +++ b/mobile/android/locales/l10n.toml @@ -201,6 +201,10 @@ exclude-multi-locale = [ reference = "toolkit/locales/en-US/chrome/global/aboutSupport.properties" l10n = "{l}toolkit/chrome/global/aboutSupport.properties" +[[paths]] + reference = "toolkit/locales/en-US/crashreporter/*.ftl" + l10n = "{l}toolkit/crashreporter/*.ftl" + [[paths]] reference = "toolkit/locales/en-US/crashreporter/crashes.dtd" l10n = "{l}toolkit/crashreporter/crashes.dtd" diff --git a/mobile/locales/filter.py b/mobile/locales/filter.py index faa6f4dcb526..82d7e1b4caad 100644 --- a/mobile/locales/filter.py +++ b/mobile/locales/filter.py @@ -29,12 +29,14 @@ def test(mod, path, entity=None): "chrome/pluginproblem/pluginproblem.dtd", "chrome/global/aboutSupport.dtd", "chrome/global/aboutSupport.properties", - "crashreporter/crashes.dtd", - "crashreporter/crashes.properties", "chrome/global/mozilla.dtd", "chrome/global/aboutTelemetry.dtd", "chrome/global/aboutTelemetry.properties", - "chrome/global/aboutWebrtc.properties"): + "chrome/global/aboutWebrtc.properties", + ): + return "error" + if re.match(r"crashreporter/[^/]*.ftl", path): + # error on crashreporter/*.ftl return "error" return "ignore" @@ -52,7 +54,7 @@ def test(mod, path, entity=None): # we only have exceptions for mobile* return "error" if mod == "mobile/android": - if not entity: + if entity is None: if (re.match(r"mobile-l10n.js", path) or re.match(r"defines.inc", path)): return "ignore" diff --git a/python/l10n/fluent_migrations/bug_1476034_aboutcrashes.py b/python/l10n/fluent_migrations/bug_1476034_aboutcrashes.py new file mode 100644 index 000000000000..115ec474a6df --- /dev/null +++ b/python/l10n/fluent_migrations/bug_1476034_aboutcrashes.py @@ -0,0 +1,35 @@ +# coding=utf8 + +# Any copyright is dedicated to the Public Domain. +# http://creativecommons.org/publicdomain/zero/1.0/ + +from __future__ import absolute_import +import fluent.syntax.ast as FTL +from fluent.migrate.helpers import transforms_from + + +def migrate(ctx): + """Bug 1476034 - about:crashes localization migration from DTD to Fluent""" + + ctx.add_transforms( + "toolkit/crashreporter/aboutcrashes.ftl", + "toolkit/crashreporter/aboutcrashes.ftl", + transforms_from( +""" +crash-reports-title = { COPY("toolkit/crashreporter/crashes.dtd", "crashReports.title") } + +clear-all-reports-label = { COPY("toolkit/crashreporter/crashes.dtd", "clearAllReports.label") } +delete-confirm-title = { COPY("toolkit/crashreporter/crashes.properties", "deleteconfirm.title") } +delete-confirm-description = { COPY("toolkit/crashreporter/crashes.properties", "deleteconfirm.description") } + +crashes-unsubmitted-label = { COPY("toolkit/crashreporter/crashes.dtd", "crashesUnsubmitted.label") } +id-heading = { COPY("toolkit/crashreporter/crashes.dtd", "id.heading") } +date-crashed-heading = { COPY("toolkit/crashreporter/crashes.dtd", "dateCrashed.heading") } + +crashes-submitted-label = { COPY("toolkit/crashreporter/crashes.dtd", "crashesSubmitted.label") } +date-submitted-heading = { COPY("toolkit/crashreporter/crashes.dtd", "dateSubmitted.heading") } + +no-reports-label = { COPY("toolkit/crashreporter/crashes.dtd", "noReports.label") } +no-config-label = { COPY("toolkit/crashreporter/crashes.dtd", "noConfig.label") } +""") + ) diff --git a/toolkit/crashreporter/content/crashes.css b/toolkit/crashreporter/content/crashes.css index 88326c6c1849..7ddcb5753354 100644 --- a/toolkit/crashreporter/content/crashes.css +++ b/toolkit/crashreporter/content/crashes.css @@ -19,7 +19,7 @@ th { text-align: left; white-space: nowrap; } -th[chromedir="rtl"] { +th:-moz-locale-dir(rtl) { text-align: right; } /* name */ @@ -51,7 +51,7 @@ td:last-child { #clear-reports { float: right; } -#clear-reports[chromedir="rtl"] { +#clear-reports:-moz-locale-dir(rtl) { float: left; } diff --git a/toolkit/crashreporter/content/crashes.js b/toolkit/crashreporter/content/crashes.js index 87b4d952ffe4..b1ad0b6bc672 100644 --- a/toolkit/crashreporter/content/crashes.js +++ b/toolkit/crashreporter/content/crashes.js @@ -130,12 +130,11 @@ function populateReportList() { } var clearReports = async function() { - let bundle = Services.strings.createBundle("chrome://global/locale/crashes.properties"); - - if (!Services. - prompt.confirm(window, - bundle.GetStringFromName("deleteconfirm.title"), - bundle.GetStringFromName("deleteconfirm.description"))) { + const [title, description] = await document.l10n.formatValues([ + {id: "delete-confirm-title"}, + {id: "delete-confirm-description"}, + ]); + if (!Services.prompt.confirm(window, title, description)) { return; } diff --git a/toolkit/crashreporter/content/crashes.xhtml b/toolkit/crashreporter/content/crashes.xhtml index b6ff209f6dda..a4e91865306d 100644 --- a/toolkit/crashreporter/content/crashes.xhtml +++ b/toolkit/crashreporter/content/crashes.xhtml @@ -3,33 +3,28 @@ - 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/. --> - - - %globalDTD; - %crashesDTD; -]> + +