@@ -5,6 +5,9 @@ import Loader from 'Loader';
55import FilterableDataTable from 'FilterableDataTable' ;
66import swal from 'sweetalert2' ;
77import { SelectElement } from 'jsx/Form' ;
8+ import { withTranslation } from 'react-i18next' ;
9+ import i18n from 'I18nSetup' ;
10+ import hiStrings from '../locale/hi/LC_MESSAGES/module_manager.json' ;
811
912/**
1013 * Module Manager React Component
@@ -63,18 +66,13 @@ class ModuleManagerIndex extends Component {
6366 * @return {string } a mapped value for the table cell at a given column
6467 */
6568 mapColumn ( column , cell ) {
66- switch ( column ) {
67- case 'Active' :
68- if ( cell === 'Y' ) {
69- return 'Yes' ;
70- } else if ( cell === 'N' ) {
71- return 'No' ;
72- }
73- // This shouldn't happen, it's a non-nullable
74- // enum in the backend.
75- return '?' ;
76- default : return cell ;
69+ const { t} = this . props ;
70+ if ( cell === 'Y' ) {
71+ return t ( 'Yes' , { ns : 'loris' } ) ;
72+ } else if ( cell === 'N' ) {
73+ return t ( 'No' , { ns : 'loris' } ) ;
7774 }
75+ return cell ;
7876 }
7977
8078 /**
@@ -85,6 +83,7 @@ class ModuleManagerIndex extends Component {
8583 * @param {number } id
8684 */
8785 toggleActive ( name , value , id ) {
86+ const { t} = this . props ;
8887 fetch (
8988 this . props . BaseURL + '/module_manager/modules/' + name ,
9089 {
@@ -98,18 +97,24 @@ class ModuleManagerIndex extends Component {
9897 }
9998 ) . then ( ( response ) => {
10099 if ( response . status != 205 ) {
101- swal . fire ( 'Error!' , 'Could not update ' + name + '.' , 'error' ) ;
100+ swal . fire (
101+ t ( 'Error!' , { ns : 'loris' } ) ,
102+ t ( 'Could not update' , { ns : 'module_manager' } ) + ' ' + name + '.' ,
103+ 'error'
104+ ) ;
102105 } else {
103106 const success = this . setModuleDisplayStatus ( name , value ) ;
104107 if ( success === true ) {
105108 swal . fire ( {
106- title : 'Success!' ,
107- text : 'Updated ' + name + ' status! ' +
108- 'To apply changes the interface must be reloaded. Proceed?' ,
109+ title : t ( 'Success!' , { ns : 'loris' } ) ,
110+ text : t ( 'Updated' , { ns : 'loris' } ) + ' ' + name + ' ' +
111+ t ( 'status!' , { ns : 'module_manager' } ) + ' ' +
112+ t ( 'To apply changes the interface must be reloaded. Proceed?' ,
113+ { ns : 'module_manager' } ) ,
109114 type : 'success' ,
110115 showCancelButton : true ,
111- confirmButtonText : 'Reload the page' ,
112- cancelButtonText : 'Continue' ,
116+ confirmButtonText : t ( 'Reload the page' , { ns : 'module_manager' } ) ,
117+ cancelButtonText : t ( 'Continue' , { ns : 'module_manager' } ) ,
113118 } ) . then ( ( status ) => {
114119 if ( status . value ) {
115120 window . location . href = this . props . BaseURL
@@ -120,8 +125,8 @@ class ModuleManagerIndex extends Component {
120125 // If we get here something went very wrong, because somehow
121126 // a module was toggled that isn't in the table.
122127 swal . fire (
123- 'Error!' ,
124- 'Could not find module ' + id + '.' ,
128+ t ( 'Error!' , { ns : 'loris' } ) ,
129+ t ( 'Could not find module' , { ns : 'module_manager' } ) + ' ' + id + '.' ,
125130 'error'
126131 ) ;
127132 }
@@ -160,13 +165,22 @@ class ModuleManagerIndex extends Component {
160165 * @return {* } a formated table cell for a given column
161166 */
162167 formatColumn ( column , cell , row ) {
163- if ( column == 'Active' && this . props . hasEditPermission ) {
168+ const { t} = this . props ;
169+ const labelActive = t ( 'Active' , { ns : 'loris' } ) ;
170+ const labelName = t ( 'Name' , { ns : 'module_manager' } ) ;
171+ if ( ( column === 'Active' || column === labelActive ) &&
172+ this . props . hasEditPermission ) {
173+ const moduleName = row [ labelName ] || row [ 'Name' ] ;
164174 return < td > < SelectElement
165- name = { row . Name }
166- id = { row . Name }
175+ name = { moduleName }
176+ id = { moduleName }
167177 label = ''
168178 emptyOption = { false }
169- options = { { 'Y' : 'Yes' , 'N' : 'No' } }
179+ sortByValue = { false }
180+ options = { {
181+ 'Y' : t ( 'Yes' , { ns : 'loris' } ) ,
182+ 'N' : t ( 'No' , { ns : 'loris' } ) ,
183+ } }
170184 value = { cell }
171185 onUserInput = { this . toggleActive }
172186 noMargins = { true }
@@ -185,29 +199,33 @@ class ModuleManagerIndex extends Component {
185199 // If error occurs, return a message.
186200 // XXX: Replace this with a UI component for 500 errors.
187201 if ( this . state . error ) {
188- return < h3 > An error occured while loading the page.</ h3 > ;
202+ const { t} = this . props ;
203+ return (
204+ < h3 > { t ( 'An error occured while loading the page.' , { ns : 'loris' } ) } </ h3 >
205+ ) ;
189206 }
190207
191208 // Waiting for async data to load
192209 if ( ! this . state . isLoaded ) {
193210 return < Loader /> ;
194211 }
195212
213+ const { t} = this . props ;
196214 const fields = [
197- { label : 'Name' , show : true , filter : {
215+ { label : t ( 'Name' , { ns : 'module_manager' } ) , show : true , filter : {
198216 name : 'Name' ,
199217 type : 'text' ,
200218 } } ,
201- { label : 'Full Name' , show : true , filter : {
219+ { label : t ( 'Full Name' , { ns : 'module_manager' } ) , show : true , filter : {
202220 name : 'Full Name' ,
203221 type : 'text' ,
204222 } } ,
205- { label : 'Active' , show : true , filter : {
223+ { label : t ( 'Active' , { ns : 'loris' } ) , show : true , filter : {
206224 name : 'Active' ,
207225 type : 'select' ,
208226 options : {
209- 'Y' : 'Yes' ,
210- 'N' : 'No' ,
227+ 'Y' : t ( 'Yes' , { ns : 'loris' } ) ,
228+ 'N' : t ( 'No' , { ns : 'loris' } ) ,
211229 } ,
212230 } } ,
213231 ] ;
@@ -226,13 +244,19 @@ ModuleManagerIndex.propTypes = {
226244 dataURL : PropTypes . string . isRequired ,
227245 BaseURL : PropTypes . string ,
228246 hasEditPermission : PropTypes . bool ,
247+ t : PropTypes . func ,
229248} ;
230249
250+ const TranslatedModuleManagerIndex = withTranslation (
251+ [ 'module_manager' , 'loris' ]
252+ ) ( ModuleManagerIndex ) ;
253+
231254window . addEventListener ( 'load' , ( ) => {
255+ i18n . addResourceBundle ( 'hi' , 'module_manager' , hiStrings ) ;
232256 createRoot (
233257 document . getElementById ( 'lorisworkspace' )
234258 ) . render (
235- < ModuleManagerIndex
259+ < TranslatedModuleManagerIndex
236260 dataURL = { `${ loris . BaseURL } /module_manager/?format=json` }
237261 BaseURL = { loris . BaseURL }
238262 hasEditPermission = { loris . userHasPermission ( 'module_manager_edit' ) }
0 commit comments