@@ -839,6 +839,8 @@ Code.init = function (toolbox) {
839839 ctx = Code . getContext ( ) ;
840840
841841 launcher . loadTemplate ( './templates/' + ctx . tpl + '.html' , function ( data ) {
842+ data . body = launcher . translate ( data . body , MSG ) ;
843+
842844 if ( ctx . jsPreprocessor === 'babel' ) {
843845 data . js = Code . transform ( ctx . data . js ) ;
844846 } else {
@@ -863,7 +865,6 @@ Code.init = function (toolbox) {
863865 var ctx = Code . getContext ( ) ,
864866 urls = Code . getUrlParts ( ) ;
865867 urls . pop ( ) ;
866- ctx . lang = Code . LANG ;
867868 localStorage . setItem ( urls . join ( '/' ) + '/launcher.html' , JSON . stringify ( ctx ) ) ;
868869 } ) ;
869870
@@ -1061,17 +1062,7 @@ Code.reloadSandbox = function () {
10611062 Code . sandboxLoaded = false ;
10621063
10631064 launcher . loadTemplate ( './templates/' + ctx . tpl + '.html' , function ( data ) {
1064-
1065- var $body = $ ( '<div/>' , {
1066- html : data . body
1067- } ) ;
1068- // find if element has translation
1069- $body . find ( '[data-translation]' ) . each ( function ( ) {
1070- // Translate string with locale file in /msg
1071- $ ( this ) . html ( window . MSG [ $ ( this ) . data ( 'translation' ) ] ) . removeAttr ( 'data-translation' ) ;
1072- } ) ;
1073- // covert element to string
1074- data . body = $body . clone ( ) . wrap ( '<div/>' ) . parent ( ) . html ( ) ;
1065+ data . body = launcher . translate ( data . body , MSG ) ;
10751066
10761067 if ( Code . running ) {
10771068 if ( ctx . jsPreprocessor === 'babel' ) {
@@ -1174,10 +1165,13 @@ Code.unhookEvents = function (window, frame) {
11741165Code . getContext = function ( ) {
11751166 var code = Blockly . JavaScript . workspaceToCode ( Code . workspace ) ,
11761167 babelize = code . indexOf ( 'async function' ) !== - 1 ,
1177- page = Code . PAGE ;
1168+ page = Code . PAGE ,
1169+ lang = Code . LANG ;
11781170
11791171 return {
1172+ page : page ,
11801173 tpl : page === 'index' ? Code . getDemoPage ( ) : page ,
1174+ lang : lang ,
11811175 modes : 'html,css,js,output' ,
11821176 data : {
11831177 js : code
@@ -1240,6 +1234,13 @@ Code.getBlockDemo = function (type) {
12401234 return null ;
12411235} ;
12421236
1237+ Code . getBlockTypes = function ( ) {
1238+ var xml = Blockly . Xml . workspaceToDom ( Code . workspace ) ;
1239+ return slice . call ( xml . querySelectorAll ( 'block' ) ) . map ( function ( block ) {
1240+ return block . getAttribute ( 'type' ) ;
1241+ } ) ;
1242+ } ;
1243+
12431244Blockly . JavaScript [ 'procedures_defnoreturn' ] = function ( block ) {
12441245 // Define a procedure with a return value.
12451246 var funcName = Blockly . JavaScript . variableDB_ . getName (
@@ -1318,11 +1319,9 @@ Blockly.Xml._domToWorkspace = Blockly.Xml.domToWorkspace;
13181319
13191320Blockly . Xml . domToWorkspace = function ( ) {
13201321 Blockly . Xml . _domToWorkspace . apply ( this , arguments ) ;
1321- var xml = Blockly . Xml . workspaceToDom ( Code . workspace ) ;
1322- var blocks = slice . call ( xml . querySelectorAll ( 'block' ) ) ;
1323- for ( var i = 0 ; i < blocks . length ; i ++ ) {
1324- var type = blocks [ i ] . getAttribute ( 'type' ) ;
1325- var demo = Code . getBlockDemo ( type ) ;
1322+ var types = Code . getBlockTypes ( ) ;
1323+ for ( var i = 0 ; i < types . length ; i ++ ) {
1324+ var demo = Code . getBlockDemo ( types [ i ] ) ;
13261325 if ( demo ) {
13271326 if ( demo !== Code . queryString . get ( 'demo' ) ) {
13281327 Code . queryString . set ( 'demo' , demo ) ;
0 commit comments