mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2024-12-24 23:12:24 -05:00
Check and set language, handling many-to-one mapping
This commit is contained in:
parent
ab633d3448
commit
d059f8baa6
1 changed files with 15 additions and 3 deletions
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue