- Allows use of Blockly's messaging format for category name, colour,… (#1028)

...in toolbox XML.
- Updated code editor demo to use this message format
- Re-built blockly_compressed.js
This commit is contained in:
vicng
2017-04-07 15:32:50 -07:00
committed by GitHub
parent dfc50ba843
commit ae2aaa2159
4 changed files with 49 additions and 30 deletions

View File

@@ -383,10 +383,22 @@ Code.init = function() {
};
window.addEventListener('resize', onresize, false);
// Interpolate translated messages into toolbox.
// The toolbox XML specifies each category name using Blockly's messaging
// format (eg. `<category name="%{BKY_CATLOGIC}">`).
// These message keys need to be defined in `Blockly.Msg` in order to
// be decoded by the library. Therefore, we'll use the `MSG` dictionary that's
// been defined for each language to import each category name message
// into `Blockly.Msg`.
// TODO: Clean up the message files so this is done explicitly instead of
// through this for-loop.
for (var messageKey in MSG) {
if (messageKey.startsWith('cat')) {
Blockly.Msg[messageKey.toUpperCase()] = MSG[messageKey];
}
}
// Construct the toolbox XML.
var toolboxText = document.getElementById('toolbox').outerHTML;
toolboxText = toolboxText.replace(/{(\w+)}/g,
function(m, p1) {return MSG[p1];});
var toolboxXml = Blockly.Xml.textToDom(toolboxText);
Code.workspace = Blockly.inject('content_blocks',

View File

@@ -74,7 +74,7 @@
<textarea id="content_xml" class="content" wrap="off"></textarea>
<xml id="toolbox" style="display: none">
<category name="{catLogic}" colour="210">
<category name="%{BKY_CATLOGIC}" colour="%{BKY_LOGIC_HUE}">
<block type="controls_if"></block>
<block type="logic_compare"></block>
<block type="logic_operation"></block>
@@ -83,7 +83,7 @@
<block type="logic_null"></block>
<block type="logic_ternary"></block>
</category>
<category name="{catLoops}" colour="120">
<category name="%{BKY_CATLOOPS}" colour="%{BKY_LOOPS_HUE}">
<block type="controls_repeat_ext">
<value name="TIMES">
<shadow type="math_number">
@@ -112,7 +112,7 @@
<block type="controls_forEach"></block>
<block type="controls_flow_statements"></block>
</category>
<category name="{catMath}" colour="230">
<category name="%{BKY_CATMATH}" colour="%{BKY_MATH_HUE}">
<block type="math_number"></block>
<block type="math_arithmetic">
<value name="A">
@@ -199,7 +199,7 @@
</block>
<block type="math_random_float"></block>
</category>
<category name="{catText}" colour="160">
<category name="%{BKY_CATTEXT}" colour="%{BKY_TEXTS_HUE}">
<block type="text"></block>
<block type="text_join"></block>
<block type="text_append">
@@ -276,7 +276,7 @@
</value>
</block>
</category>
<category name="{catLists}" colour="260">
<category name="%{BKY_CATLISTS}" colour="%{BKY_LISTS_HUE}">
<block type="lists_create_with">
<mutation items="0"></mutation>
</block>
@@ -327,7 +327,7 @@
</block>
<block type="lists_sort"></block>
</category>
<category name="{catColour}" colour="20">
<category name="%{BKY_CATCOLOUR}" colour="%{BKY_COLOUR_HUE}">
<block type="colour_picker"></block>
<block type="colour_random"></block>
<block type="colour_rgb">
@@ -366,8 +366,8 @@
</block>
</category>
<sep></sep>
<category name="{catVariables}" colour="330" custom="VARIABLE"></category>
<category name="{catFunctions}" colour="290" custom="PROCEDURE"></category>
<category name="%{BKY_CATVARIABLES}" colour="%{BKY_VARIABLES_HUE}" custom="VARIABLE"></category>
<category name="%{BKY_CATFUNCTIONS}" colour="%{BKY_PROCEDURES_HUE}" custom="PROCEDURE"></category>
</xml>
</body>