Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1719)

Unified Diff: chrome/browser/resources/chromeos/chromevox/host/chrome/tts_background.js

Issue 2506203002: Fix language switching (Closed)
Patch Set: No tts lang. Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | chrome/browser/resources/chromeos/chromevox/host/chrome/tts_background_test.extjs » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/resources/chromeos/chromevox/host/chrome/tts_background.js
diff --git a/chrome/browser/resources/chromeos/chromevox/host/chrome/tts_background.js b/chrome/browser/resources/chromeos/chromevox/host/chrome/tts_background.js
index f8bf898a6a625996064ae6425745a58c4af174c9..be031a9bf8d780ea4cbd1b544d4f2996d5add30d 100644
--- a/chrome/browser/resources/chromeos/chromevox/host/chrome/tts_background.js
+++ b/chrome/browser/resources/chromeos/chromevox/host/chrome/tts_background.js
@@ -57,7 +57,7 @@ cvox.TtsBackground = function(opt_enableMath) {
// specified.
if (this.ttsProperties['lang'] == undefined) {
this.ttsProperties['lang'] =
- chrome.i18n.getMessage('@@ui_locale').replace('_', '-');
+ chrome.i18n.getUILanguage();
}
this.lastEventType = 'end';
@@ -680,24 +680,30 @@ cvox.TtsBackground.prototype.clearTimeout_ = function() {
* Update the current voice used to speak based upon values in storage. If that
* does not succeed, fallback to use system locale when picking a voice.
* @param {string} voiceName Voice name to set.
+ * @param {function(string) : void=} opt_callback Called when the voice is
+ * determined.
* @private
*/
-cvox.TtsBackground.prototype.updateVoice_ = function(voiceName) {
+cvox.TtsBackground.prototype.updateVoice_ = function(voiceName, opt_callback) {
chrome.tts.getVoices(goog.bind(function(voices) {
- var currentLocale = chrome.i18n.getMessage('@@ui_locale').replace('_', '-');
-
- // TODO(dtseng): Prefer voices having the default property once we switch to
- // web speech. See crbug.com/544139.
-
- var newVoice = voices.find(
- function(v) { return v.voiceName == voiceName; }) ||
- voices.find(function(v) { return v.lang === currentLocale; }) ||
- voices.find(function(v) { return currentLocale.startsWith(v.lang); }) ||
- voices[0];
-
- if (newVoice) {
- this.currentVoice = newVoice.voiceName;
- this.startSpeakingNextItemInQueue_();
- }
+ chrome.i18n.getAcceptLanguages(goog.bind(function(acceptLanguages) {
+ var currentLocale = acceptLanguages[0] ||
+ chrome.i18n.getUILanguage() || '';
+ var match = voices.find.bind(voices);
+ var newVoice =
+ match(function(v) { return v.voiceName == voiceName; }) ||
+ match(function(v) { return v.lang === currentLocale; }) ||
+ match(function(v) { return currentLocale.startsWith(v.lang); }) ||
+ match(function(v) { return v.lang &&
+ v.lang.startsWith(currentLocale); }) ||
+ voices[0];
+
+ if (newVoice) {
+ this.currentVoice = newVoice.voiceName;
+ this.startSpeakingNextItemInQueue_();
+ }
+ if (opt_callback)
+ opt_callback(this.currentVoice);
+ }, this));
}, this));
};
« no previous file with comments | « no previous file | chrome/browser/resources/chromeos/chromevox/host/chrome/tts_background_test.extjs » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698