Check and set language, handling many-to-one mapping

This commit is contained in:
Eric Rosenbaum 2019-03-05 17:38:54 -05:00
parent ab633d3448
commit d059f8baa6

View file

@ -476,7 +476,14 @@ class Scratch3Text2SpeechBlocks {
if (!stage) return; if (!stage) return;
// Only set the language if it is in the list. // Only set the language if it is in the list.
if (this.isSupportedLanguage(languageCode)) { if (this.isSupportedLanguage(languageCode)) {
stage.textToSpeechLanguage = languageCode; // Set the language code used by the extension. There are a few
// languages where we map multiple written languages to one spoken
// language.
for (const lang in this.LANGUAGE_INFO) {
if (this.LANGUAGE_INFO[lang].locales.includes(languageCode)) {
stage.textToSpeechLanguage = lang;
}
}
} }
// If the language is null, set it to the default language. // If the language is null, set it to the default language.
// This can occur e.g. if the extension was loaded with the editor // This can occur e.g. if the extension was loaded with the editor
@ -500,13 +507,18 @@ class Scratch3Text2SpeechBlocks {
} }
/** /**
* Check if a language code is in the list of supported languages for the * Check if a Scratch language code is in the list of supported languages for the
* speech synthesis service. * speech synthesis service.
* @param {string} languageCode the language code to check. * @param {string} languageCode the language code to check.
* @returns {boolean} true if the language code is supported. * @returns {boolean} true if the language code is supported.
*/ */
isSupportedLanguage (languageCode) { isSupportedLanguage (languageCode) {
return Object.keys(this.LANGUAGE_INFO).includes(languageCode); for (const lang in this.LANGUAGE_INFO) {
if (this.LANGUAGE_INFO[lang].locales.includes(languageCode)) {
return true;
}
}
return false;
} }
/** /**