@@ -22,6 +22,7 @@ import * as React from 'react';
2222import * as Blockly from 'blockly/core' ;
2323import * as En from 'blockly/msg/en' ;
2424import * as Es from 'blockly/msg/es' ;
25+ import * as He from 'blockly/msg/he' ;
2526import { customTokens } from '../blocks/tokens' ;
2627
2728import { themes } from '../themes/mrc_themes' ;
@@ -140,6 +141,20 @@ const BlocklyComponent = React.forwardRef<BlocklyComponentType | null, BlocklyCo
140141 if ( ! workspaceRef . current ) {
141142 return ;
142143 }
144+
145+ const newIsRtl = i18n . dir ( ) === 'rtl' ;
146+ const currentIsRtl = workspaceRef . current . RTL ;
147+
148+ // If RTL direction changed, we need to recreate the workspace
149+ if ( newIsRtl !== currentIsRtl ) {
150+ cleanupWorkspace ( ) ;
151+ initializeWorkspace ( ) ;
152+ if ( props . onWorkspaceRecreated ) {
153+ props . onWorkspaceRecreated ( workspaceRef . current ! ) ;
154+ }
155+ return ;
156+ }
157+
143158 // Set new locale
144159 switch ( i18n . language ) {
145160 case 'es' :
@@ -148,6 +163,9 @@ const BlocklyComponent = React.forwardRef<BlocklyComponentType | null, BlocklyCo
148163 case 'en' :
149164 Blockly . setLocale ( En as any ) ;
150165 break ;
166+ case 'he' :
167+ Blockly . setLocale ( He as any ) ;
168+ break ;
151169 default :
152170 Blockly . setLocale ( En as any ) ;
153171 break ;
@@ -175,6 +193,9 @@ const BlocklyComponent = React.forwardRef<BlocklyComponentType | null, BlocklyCo
175193 case 'en' :
176194 Blockly . setLocale ( En as any ) ;
177195 break ;
196+ case 'he' :
197+ Blockly . setLocale ( He as any ) ;
198+ break ;
178199 default :
179200 Blockly . setLocale ( En as any ) ;
180201 break ;
@@ -183,6 +204,7 @@ const BlocklyComponent = React.forwardRef<BlocklyComponentType | null, BlocklyCo
183204
184205 // Create workspace
185206 const workspaceConfig = createWorkspaceConfig ( ) ;
207+ workspaceConfig . rtl = i18n . dir ( ) === 'rtl' ;
186208 const workspace = Blockly . inject ( blocklyDiv . current , workspaceConfig ) ;
187209 workspaceRef . current = workspace ;
188210 } ;
0 commit comments