From 5ba476c8334d5aef235610f70f139bc44c0070e3 Mon Sep 17 00:00:00 2001 From: Eric Rosenbaum Date: Tue, 10 Sep 2019 18:37:21 -0400 Subject: [PATCH] Working localized Text to Speech language menu with dummy data --- src/extensions/scratch3_text2speech/index.js | 60 ++++++++++++++++++-- 1 file changed, 56 insertions(+), 4 deletions(-) diff --git a/src/extensions/scratch3_text2speech/index.js b/src/extensions/scratch3_text2speech/index.js index 747912322..f2c542940 100644 --- a/src/extensions/scratch3_text2speech/index.js +++ b/src/extensions/scratch3_text2speech/index.js @@ -1,5 +1,6 @@ const formatMessage = require('format-message'); const nets = require('nets'); +const languageNames = require('scratch-translate-extension-languages'); const ArgumentType = require('../../extension-support/argument-type'); const BlockType = require('../../extension-support/block-type'); @@ -588,10 +589,61 @@ class Scratch3Text2SpeechBlocks { * @return {array} the text and value for each menu item. */ getLanguageMenu () { - return Object.keys(this.LANGUAGE_INFO).map(key => ({ - text: this.LANGUAGE_INFO[key].name, - value: key - })); + // Mock data to use until we update the scratch-translate-extension-languages + // module. + languageNames.spokenLanguages = { + en: [ + { + code: 'zh-cn', + name: 'Chinese (Mandarin)' + } + ], + es: [ + { + code: 'zh-cn', + name: 'Chino (Mandarín)' + }, + { + code: 'hi', + name: 'Hindi' + }, + { + code: 'pt-br', + name: 'Portugués (Brasileiro)' + }, + { + code: 'es-419', + name: 'Español (Latinoamericano)' + } + ] + }; + + // Get the array of localized language names + let nameArray = languageNames.menuMap[this.getEditorLanguage()]; + // Also, get any localized names of spoken languages + const spokenNameArray = languageNames.spokenLanguages[this.getEditorLanguage()]; + if (spokenNameArray) { + nameArray = nameArray.concat(spokenNameArray); + } + // Create a map of language code to localized name + const localizedNameMap = {}; + nameArray.forEach(lang => { + localizedNameMap[lang.code] = lang.name; + }); + + return Object.keys(this.LANGUAGE_INFO).map(key => { + let name = this.LANGUAGE_INFO[key].name; + const localizedName = localizedNameMap[key]; + if (localizedName) { + name = localizedName; + } + // Uppercase the first character of the name + name = name.charAt(0).toUpperCase() + name.slice(1); + return { + text: name, + value: key + }; + }); } /**