|
20 | 20 | */ |
21 | 21 | import * as React from 'react'; |
22 | 22 | import * as Blockly from 'blockly/core'; |
23 | | -import * as locale from 'blockly/msg/en'; |
| 23 | +import * as En from 'blockly/msg/en'; |
| 24 | +import * as Es from 'blockly/msg/es'; |
| 25 | +import { customTokens } from '../blocks/tokens'; |
| 26 | + |
24 | 27 | import { themes } from '../themes/mrc_themes'; |
25 | 28 | import {pluginInfo as HardwareConnectionsPluginInfo} from '../blocks/utils/connection_checker'; |
26 | 29 |
|
27 | 30 | import 'blockly/blocks'; // Includes standard blocks like controls_if, logic_compare, etc. |
| 31 | +import { useTranslation } from 'react-i18next'; |
| 32 | + |
28 | 33 |
|
29 | 34 | /** Interface for methods exposed by the BlocklyComponent. */ |
30 | 35 | export interface BlocklyComponentType { |
@@ -78,6 +83,10 @@ const BlocklyComponent = React.forwardRef<BlocklyComponentType | null, BlocklyCo |
78 | 83 | const blocklyDiv = React.useRef<HTMLDivElement | null>(null); |
79 | 84 | const workspaceRef = React.useRef<Blockly.WorkspaceSvg | null>(null); |
80 | 85 |
|
| 86 | + const { t, i18n } = useTranslation(); |
| 87 | + // const { t } = useTranslation(); |
| 88 | + |
| 89 | + |
81 | 90 | const getBlocklyTheme = (): Blockly.Theme => { |
82 | 91 | const blocklyTheme = 'mrc_theme_' + theme.replace(/-/g, '_'); |
83 | 92 | // Find the theme by key |
@@ -133,8 +142,18 @@ const BlocklyComponent = React.forwardRef<BlocklyComponentType | null, BlocklyCo |
133 | 142 | } |
134 | 143 |
|
135 | 144 | // Set Blockly locale |
136 | | - Blockly.setLocale(locale as any); |
137 | | - |
| 145 | + switch (i18n.language) { |
| 146 | + case 'es': |
| 147 | + Blockly.setLocale(Es as any); |
| 148 | + break; |
| 149 | + case 'en': |
| 150 | + Blockly.setLocale(En as any); |
| 151 | + break; |
| 152 | + default: |
| 153 | + Blockly.setLocale(En as any); |
| 154 | + break; |
| 155 | + } |
| 156 | + Blockly.setLocale(customTokens(t)); |
138 | 157 | // Create workspace |
139 | 158 | const workspaceConfig = createWorkspaceConfig(); |
140 | 159 | const workspace = Blockly.inject(blocklyDiv.current, workspaceConfig); |
|
0 commit comments