Skip to content

Commit ed5e2ce

Browse files
authored
[instruments/candidate_profile] Translate Behavioural Data widget on candidate profile (#10085)
This adds Japanese translations for the last remaining widget on the candidate profile page. The dates are also now formatted according to the user's locale.
1 parent 4634df6 commit ed5e2ce

File tree

7 files changed

+85
-23
lines changed

7 files changed

+85
-23
lines changed

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ locales:
132132
msgfmt -o modules/instrument_list/locale/es/LC_MESSAGES/instrument_list.mo modules/instrument_list/locale/es/LC_MESSAGES/instrument_list.po
133133
msgfmt -o modules/instrument_manager/locale/ja/LC_MESSAGES/instrument_manager.mo modules/instrument_manager/locale/ja/LC_MESSAGES/instrument_manager.po
134134
msgfmt -o modules/instruments/locale/ja/LC_MESSAGES/instruments.mo modules/instruments/locale/ja/LC_MESSAGES/instruments.po
135+
npx i18next-conv -l ja -s modules/instruments/locale/ja/LC_MESSAGES/instruments.po -t modules/instruments/locale/ja/LC_MESSAGES/instruments.json --compatibilityJSON v4
135136
msgfmt -o modules/instruments/locale/es/LC_MESSAGES/instruments.mo modules/instruments/locale/es/LC_MESSAGES/instruments.po
136137
msgfmt -o modules/issue_tracker/locale/ja/LC_MESSAGES/issue_tracker.mo modules/issue_tracker/locale/ja/LC_MESSAGES/issue_tracker.po
137138
npx i18next-conv -l ja -s modules/issue_tracker/locale/ja/LC_MESSAGES/issue_tracker.po -t modules/issue_tracker/locale/ja/LC_MESSAGES/issue_tracker.json --compatibilityJSON v4

locale/ja/LC_MESSAGES/loris.po

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,9 @@ msgstr "セッション"
187187
msgid "Date of registration"
188188
msgstr "入学日"
189189

190+
msgid "Date Of Visit"
191+
msgstr "訪問日"
192+
190193
msgid "Participant Status"
191194
msgstr "参加者ステータス"
192195

@@ -336,8 +339,9 @@ msgstr "進行中"
336339
msgid "Complete"
337340
msgstr "完了"
338341

339-
msgid "Instruments"
340-
msgstr "楽器"
342+
msgid "Instrument"
343+
msgid_plural "Instruments"
344+
msgstr[0] "楽器"
341345

342346
msgid "None"
343347
msgstr "なし"

locale/loris.pot

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,9 @@ msgstr ""
192192
msgid "Date of registration"
193193
msgstr ""
194194

195+
msgid "Date Of Visit"
196+
msgstr ""
197+
195198
msgid "Participant Status"
196199
msgstr ""
197200

@@ -380,8 +383,9 @@ msgstr ""
380383
msgid "Complete"
381384
msgstr ""
382385

383-
msgid "Instruments"
384-
msgstr ""
386+
msgid "Instrument"
387+
msgid_plural "Instruments"
388+
msgstr[0] ""
385389

386390
msgid "None"
387391
msgstr ""

modules/instruments/jsx/VisitInstrumentList.js

Lines changed: 48 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import React, {Component} from 'react';
2+
import {withTranslation} from 'react-i18next';
23
import 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);

modules/instruments/locale/instruments.pot

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,15 @@ msgstr ""
4747

4848
msgid "Top"
4949
msgstr ""
50+
51+
msgid "Behavioural Data"
52+
msgstr ""
53+
54+
msgid "Completion"
55+
msgstr ""
56+
57+
msgid "Conflicts?"
58+
msgstr ""
59+
60+
msgid "Visit has no registered instruments in test battery."
61+
msgstr ""

modules/instruments/locale/ja/LC_MESSAGES/instruments.po

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,14 @@ msgstr "サブテスト"
4848
msgid "Top"
4949
msgstr "トップ"
5050

51+
msgid "Behavioural Data"
52+
msgstr "行動データ"
53+
54+
msgid "Completion"
55+
msgstr "完了"
56+
57+
msgid "Conflicts?"
58+
msgstr "衝突?"
59+
60+
msgid "Visit has no registered instruments in test battery."
61+
msgstr "訪問にはテスト バッテリーに登録された機器がありません。"

modules/instruments/php/module.class.inc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ class Module extends \Module
154154

155155
return [
156156
new \LORIS\candidate_profile\CandidateWidget(
157-
"Behavioural Data",
157+
dgettext("instruments", "Behavioural Data"),
158158
$baseurl . "/instruments/js/CandidateInstrumentList.js",
159159
'lorisjs.instruments.CandidateInstrumentList.default',
160160
[],

0 commit comments

Comments
 (0)