11import React , { Component } from 'react' ;
2+ import { withTranslation } from 'react-i18next' ;
23import PropTypes from 'prop-types' ;
4+ import i18n from 'I18nSetup' ;
5+ import jaStrings from '../locale/ja/LC_MESSAGES/instruments.json' ;
36
47/**
58 * A VisitInstrumentList is a type of React component which displays
@@ -17,6 +20,7 @@ class VisitInstrumentList extends Component {
1720 */
1821 constructor ( props ) {
1922 super ( props ) ;
23+ i18n . addResourceBundle ( 'ja' , 'instruments' , jaStrings ) ;
2024 this . state = {
2125 expanded : false ,
2226 hover : false ,
@@ -47,10 +51,17 @@ class VisitInstrumentList extends Component {
4751 let vdate = new Date ( visit ) ;
4852 let years = vdate . getFullYear ( ) - dobdate . getFullYear ( ) ;
4953 let months = years * 12 + vdate . getMonth ( ) - dobdate . getMonth ( ) ;
54+
5055 if ( months <= 36 ) {
51- return months + ' months old' ;
56+ return this . props . t (
57+ '{{months}} months old' ,
58+ { ns : 'loris' , months : months }
59+ ) ;
5260 }
53- return years + ' years old' ;
61+ return this . props . t (
62+ '{{years}} years old' ,
63+ { ns : 'loris' , years : years }
64+ ) ;
5465 }
5566
5667 /**
@@ -86,6 +97,14 @@ class VisitInstrumentList extends Component {
8697 * @return {object } - The rendered JSX
8798 */
8899 render ( ) {
100+ const dateFormatter = new Intl . DateTimeFormat (
101+ loris . user . langpref . replace ( '_' , '-' ) ,
102+ {
103+ style : 'short' ,
104+ timeZone : 'UTC' ,
105+
106+ }
107+ ) ;
89108 let style = {
90109 marginRight : '0.5%' ,
91110 textAlign : 'center' ,
@@ -96,16 +115,18 @@ class VisitInstrumentList extends Component {
96115 backgroundColor : 'transparent' ,
97116 } ;
98117
99- let vstatus = 'Not Started' ;
118+ let vstatus = this . props . t ( 'Not Started' , { ns : 'loris' } ) ;
100119 let bg = '#ea9999' ;
120+ const statusString = ( s ) => this . props . t ( s , { ns : 'loris' } )
121+ + '—' + this . props . t ( this . props . Visit . Stages [ s ] . Status , { ns : 'loris' } ) ;
101122 if ( this . props . Visit . Stages . Approval ) {
102- vstatus = 'Approval - ' + this . props . Visit . Stages . Approval . Status ;
123+ vstatus = statusString ( 'Approval' ) ;
103124 bg = '#b6d7a8' ;
104125 } else if ( this . props . Visit . Stages . Visit ) {
105- vstatus = 'Visit - ' + this . props . Visit . Stages . Visit . Status ;
126+ vstatus = statusString ( 'Visit' ) ;
106127 bg = '#ffe599' ;
107128 } else if ( this . props . Visit . Stages . Screening ) {
108- vstatus = 'Screening - ' + this . props . Visit . Stages . Screening . Status ;
129+ vstatus = statusString ( 'Screening' ) ;
109130 bg = '#f9cb9c' ;
110131 }
111132
@@ -185,24 +206,30 @@ class VisitInstrumentList extends Component {
185206 if ( this . state . instruments . length === 0 ) {
186207 instruments = (
187208 < div >
188- { 'Visit has no registered instruments in test battery.' }
209+ { this . props . t (
210+ 'Visit has no registered instruments in test battery.' ,
211+ { ns : 'instruments' } )
212+ }
189213 </ div >
190214 ) ;
191215 } else {
192216 instruments = ( < div >
193- < h5 > Instruments</ h5 >
217+ < h5 > { this . props . t (
218+ 'Instrument' ,
219+ { ns : 'loris' , count : this . state . instruments . length }
220+ ) } </ h5 >
194221 < table
195222 className = "table table-hover table-bordered"
196223 style = { { width : '95%' } }
197224 >
198225 < thead >
199226 < tr >
200- < th > Instrument</ th >
227+ < th > { this . props . t ( ' Instrument' , { ns : 'loris' , count : 1 } ) } </ th >
201228 < th style = { { textAlign : 'center' } } >
202- Completion
229+ { this . props . t ( 'Completion' , { ns : 'instruments' } ) }
203230 </ th >
204231 < th style = { { textAlign : 'center' } } >
205- Conflicts?
232+ { this . props . t ( ' Conflicts?' , { ns : 'instruments' } ) }
206233 </ th >
207234 </ tr >
208235 </ thead >
@@ -223,11 +250,13 @@ class VisitInstrumentList extends Component {
223250 let vage = null ;
224251 if ( this . props . Visit . Stages . Visit ) {
225252 vdate = ( < div style = { termstyle } >
226- < dt > Date Of Visit</ dt >
227- < dd > { this . props . Visit . Stages . Visit . Date } </ dd >
253+ < dt > { this . props . t ( 'Date Of Visit' , { ns : 'loris' } ) } </ dt >
254+ < dd > { dateFormatter . format (
255+ new Date ( this . props . Visit . Stages . Visit . Date )
256+ ) } </ dd >
228257 </ div > ) ;
229258 vage = ( < div style = { termstyle } >
230- < dt > Age</ dt >
259+ < dt > { this . props . t ( ' Age' , { ns : 'loris' } ) } </ dt >
231260 < dd > { this . calcAge (
232261 this . props . Candidate . Meta . DoB ,
233262 this . props . Visit . Stages . Visit . Date
@@ -268,17 +297,17 @@ class VisitInstrumentList extends Component {
268297 < div >
269298 < dl style = { defliststyle } >
270299 < div style = { termstyle } >
271- < dt > Cohort</ dt >
300+ < dt > { this . props . t ( ' Cohort' , { ns : 'loris' , count : 1 } ) } </ dt >
272301 < dd > { this . props . Visit . Meta . Battery } </ dd >
273302 </ div >
274303 < div style = { termstyle } >
275- < dt > Site</ dt >
304+ < dt > { this . props . t ( ' Site' , { ns : 'loris' } ) } </ dt >
276305 < dd > { this . props . Visit . Meta . Site } </ dd >
277306 </ div >
278307 { vdate }
279308 { vage }
280309 < div style = { termstyle } >
281- < dt > Status</ dt >
310+ < dt > { this . props . t ( ' Status' , { ns : 'loris' } ) } </ dt >
282311 < dd > { vstatus } </ dd >
283312 </ div >
284313 </ dl >
@@ -294,6 +323,7 @@ VisitInstrumentList.propTypes = {
294323 Candidate : PropTypes . object ,
295324 Visit : PropTypes . object ,
296325 VisitMap : PropTypes . object ,
326+ t : PropTypes . Func ,
297327} ;
298328
299- export default VisitInstrumentList ;
329+ export default withTranslation ( [ 'instruments' , 'loris' ] ) ( VisitInstrumentList ) ;
0 commit comments