Commit 1075b89a authored by Akihiro Ota's avatar Akihiro Ota Committed by Commit Bot

ChromeVox Cleanup: Shorten PhoneticData API name.

Bug: N/A
Change-Id: Idc2bd9e15811692ba976c60a35c65e248a7aa8ca
Relnotes: N/A
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2157775
Commit-Queue: Akihiro Ota <akihiroota@chromium.org>
Reviewed-by: default avatarDavid Tseng <dtseng@chromium.org>
Cr-Commit-Position: refs/heads/master@{#761052}
parent 406f8c3b
...@@ -1011,12 +1011,10 @@ CommandHandler.onCommand = function(command) { ...@@ -1011,12 +1011,10 @@ CommandHandler.onCommand = function(command) {
// Get unicode-aware array of characters. // Get unicode-aware array of characters.
const characterArray = [...word]; const characterArray = [...word];
// We currently only load phonetic data for the browser UI language.
const language = chrome.i18n.getUILanguage(); const language = chrome.i18n.getUILanguage();
for (let i = 0; i < characterArray.length; ++i) { for (let i = 0; i < characterArray.length; ++i) {
const character = characterArray[i]; const character = characterArray[i];
const phoneticText = const phoneticText = PhoneticData.forCharacter(character, language);
PhoneticData.getPhoneticDisambiguation(language, character);
// Speak the character followed by its phonetic disambiguation, if it // Speak the character followed by its phonetic disambiguation, if it
// was found. // was found.
new Output() new Output()
......
...@@ -20,22 +20,25 @@ PhoneticData.init = function() { ...@@ -20,22 +20,25 @@ PhoneticData.init = function() {
}; };
/** /**
* Returns the phonetic disambiguation for |character| in |locale|. * Returns the phonetic disambiguation for |char| in |locale|.
* Returns empty string if disambiguation can't be found. * Returns empty string if disambiguation can't be found.
* @param {string} char
* @param {string} locale * @param {string} locale
* @param {string} character
* @return {string} * @return {string}
*/ */
PhoneticData.getPhoneticDisambiguation = function(locale, character) { PhoneticData.forCharacter = function(char, locale) {
const phoneticDictionaries = const phoneticDictionaries =
chrome.extension.getBackgroundPage().PhoneticDictionaries; chrome.extension.getBackgroundPage().PhoneticDictionaries;
if (!locale || !character || !phoneticDictionaries || if (!phoneticDictionaries || !phoneticDictionaries.phoneticMap_) {
!phoneticDictionaries.phoneticMap_) { throw Error('PhoneticDictionaries map must be defined.');
return ''; }
if (!char || !locale) {
throw Error('PhoneticData api requires non-empty arguments.');
} }
char = char.toLowerCase();
locale = locale.toLowerCase(); locale = locale.toLowerCase();
character = character.toLowerCase();
let map = null; let map = null;
if (locale === 'ja') { if (locale === 'ja') {
map = JaPhoneticData.phoneticMap_; map = JaPhoneticData.phoneticMap_;
...@@ -50,5 +53,5 @@ PhoneticData.getPhoneticDisambiguation = function(locale, character) { ...@@ -50,5 +53,5 @@ PhoneticData.getPhoneticDisambiguation = function(locale, character) {
return ''; return '';
} }
return map[character] || ''; return map[char] || '';
}; };
...@@ -726,8 +726,7 @@ TtsBackground = class extends ChromeTtsBase { ...@@ -726,8 +726,7 @@ TtsBackground = class extends ChromeTtsBase {
properties['lang'] = chrome.i18n.getUILanguage(); properties['lang'] = chrome.i18n.getUILanguage();
} }
const phoneticText = const phoneticText = PhoneticData.forCharacter(text, properties['lang']);
PhoneticData.getPhoneticDisambiguation(properties['lang'], text);
if (phoneticText) { if (phoneticText) {
properties['delay'] = true; properties['delay'] = true;
this.speak(phoneticText, QueueMode.QUEUE, properties); this.speak(phoneticText, QueueMode.QUEUE, properties);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment