@@ -35,6 +35,8 @@ import {
3535 QuestionCircleOutlined ,
3636 InfoCircleOutlined ,
3737 BgColorsOutlined ,
38+ GlobalOutlined ,
39+ CheckOutlined ,
3840} from '@ant-design/icons' ;
3941import FileManageModal from './FileManageModal' ;
4042import ProjectManageModal from './ProjectManageModal' ;
@@ -92,7 +94,7 @@ function getDivider(): MenuItem {
9294/**
9395 * Generates menu items for a given project.
9496 */
95- function getMenuItems ( t : ( key : string ) => string , project : commonStorage . Project ) : MenuItem [ ] {
97+ function getMenuItems ( t : ( key : string ) => string , project : commonStorage . Project , currentLanguage : string ) : MenuItem [ ] {
9698 const mechanisms : MenuItem [ ] = [ ] ;
9799 const opmodes : MenuItem [ ] = [ ] ;
98100
@@ -123,24 +125,35 @@ function getMenuItems(t: (key: string) => string, project: commonStorage.Project
123125 opmodes . push ( getItem ( 'Manage...' , 'manageOpmodes' ) ) ;
124126
125127 return [
126- getItem ( t ( 'Project ' ) , 'project' , < FolderOutlined /> , [
127- getItem ( t ( 'Save ' ) , 'save' , < SaveOutlined /> ) ,
128- getItem ( t ( 'Deploy ' ) , 'deploy' , undefined , undefined , true ) ,
128+ getItem ( t ( 'PROJECT ' ) , 'project' , < FolderOutlined /> , [
129+ getItem ( t ( 'SAVE ' ) , 'save' , < SaveOutlined /> ) ,
130+ getItem ( t ( 'DEPLOY ' ) , 'deploy' , undefined , undefined , true ) ,
129131 getDivider ( ) ,
130- getItem ( t ( 'Manage ' ) + '...' , 'manageProjects' ) ,
132+ getItem ( t ( 'MANAGE ' ) + '...' , 'manageProjects' ) ,
131133 ] ) ,
132- getItem ( t ( 'Explorer ' ) , 'explorer' , < FileOutlined /> , [
133- getItem ( t ( 'Robot ' ) , project . robot . modulePath , < RobotOutlined /> ) ,
134- getItem ( t ( 'Mechanisms ' ) , 'mechanisms' , < BlockOutlined /> , mechanisms ) ,
135- getItem ( t ( 'OpModes ' ) , 'opmodes' , < CodeOutlined /> , opmodes ) ,
134+ getItem ( t ( 'EXPLORER ' ) , 'explorer' , < FileOutlined /> , [
135+ getItem ( t ( 'ROBOT ' ) , project . robot . modulePath , < RobotOutlined /> ) ,
136+ getItem ( t ( 'MECHANISMS ' ) , 'mechanisms' , < BlockOutlined /> , mechanisms ) ,
137+ getItem ( t ( 'OPMODES ' ) , 'opmodes' , < CodeOutlined /> , opmodes ) ,
136138 ] ) ,
137- getItem ( t ( 'Settings' ) , 'settings' , < SettingOutlined /> , [
138- getItem ( t ( 'WPI toolbox' ) , 'wpi_toolbox' ) ,
139- getItem ( t ( 'Theme' ) + '...' , 'theme' , < BgColorsOutlined /> )
139+ getItem ( t ( 'SETTINGS' ) , 'settings' , < SettingOutlined /> , [
140+ getItem ( t ( 'WPI_TOOLBOX' ) , 'wpi_toolbox' ) ,
141+ getItem ( t ( 'THEME' ) + '...' , 'theme' , < BgColorsOutlined /> ) ,
142+ getItem ( t ( 'LANGUAGE' ) , 'language' , < GlobalOutlined /> , [
143+ getItem (
144+ t ( 'ENGLISH' ) ,
145+ 'setlang:en' ,
146+ currentLanguage === 'en' ? < CheckOutlined /> : undefined
147+ ) ,
148+ getItem (
149+ t ( 'SPANISH' ) ,
150+ 'setlang:es' ,
151+ currentLanguage === 'es' ? < CheckOutlined /> : undefined
152+ ) ,
153+ ] ) ,
140154 ] ) ,
141- getItem ( t ( 'Help' ) , 'help' , < QuestionCircleOutlined /> , [
142- getItem ( t ( 'About' ) + '...' , 'about' , < InfoCircleOutlined />
143- ) ,
155+ getItem ( t ( 'HELP' ) , 'help' , < QuestionCircleOutlined /> , [
156+ getItem ( t ( 'ABOUT' ) + '...' , 'about' , < InfoCircleOutlined /> ) ,
144157 ] ) ,
145158 ] ;
146159}
@@ -150,7 +163,7 @@ function getMenuItems(t: (key: string) => string, project: commonStorage.Project
150163 * Provides access to mechanisms, opmodes, and project management functionality.
151164 */
152165export function Component ( props : MenuProps ) : React . JSX . Element {
153- const { t} = I18Next . useTranslation ( ) ;
166+ const { t, i18n } = I18Next . useTranslation ( ) ;
154167
155168 const [ projects , setProjects ] = React . useState < commonStorage . Project [ ] > ( [ ] ) ;
156169 const [ menuItems , setMenuItems ] = React . useState < MenuItem [ ] > ( [ ] ) ;
@@ -264,8 +277,12 @@ export function Component(props: MenuProps): React.JSX.Element {
264277 props . openWPIToolboxSettings ( ) ;
265278 } else if ( key === 'theme' ) {
266279 setThemeModalOpen ( true ) ;
280+ } else if ( key . startsWith ( 'setlang:' ) ) {
281+ const lang = key . split ( ':' ) [ 1 ] ;
282+ i18n . changeLanguage ( lang ) ;
267283 } else {
268284 // TODO: Handle other menu actions
285+
269286 console . log ( `Selected key that wasn't module: ${ key } ` ) ;
270287 }
271288 } ;
@@ -294,14 +311,14 @@ export function Component(props: MenuProps): React.JSX.Element {
294311 fetchMostRecentProject ( ) ;
295312 } , [ projects ] ) ;
296313
297- // Update menu items and save project when project changes
314+ // Update menu items and save project when project or language changes
298315 React . useEffect ( ( ) => {
299316 if ( props . project ) {
300317 setMostRecentProject ( ) ;
301- setMenuItems ( getMenuItems ( t , props . project ) ) ;
318+ setMenuItems ( getMenuItems ( t , props . project , i18n . language ) ) ;
302319 setNoProjects ( false ) ;
303320 }
304- } , [ props . project ] ) ;
321+ } , [ props . project , i18n . language ] ) ; // Add i18n.language dependency
305322
306323 return (
307324 < >
0 commit comments