[Switch Access] Localize menu strings

Bug: 864835
Change-Id: I089186b74cb453d6504e567ebb67f0f167c3d5fa
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1582606
Commit-Queue: Anastasia Helfinstein <anastasi@google.com>
Reviewed-by: Katie Dektar <katie@chromium.org>
Cr-Commit-Position: refs/heads/master@{#654311}
diff --git a/chrome/browser/resources/chromeos/switch_access/menu_panel.html b/chrome/browser/resources/chromeos/switch_access/menu_panel.html
index 242a2a7..82ea3384 100644
--- a/chrome/browser/resources/chromeos/switch_access/menu_panel.html
+++ b/chrome/browser/resources/chromeos/switch_access/menu_panel.html
@@ -5,7 +5,7 @@
 <!DOCTYPE html>
 <head>
   <meta charset="utf-8">
-  <title>Switch Access Menu</title>
+  <title class="i18n" msgid="menu_title">Switch Access Menu</title>
   <script type="text/javascript" src="closure/base.js"></script>
   <script type="text/javascript" src="switch_access_constants.js"></script>
   <script type="text/javascript" src="menu_panel.js"></script>
@@ -16,55 +16,55 @@
       aria-label="Switch Access Menu">
     <button class="action" id="select">
       <img src="icons/select.svg">
-      <p>Select</p>
+      <p class="i18n" msgid="select"></p>
     </button>
     <button class="action" id="keyboard">
       <img src="icons/keyboard.svg">
-      <p>Keyboard</p>
+      <p class="i18n" msgid="open_keyboard"></p>
     </button>
     <button class="action" id="increment">
       <img src="icons/increment.svg">
-      <p>Increment</p>
+      <p class="i18n" msgid="increment"></p>
     </button>
     <button class="action" id="decrement">
       <img src="icons/decrement.svg">
-      <p>Decrement</p>
+      <p class="i18n" msgid="decrement"></p>
     </button>
     <button class="action" id="scrollDown">
       <img src="icons/scrollDownOrForward.svg">
-      <p>Scroll down</p>
+      <p class="i18n" msgid="scroll_down"></p>
     </button>
     <button class="action" id="scrollUp">
       <img src="icons/scrollUpOrBackward.svg">
-      <p>Scroll up</p>
+      <p class="i18n" msgid="scroll_up"></p>
     </button>
     <button class="action" id="scrollRight">
       <img src="icons/scrollRight.svg">
-      <p>Scroll right</p>
+      <p class="i18n" msgid="scroll_right"></p>
     </button>
     <button class="action" id="scrollLeft">
       <img src="icons/scrollLeft.svg">
-      <p>Scroll left</p>
+      <p class="i18n" msgid="scroll_left"></p>
     </button>
     <button class="action" id="scrollForward">
       <img src="icons/scrollDownOrForward.svg">
-      <p>Scroll forward</p>
+      <p class="i18n" msgid="scroll_forward"></p>
     </button>
     <button class="action" id="scrollBackward">
       <img src="icons/scrollUpOrBackward.svg">
-      <p>Scroll backward</p>
+      <p class="i18n" msgid="scroll_backward"></p>
     </button>
     <button class="action" id="dictation">
       <img src="icons/dictation.svg">
-      <p>Dictation</p>
+      <p class="i18n" msgid="dictation"></p>
     </button>
     <button class="action" id="showContextMenu">
       <img src="icons/showContextMenu.svg">
-      <p>Context Menu</p>
+      <p class="i18n" msgid="show_context_menu"></p>
     </button>
     <button class="action" id="options">
       <img src="icons/options.svg">
-      <p>Options</p>
+      <p class="i18n" msgid="settings_action"></p>
     </button>
   </div>
   <button id="back">
diff --git a/chrome/browser/resources/chromeos/switch_access/menu_panel.js b/chrome/browser/resources/chromeos/switch_access/menu_panel.js
index 30530a8..40a0a9b 100644
--- a/chrome/browser/resources/chromeos/switch_access/menu_panel.js
+++ b/chrome/browser/resources/chromeos/switch_access/menu_panel.js
@@ -28,6 +28,8 @@
       this.connectToBackground();
     else
       background.addEventListener('load', this.connectToBackground.bind(this));
+
+    this.addTranslatedMessagesToDom_();
   }
 
   /**
@@ -106,6 +108,32 @@
     const height = 60 * numRows;
     document.getElementById(SAConstants.MENU_ID).style.height = height + 'px';
   }
+
+  /**
+   * Processes an HTML DOM, replacing text content with translated text messages
+   * on elements marked up for translation. Elements whose class attributes
+   * contain the 'i18n' class name are expected to also have an msgid attribute.
+   * The value of the msgid attributes are looked up as message IDs and the
+   * resulting text is used as the text content of the elements.
+   *
+   * TODO(crbug/706981): Combine with similar function in SelectToSpeakOptions.
+   * @private
+   */
+  addTranslatedMessagesToDom_() {
+    const elements = document.querySelectorAll('.i18n');
+    for (const element of elements) {
+      const messageId = element.getAttribute('msgid');
+      if (!messageId)
+        throw new Error('Element has no msgid attribute: ' + element);
+      const translatedMessage =
+          chrome.i18n.getMessage('switch_access_' + messageId);
+      if (element.tagName == 'INPUT')
+        element.setAttribute('placeholder', translatedMessage);
+      else
+        element.textContent = translatedMessage;
+      element.classList.add('i18n-processed');
+    }
+  }
 }
 
 let switchAccessMenuPanel = new Panel();
diff --git a/chrome/browser/resources/chromeos/switch_access/strings/switch_access_strings.grd b/chrome/browser/resources/chromeos/switch_access/strings/switch_access_strings.grd
index ce211b2..f80a309 100644
--- a/chrome/browser/resources/chromeos/switch_access/strings/switch_access_strings.grd
+++ b/chrome/browser/resources/chromeos/switch_access/strings/switch_access_strings.grd
@@ -120,6 +120,48 @@
       <message desc="The description for Switch Access." name="IDS_SWITCH_ACCESS_DESCRIPTION">
         Control the device with just 1 or 2 switches.
       </message>
+      <message desc="The title of the Switch Access menu to select which action to perform on an element." name="IDS_SWITCH_ACCESS_MENU_TITLE">
+        Switch Access Menu
+      </message>
+      <message desc="The Switch Access action to perform the default action on the current element, similar to a click or tap. Should be short." name="IDS_SWITCH_ACCESS_SELECT">
+        Select
+      </message>
+      <message desc="The Switch Access action to open the onscreen keyboard and begin entering text in the selected text input element. Should be short." name="IDS_SWITCH_ACCESS_OPEN_KEYBOARD">
+        Keyboard
+      </message>
+      <message desc="The Switch Access action to increment the selected input element. Should be short." name="IDS_SWITCH_ACCESS_INCREMENT">
+        Increment
+      </message>
+      <message desc="The Switch Access action to decrement the selected input element. Should be short." name="IDS_SWITCH_ACCESS_DECREMENT">
+        Decrement
+      </message>
+      <message desc="The Switch Access action to scroll the selected element down. Should be short." name="IDS_SWITCH_ACCESS_SCROLL_DOWN">
+        Scroll down
+      </message>
+      <message desc="The Switch Access action to scroll the selected element up. Should be short." name="IDS_SWITCH_ACCESS_SCROLL_UP">
+        Scroll up
+      </message>
+      <message desc="The Switch Access action to scroll the selected element right. Should be short." name="IDS_SWITCH_ACCESS_SCROLL_RIGHT">
+        Scroll right
+      </message>
+      <message desc="The Switch Access action to scroll the selected element left. Should be short." name="IDS_SWITCH_ACCESS_SCROLL_LEFT">
+        Scroll left
+      </message>
+      <message desc="The Switch Access action to scroll the selected element logically forward (generally either down or right, depending on the context). Should be short." name="IDS_SWITCH_ACCESS_SCROLL_FORWARD">
+        Scroll forward
+      </message>
+      <message desc="The Switch Access action to scroll the selected element logically backward (generally either up or left, depending on the context). Should be short." name="IDS_SWITCH_ACCESS_SCROLL_BACKWARD">
+        Scroll backward
+      </message>
+      <message desc="The Switch Access action to speak to type in the selected text input element. Ideally the same as the name of the standalone Dictation feature (IDS_ASH_STATUS_TRAY_ACCESSIBILITY_DICTATION). Should be short." name="IDS_SWITCH_ACCESS_DICTATION">
+        Dictation
+      </message>
+      <message desc="The Switch Access action to show the system context menu, as when a user right-clicks on the focused element. Should be short." name="IDS_SWITCH_ACCESS_SHOW_CONTEXT_MENU">
+        Context menu
+      </message>
+      <message desc="The Switch Access action to open the Switch Access settings page. Should be short." name="IDS_SWITCH_ACCESS_SETTINGS_ACTION">
+        Settings
+      </message>
     </messages>
   </release>
 </grit>
diff --git a/chrome/browser/resources/chromeos/switch_access/strings/switch_access_strings_grd/IDS_SWITCH_ACCESS_DECREMENT.png.sha1 b/chrome/browser/resources/chromeos/switch_access/strings/switch_access_strings_grd/IDS_SWITCH_ACCESS_DECREMENT.png.sha1
new file mode 100644
index 0000000..b546f00
--- /dev/null
+++ b/chrome/browser/resources/chromeos/switch_access/strings/switch_access_strings_grd/IDS_SWITCH_ACCESS_DECREMENT.png.sha1
@@ -0,0 +1 @@
+4f6c1c2a63f0eaffa4a95aa79f29242ddc1009f7
\ No newline at end of file
diff --git a/chrome/browser/resources/chromeos/switch_access/strings/switch_access_strings_grd/IDS_SWITCH_ACCESS_DICTATION.png.sha1 b/chrome/browser/resources/chromeos/switch_access/strings/switch_access_strings_grd/IDS_SWITCH_ACCESS_DICTATION.png.sha1
new file mode 100644
index 0000000..da70638
--- /dev/null
+++ b/chrome/browser/resources/chromeos/switch_access/strings/switch_access_strings_grd/IDS_SWITCH_ACCESS_DICTATION.png.sha1
@@ -0,0 +1 @@
+7ef9b7141351053e543b20774177e8a6bd79c93a
\ No newline at end of file
diff --git a/chrome/browser/resources/chromeos/switch_access/strings/switch_access_strings_grd/IDS_SWITCH_ACCESS_INCREMENT.png.sha1 b/chrome/browser/resources/chromeos/switch_access/strings/switch_access_strings_grd/IDS_SWITCH_ACCESS_INCREMENT.png.sha1
new file mode 100644
index 0000000..b546f00
--- /dev/null
+++ b/chrome/browser/resources/chromeos/switch_access/strings/switch_access_strings_grd/IDS_SWITCH_ACCESS_INCREMENT.png.sha1
@@ -0,0 +1 @@
+4f6c1c2a63f0eaffa4a95aa79f29242ddc1009f7
\ No newline at end of file
diff --git a/chrome/browser/resources/chromeos/switch_access/strings/switch_access_strings_grd/IDS_SWITCH_ACCESS_OPEN_KEYBOARD.png.sha1 b/chrome/browser/resources/chromeos/switch_access/strings/switch_access_strings_grd/IDS_SWITCH_ACCESS_OPEN_KEYBOARD.png.sha1
new file mode 100644
index 0000000..da70638
--- /dev/null
+++ b/chrome/browser/resources/chromeos/switch_access/strings/switch_access_strings_grd/IDS_SWITCH_ACCESS_OPEN_KEYBOARD.png.sha1
@@ -0,0 +1 @@
+7ef9b7141351053e543b20774177e8a6bd79c93a
\ No newline at end of file
diff --git a/chrome/browser/resources/chromeos/switch_access/strings/switch_access_strings_grd/IDS_SWITCH_ACCESS_SCROLL_BACKWARD.png.sha1 b/chrome/browser/resources/chromeos/switch_access/strings/switch_access_strings_grd/IDS_SWITCH_ACCESS_SCROLL_BACKWARD.png.sha1
new file mode 100644
index 0000000..d01761a
--- /dev/null
+++ b/chrome/browser/resources/chromeos/switch_access/strings/switch_access_strings_grd/IDS_SWITCH_ACCESS_SCROLL_BACKWARD.png.sha1
@@ -0,0 +1 @@
+a5e7fa3a053590ed40b9dfa7395c8a0a56c02bac
\ No newline at end of file
diff --git a/chrome/browser/resources/chromeos/switch_access/strings/switch_access_strings_grd/IDS_SWITCH_ACCESS_SCROLL_DOWN.png.sha1 b/chrome/browser/resources/chromeos/switch_access/strings/switch_access_strings_grd/IDS_SWITCH_ACCESS_SCROLL_DOWN.png.sha1
new file mode 100644
index 0000000..675c9295
--- /dev/null
+++ b/chrome/browser/resources/chromeos/switch_access/strings/switch_access_strings_grd/IDS_SWITCH_ACCESS_SCROLL_DOWN.png.sha1
@@ -0,0 +1 @@
+35600a646b9828621160b38640ab865e95a93779
\ No newline at end of file
diff --git a/chrome/browser/resources/chromeos/switch_access/strings/switch_access_strings_grd/IDS_SWITCH_ACCESS_SCROLL_FORWARD.png.sha1 b/chrome/browser/resources/chromeos/switch_access/strings/switch_access_strings_grd/IDS_SWITCH_ACCESS_SCROLL_FORWARD.png.sha1
new file mode 100644
index 0000000..d01761a
--- /dev/null
+++ b/chrome/browser/resources/chromeos/switch_access/strings/switch_access_strings_grd/IDS_SWITCH_ACCESS_SCROLL_FORWARD.png.sha1
@@ -0,0 +1 @@
+a5e7fa3a053590ed40b9dfa7395c8a0a56c02bac
\ No newline at end of file
diff --git a/chrome/browser/resources/chromeos/switch_access/strings/switch_access_strings_grd/IDS_SWITCH_ACCESS_SCROLL_LEFT.png.sha1 b/chrome/browser/resources/chromeos/switch_access/strings/switch_access_strings_grd/IDS_SWITCH_ACCESS_SCROLL_LEFT.png.sha1
new file mode 100644
index 0000000..b7030ff
--- /dev/null
+++ b/chrome/browser/resources/chromeos/switch_access/strings/switch_access_strings_grd/IDS_SWITCH_ACCESS_SCROLL_LEFT.png.sha1
@@ -0,0 +1 @@
+32082b618afdc0dde1e316d8a6e203f2a0a2f481
\ No newline at end of file
diff --git a/chrome/browser/resources/chromeos/switch_access/strings/switch_access_strings_grd/IDS_SWITCH_ACCESS_SCROLL_RIGHT.png.sha1 b/chrome/browser/resources/chromeos/switch_access/strings/switch_access_strings_grd/IDS_SWITCH_ACCESS_SCROLL_RIGHT.png.sha1
new file mode 100644
index 0000000..b7030ff
--- /dev/null
+++ b/chrome/browser/resources/chromeos/switch_access/strings/switch_access_strings_grd/IDS_SWITCH_ACCESS_SCROLL_RIGHT.png.sha1
@@ -0,0 +1 @@
+32082b618afdc0dde1e316d8a6e203f2a0a2f481
\ No newline at end of file
diff --git a/chrome/browser/resources/chromeos/switch_access/strings/switch_access_strings_grd/IDS_SWITCH_ACCESS_SCROLL_UP.png.sha1 b/chrome/browser/resources/chromeos/switch_access/strings/switch_access_strings_grd/IDS_SWITCH_ACCESS_SCROLL_UP.png.sha1
new file mode 100644
index 0000000..675c9295
--- /dev/null
+++ b/chrome/browser/resources/chromeos/switch_access/strings/switch_access_strings_grd/IDS_SWITCH_ACCESS_SCROLL_UP.png.sha1
@@ -0,0 +1 @@
+35600a646b9828621160b38640ab865e95a93779
\ No newline at end of file
diff --git a/chrome/browser/resources/chromeos/switch_access/strings/switch_access_strings_grd/IDS_SWITCH_ACCESS_SELECT.png.sha1 b/chrome/browser/resources/chromeos/switch_access/strings/switch_access_strings_grd/IDS_SWITCH_ACCESS_SELECT.png.sha1
new file mode 100644
index 0000000..b546f00
--- /dev/null
+++ b/chrome/browser/resources/chromeos/switch_access/strings/switch_access_strings_grd/IDS_SWITCH_ACCESS_SELECT.png.sha1
@@ -0,0 +1 @@
+4f6c1c2a63f0eaffa4a95aa79f29242ddc1009f7
\ No newline at end of file
diff --git a/chrome/browser/resources/chromeos/switch_access/strings/switch_access_strings_grd/IDS_SWITCH_ACCESS_SETTINGS_ACTION.png.sha1 b/chrome/browser/resources/chromeos/switch_access/strings/switch_access_strings_grd/IDS_SWITCH_ACCESS_SETTINGS_ACTION.png.sha1
new file mode 100644
index 0000000..da70638
--- /dev/null
+++ b/chrome/browser/resources/chromeos/switch_access/strings/switch_access_strings_grd/IDS_SWITCH_ACCESS_SETTINGS_ACTION.png.sha1
@@ -0,0 +1 @@
+7ef9b7141351053e543b20774177e8a6bd79c93a
\ No newline at end of file
diff --git a/chrome/browser/resources/chromeos/switch_access/strings/switch_access_strings_grd/IDS_SWITCH_ACCESS_SHOW_CONTEXT_MENU.png.sha1 b/chrome/browser/resources/chromeos/switch_access/strings/switch_access_strings_grd/IDS_SWITCH_ACCESS_SHOW_CONTEXT_MENU.png.sha1
new file mode 100644
index 0000000..da70638
--- /dev/null
+++ b/chrome/browser/resources/chromeos/switch_access/strings/switch_access_strings_grd/IDS_SWITCH_ACCESS_SHOW_CONTEXT_MENU.png.sha1
@@ -0,0 +1 @@
+7ef9b7141351053e543b20774177e8a6bd79c93a
\ No newline at end of file