Bug 1768567 - Fix missing plus sign in the fluent strings of the global shortcuts file and create a string mapping for easier update. r=mkmelin
authorAlessandro Castellani <alessandro@thunderbird.net>
Wed, 18 May 2022 22:29:43 +0000
changeset 35766 279167f85f2f59526b2599ab02c2c6afc55a10a1
parent 35765 f4fb3a75992a9417c563953deed3783a0bf4cd1b
child 35767 9ac8cbc657e117c917d75bd7b739b1f76123929b
push id19934
push useralessandro@thunderbird.net
push dateWed, 18 May 2022 22:31:52 +0000
treeherdercomm-central@9ac8cbc657e1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmkmelin
bugs1768567
Bug 1768567 - Fix missing plus sign in the fluent strings of the global shortcuts file and create a string mapping for easier update. r=mkmelin Differential Revision: https://phabricator.services.mozilla.com/D146599
mail/locales/en-US/messenger/shortcuts.ftl
mail/modules/ShortcutsManager.jsm
--- a/mail/locales/en-US/messenger/shortcuts.ftl
+++ b/mail/locales/en-US/messenger/shortcuts.ftl
@@ -75,32 +75,32 @@ meta-ctrl-shift-shortcut-key = {
 }
 
 alt-shift-shortcut-key = {
   PLATFORM() ->
     [macos] ⌥ ⇧ { $key }
    *[other] Alt+Shift+{ $key }
 }
 
-meta-shift-alt-shortcut-key = {
+meta-shift-alt-shortcut-key2 = {
   PLATFORM() ->
     [macos] ⌥ ⇧ ⌘ { $key }
-   *[other] Meta+Alt+Shift{ $key }
+   *[other] Meta+Alt+Shift+{ $key }
 }
 
-ctrl-shift-alt-shortcut-key = {
+ctrl-shift-alt-shortcut-key2 = {
   PLATFORM() ->
     [macos] ⌃ ⌥ ⇧ { $key }
-   *[other] Ctrl+Alt+Shift{ $key }
+   *[other] Ctrl+Alt+Shift+{ $key }
 }
 
-meta-ctrl-shift-alt-shortcut-key = {
+meta-ctrl-shift-alt-shortcut-key2 = {
   PLATFORM() ->
     [macos] ⌃ ⌥ ⇧ ⌘ { $key }
-   *[other] Meta+Ctrl+Alt+Shift{ $key }
+   *[other] Meta+Ctrl+Alt+Shift+{ $key }
 }
 
 # Variables:
 #  $title (String): The title coming from the original element.
 #  $shortcut (String): The shortcut generated from the keystroke combination.
 button-shortcut-string =
     .title = { $title } ({ $shortcut })
 
--- a/mail/modules/ShortcutsManager.jsm
+++ b/mail/modules/ShortcutsManager.jsm
@@ -12,16 +12,29 @@
 const EXPORTED_SYMBOLS = ["ShortcutsManager"];
 
 const { XPCOMUtils } = ChromeUtils.import(
   "resource://gre/modules/XPCOMUtils.jsm"
 );
 
 const ShortcutsManager = {
   /**
+   * Fluent strings mapping to allow updating strings without changing all the
+   * IDs in the shortcuts.ftl file. This is needed because the IDs are
+   * dynamically generated.
+   *
+   * @type {Object}
+   */
+  fluentMapping: {
+    "meta-shift-alt-shortcut-key": "meta-shift-alt-shortcut-key2",
+    "ctrl-shift-alt-shortcut-key": "ctrl-shift-alt-shortcut-key2",
+    "meta-ctrl-shift-alt-shortcut-key": "meta-ctrl-shift-alt-shortcut-key2",
+  },
+
+  /**
    * Data set for a shortcut.
    *
    * @typedef {Object} Shortcut
    * @property {string} id - The id for this shortcut.
    * @property {string} name - The name of this shortcut. TODO: This should use
    *   fluent to be translatable in the future, once we decide to expose this
    *   array and make it customizable.
    * @property {?string} key - The keyboard key used by this shortcut, or null
@@ -305,17 +318,21 @@ const ShortcutsManager = {
 
     if (shortcut.modifiers[platform].altKey) {
       string.push("alt");
       aria.push("Alt");
     }
     string.push("shortcut-key");
     aria.push(shortcut.key.toUpperCase());
 
-    let value = await this.l10n.formatValue(string.join("-"), {
+    // Check if the ID was updated in the fluent file and replace it.
+    let stringId = string.join("-");
+    stringId = this.fluentMapping[stringId] || stringId;
+
+    let value = await this.l10n.formatValue(stringId, {
       key: shortcut.key.toUpperCase(),
     });
 
     return { localizedShortcut: value, ariaKeyShortcuts: aria.join("+") };
   },
 };
 
 XPCOMUtils.defineLazyGetter(