mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2024-12-24 06:52:40 -05:00
Merge pull request #1178 from picklesrus/translate-language-reporter-block
Add language reporter block to translate extension
This commit is contained in:
commit
057e89b1e0
1 changed files with 36 additions and 7 deletions
|
@ -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,
|
||||
|
@ -100,6 +105,16 @@ class Scratch3TranslateBlocks {
|
|||
defaultValue: this._viewerLanguageCode
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
opcode: 'getViewerLanguage',
|
||||
text: formatMessage({
|
||||
id: 'translate.viewerLanguage',
|
||||
default: 'viewer language',
|
||||
description: 'the languge of the project viewer'
|
||||
}),
|
||||
blockType: BlockType.REPORTER,
|
||||
arguments: {}
|
||||
}
|
||||
],
|
||||
menus: {
|
||||
|
@ -108,6 +123,20 @@ class Scratch3TranslateBlocks {
|
|||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the human readable language value for the reporter block.
|
||||
* @return {string} the language name of the project viewer.
|
||||
*/
|
||||
getViewerLanguage () {
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the viewer's language code.
|
||||
|
|
Loading…
Reference in a new issue