1- import * as React from ' react' ;
2- import { getter } from ' @progress/kendo-react-common' ;
1+ import * as React from " react" ;
2+ import { getter } from " @progress/kendo-react-common" ;
33import {
44 Grid ,
55 GridColumn ,
@@ -10,16 +10,21 @@ import {
1010 getSelectedStateFromKeyDown ,
1111 GridSortChangeEvent ,
1212 GridPageChangeEvent ,
13- } from ' @progress/kendo-react-grid' ;
13+ } from " @progress/kendo-react-grid" ;
1414import {
1515 ChartWizard ,
1616 ChartWizardDataRow ,
1717 getWizardDataFromGridSelection ,
18- } from '@progress/kendo-react-chart-wizard' ;
19- import { Button } from '@progress/kendo-react-buttons' ;
20- import { orderBy } from '@progress/kendo-data-query' ;
21- import { chartAreaStackedIcon } from '@progress/kendo-svg-icons' ;
22- import { sampleData } from '../data/shared-gd-sampleChartData' ;
18+ } from "@progress/kendo-react-chart-wizard" ;
19+ import { Button } from "@progress/kendo-react-buttons" ;
20+ import { orderBy } from "@progress/kendo-data-query" ;
21+ import { chartAreaStackedIcon } from "@progress/kendo-svg-icons" ;
22+ import { sampleData } from "../data/shared-gd-sampleChartData" ;
23+ import { useLanguageContext } from "../helpers/LanguageContext" ;
24+ import { LocalizationProvider , loadMessages } from "@progress/kendo-react-intl" ;
25+ import esMessages from "../data/messages/es" ;
26+ import frMessages from "../data/messages/fr" ;
27+ import enMessages from "../data/messages/en" ;
2328
2429interface SampleDataItem {
2530 ID : string ;
@@ -33,8 +38,8 @@ interface SampleDataItem {
3338 URL : string ;
3439}
3540
36- const DATA_ITEM_KEY = 'ID' ;
37- const SELECTED_FIELD = ' selected' ;
41+ const DATA_ITEM_KEY = "ID" ;
42+ const SELECTED_FIELD = " selected" ;
3843const idGetter = getter ( DATA_ITEM_KEY ) ;
3944
4045interface SelectedState {
@@ -44,15 +49,27 @@ interface SelectedState {
4449const AdminView : React . FC = ( ) => {
4550 const gridRef = React . useRef < GridHandle > ( null ) ;
4651 const [ selectedState , setSelectedState ] = React . useState < SelectedState > ( { } ) ;
47- const [ sort , setSort ] = React . useState < { field : string ; dir : ' asc' | ' desc' } [ ] > ( [
48- { field : ' Sales' , dir : ' desc' } ,
52+ const [ sort , setSort ] = React . useState < { field : string ; dir : " asc" | " desc" } [ ] > ( [
53+ { field : " Sales" , dir : " desc" } ,
4954 ] ) ;
5055 const [ showChartWizard , setShowChartWizard ] = React . useState < boolean > ( false ) ;
5156 const [ chartData , setChartData ] = React . useState < ChartWizardDataRow [ ] > ( [ ] ) ;
5257 const [ top3SalesData , setTop3SalesData ] = React . useState < ChartWizardDataRow [ ] > ( [ ] ) ;
5358 const [ top3Visible , setTop3Visible ] = React . useState < boolean > ( false ) ;
5459 const [ page , setPage ] = React . useState < { skip : number ; take : number } > ( { skip : 0 , take : 4 } ) ;
5560
61+ const { t, language } = useLanguageContext ( ) ;
62+
63+ React . useEffect ( ( ) => {
64+ if ( language === "es" ) {
65+ loadMessages ( esMessages , "es" ) ;
66+ } else if ( language === "fr" ) {
67+ loadMessages ( frMessages , "fr" ) ;
68+ } else {
69+ loadMessages ( enMessages , "en" ) ;
70+ }
71+ } , [ language ] ) ;
72+
5673 const data = sampleData . map ( ( item ) => ( {
5774 ...item ,
5875 [ SELECTED_FIELD ] : selectedState [ idGetter ( item ) ] ,
@@ -96,7 +113,7 @@ const AdminView: React.FC = () => {
96113 setChartData ( chartWizardData ) ;
97114 setShowChartWizard ( true ) ;
98115 } else {
99- console . error ( ' Grid reference is not available.' ) ;
116+ console . error ( " Grid reference is not available." ) ;
100117 }
101118 } , [ selectedState ] ) ;
102119
@@ -111,8 +128,8 @@ const AdminView: React.FC = () => {
111128 const sortedTop3Sales = selectedData
112129 . sort (
113130 ( a , b ) =>
114- b . find ( ( field ) => field . field === ' Total Sales' ) ?. value -
115- a . find ( ( field ) => field . field === ' Total Sales' ) ?. value
131+ b . find ( ( field ) => field . field === " Total Sales" ) ?. value -
132+ a . find ( ( field ) => field . field === " Total Sales" ) ?. value
116133 )
117134 . slice ( 0 , 3 ) ;
118135
@@ -127,29 +144,30 @@ const AdminView: React.FC = () => {
127144 const imageUrl = field && field in dataItem ? ( dataItem as Record < string , any > ) [ field ] : dataItem . URL ;
128145 return (
129146 < td >
130- < img src = { imageUrl } alt = "Product" style = { { width : ' 100px' , height : ' auto' } } />
147+ < img src = { imageUrl } alt = "Product" style = { { width : " 100px" , height : " auto" } } />
131148 </ td >
132149 ) ;
133150 } ;
134151
135152 return (
136- < >
137- < div style = { { marginBottom : ' 10px' } } >
153+ < LocalizationProvider language = { language } >
154+ < div style = { { marginBottom : " 10px" } } >
138155 < Button
139156 svgIcon = { chartAreaStackedIcon }
140157 onClick = { handleSelectedChart }
141158 disabled = { disabled }
142- style = { { marginRight : ' 10px' } }
159+ style = { { marginRight : " 10px" } }
143160 >
144- Chart of Selected Data
161+ { t . chartSelectedDataButton }
145162 </ Button >
146163 < Button svgIcon = { chartAreaStackedIcon } onClick = { handleTop3Sales } >
147- Top 3 Sales per Category
164+ { t . top3SalesButton }
148165 </ Button >
149166 </ div >
150167 < Grid
168+ key = { language }
151169 ref = { gridRef }
152- style = { { height : ' 500px' } }
170+ style = { { height : " 500px" } }
153171 data = { pagedData }
154172 dataItemKey = { DATA_ITEM_KEY }
155173 selectedField = { SELECTED_FIELD }
@@ -161,24 +179,24 @@ const AdminView: React.FC = () => {
161179 selectable = { {
162180 enabled : true ,
163181 drag : true ,
164- mode : ' multiple' ,
182+ mode : " multiple" ,
165183 } }
166184 navigatable = { true }
167185 onSelectionChange = { onSelectionChange }
168186 onKeyDown = { onKeyDown }
169187 sortable = { true }
170188 sort = { sort }
171189 onSortChange = { ( e : GridSortChangeEvent ) => {
172- setSort ( e . sort as { field : string ; dir : ' asc' | ' desc' } [ ] ) ;
190+ setSort ( e . sort as { field : string ; dir : " asc" | " desc" } [ ] ) ;
173191 } }
174192 >
175- < GridColumn field = "URL" title = "Product" cell = { URLImageCell } />
176- < GridColumn field = "Product" title = "Name" />
177- < GridColumn field = "SKU" title = "SKU" />
178- < GridColumn field = "Category" title = "Category" />
179- < GridColumn field = "Price" title = "Price" />
180- < GridColumn field = "Quantity" title = "Quantity" />
181- < GridColumn field = "Sales" title = "Total Sales" />
193+ < GridColumn field = "URL" title = { t . grid . productTitle } cell = { URLImageCell } />
194+ < GridColumn field = "Product" title = { t . grid . nameTitle } />
195+ < GridColumn field = "SKU" title = { t . grid . skuTitle } />
196+ < GridColumn field = "Category" title = { t . grid . categoryTitle } />
197+ < GridColumn field = "Price" title = { t . grid . priceTitle } />
198+ < GridColumn field = "Quantity" title = { t . grid . quantityTitle } />
199+ < GridColumn field = "Sales" title = { t . grid . totalSalesTitle } />
182200 </ Grid >
183201
184202 { showChartWizard && (
@@ -194,7 +212,7 @@ const AdminView: React.FC = () => {
194212 onClose = { ( ) => setTop3Visible ( false ) }
195213 />
196214 ) }
197- </ >
215+ </ LocalizationProvider >
198216 ) ;
199217} ;
200218
0 commit comments