From f615e9191af90bd6e08530f1de5e07806fcfff4b Mon Sep 17 00:00:00 2001 From: picklesrus Date: Mon, 28 May 2018 11:58:17 -0700 Subject: [PATCH 1/3] Add language reporter block to translate extension --- src/extensions/scratch3_translate/index.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/extensions/scratch3_translate/index.js b/src/extensions/scratch3_translate/index.js index 0e7586dcd..67364cf07 100644 --- a/src/extensions/scratch3_translate/index.js +++ b/src/extensions/scratch3_translate/index.js @@ -100,6 +100,12 @@ class Scratch3TranslateBlocks { defaultValue: this._viewerLanguageCode } } + }, + { + opcode: 'getViewerLanguage', + text: 'viewer language', + blockType: BlockType.REPORTER, + arguments: {} } ], menus: { @@ -108,6 +114,13 @@ class Scratch3TranslateBlocks { }; } + /** + * Get the viewer language for the reporter block. + * @return {string} the language code of the project viewer. + */ + getViewerLanguage () { + return this._viewerLanguageCode; + } /** * Get the viewer's language code. From e2f6dfd29f6729d204bb7aba978af71eddbf6f27 Mon Sep 17 00:00:00 2001 From: picklesrus Date: Tue, 29 May 2018 15:06:38 -0700 Subject: [PATCH 2/3] - Update the reporter to return the human readable language. - Remove the non-final icons and replace with a TODO. - Add messages for the text in the blocks. --- src/extensions/scratch3_translate/index.js | 38 +++++++++++++++------- 1 file changed, 27 insertions(+), 11 deletions(-) diff --git a/src/extensions/scratch3_translate/index.js b/src/extensions/scratch3_translate/index.js index 67364cf07..d9869ec40 100644 --- a/src/extensions/scratch3_translate/index.js +++ b/src/extensions/scratch3_translate/index.js @@ -6,9 +6,6 @@ const nets = require('nets'); const languageNames = require('scratch-translate-extension-languages'); const formatMessage = require('format-message'); -// TODO: Change these to the correct icons. -const blockIconURI = 'https://www.gstatic.com/images/icons/material/system/1x/translate_white_24dp.png'; -const menuIconURI = 'https://www.gstatic.com/images/icons/material/system/1x/translate_grey600_24dp.png'; /** * The url of the translate server. @@ -82,17 +79,25 @@ class Scratch3TranslateBlocks { return { id: 'translate', name: 'Translate', - menuIconURI: menuIconURI, - blockIconURI: blockIconURI, + menuIconURI: '', // TODO: Add the final icons. + blockIconURI: '', blocks: [ { opcode: 'getTranslate', - text: 'translate [WORDS] to [LANGUAGE]', + text: formatMessage({ + id: 'translate.translateBlock', + default: 'translate [WORDS] to [LANGUAGE]', + description: 'translate some text to a different language' + }), blockType: BlockType.REPORTER, arguments: { WORDS: { type: ArgumentType.STRING, - defaultValue: 'hello' + defaultValue: formatMessage({ + id: 'translate.defaultTextToTranslate', + default: 'hello', + description: 'hello: the default text to translate' + }) }, LANGUAGE: { type: ArgumentType.STRING, @@ -103,7 +108,11 @@ class Scratch3TranslateBlocks { }, { opcode: 'getViewerLanguage', - text: 'viewer language', + text: formatMessage({ + id: 'translate.viewerLanguage', + default: 'viewer language', + description: 'the languge of the project viewer' + }), blockType: BlockType.REPORTER, arguments: {} } @@ -115,11 +124,18 @@ class Scratch3TranslateBlocks { } /** - * Get the viewer language for the reporter block. - * @return {string} the language code of the project viewer. + * Get the human readable language value for the reporter block. + * @return {string} the language name of the project viewer. */ getViewerLanguage () { - return this._viewerLanguageCode; + this._viewerLanguageCode = this.getViewerLanguageCode(); + const names = languageNames.menuMap[this._viewerLanguageCode]; + const langNameObj = names.find(obj => obj.code === this._viewerLanguageCode); + let langName = this._viewerLanguageCode; + if (langNameObj) { + langName = langNameObj.name; + } + return langName; } /** From 123edcb91366143de63bdf98b18feac3289a956a Mon Sep 17 00:00:00 2001 From: picklesrus Date: Tue, 29 May 2018 15:14:38 -0700 Subject: [PATCH 3/3] remove stray space --- src/extensions/scratch3_translate/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/extensions/scratch3_translate/index.js b/src/extensions/scratch3_translate/index.js index d9869ec40..f8f559eab 100644 --- a/src/extensions/scratch3_translate/index.js +++ b/src/extensions/scratch3_translate/index.js @@ -79,7 +79,7 @@ class Scratch3TranslateBlocks { return { id: 'translate', name: 'Translate', - menuIconURI: '', // TODO: Add the final icons. + menuIconURI: '', // TODO: Add the final icons. blockIconURI: '', blocks: [ {