Skip to content

Commit 00ee1f9

Browse files
authored
[dashboard/statistics] Translate Recruitment widget (#10059)
This translates the recruitment widget (the last widget) on the LORIS dashboard, so that the entire dashboard is now translated (The recruitment widget had been waiting on #9937 to be merged before translating it.). Japanese is used as a test language. It also fixes a regression on the study progression translation introduced by #9937 as new filters that are shared between the two were added.
1 parent cf686eb commit 00ee1f9

File tree

13 files changed

+302
-53
lines changed

13 files changed

+302
-53
lines changed

locale/ja/LC_MESSAGES/loris.po

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,9 @@ msgstr "詳細フィルターを非表示"
232232
msgid "Language"
233233
msgstr "言語"
234234

235+
msgid "Ethnicity"
236+
msgstr "民族"
237+
235238
# Data table strings
236239
msgid "{{pageCount}} rows displayed of {{totalCount}}."
237240
msgstr "{{totalCount}}行中{{pageCount}}行を表示"
@@ -332,3 +335,8 @@ msgstr "{{months}}ヶ月"
332335

333336
msgid "{{years}} years old"
334337
msgstr "{{years}}歳"
338+
339+
# Other generic terms
340+
msgid "Loading..."
341+
msgstr "読み込み中..."
342+

locale/loris.pot

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,9 @@ msgstr ""
231231
msgid "Language"
232232
msgstr ""
233233

234+
msgid "Ethnicity"
235+
msgstr ""
236+
234237
# Data table strings
235238
msgid "{{pageCount}} rows displayed of {{totalCount}}."
236239
msgstr ""
@@ -331,3 +334,8 @@ msgstr ""
331334

332335
msgid "{{years}} years old"
333336
msgstr ""
337+
338+
# Other generic terms
339+
msgid "Loading..."
340+
msgstr ""
341+

modules/dashboard/test/DashboardTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -409,17 +409,17 @@ public function testDashboardRecruitmentView()
409409
)
410410
)->getText();
411411

412-
$this->assertStringContainsString("Recruitment - overall", $assertText1);
412+
$this->assertStringContainsString("Recruitment — Overall", $assertText1);
413413
$this->assertStringContainsString(
414-
"Recruitment - site breakdown",
414+
"Recruitment — Site Breakdown",
415415
$assertText2
416416
);
417417
$this->assertStringContainsString(
418-
"Recruitment - project breakdown",
418+
"Recruitment — Project Breakdown",
419419
$assertText3
420420
);
421421
$this->assertStringContainsString(
422-
"Recruitment - cohort breakdown",
422+
"Recruitment — Cohort Breakdown",
423423
$assertText4
424424
);
425425
}

modules/statistics/jsx/WidgetIndex.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ const WidgetIndex = (props) => {
6161
}
6262
);
6363
setupCharts(
64+
t,
6465
false,
6566
{
6667
[section]: {
@@ -86,6 +87,7 @@ const WidgetIndex = (props) => {
8687
onClick ={() => {
8788
setModalChart(chartDetails[section][chartID]);
8889
setupCharts(
90+
t,
8991
true,
9092
{
9193
[section]:
@@ -185,7 +187,7 @@ const WidgetIndex = (props) => {
185187
setChartDetails
186188
) => {
187189
// Unload all charts in the section first
188-
unloadCharts(chartDetails, section);
190+
unloadCharts(t, chartDetails, section);
189191

190192
// Clear cached data from chartDetails to prevent old data from showing
191193
let clearedChartDetails = {...chartDetails};
@@ -215,7 +217,9 @@ const WidgetIndex = (props) => {
215217
...clearedChartDetails[section][chart],
216218
filters: queryString,
217219
};
218-
const chartPromise = setupCharts(false,
220+
const chartPromise = setupCharts(
221+
t,
222+
false,
219223
{[section]: {[chart]: newChart}},
220224
t('Total', {ns: 'loris'}),
221225
).then(

modules/statistics/jsx/widgets/helpers/chartBuilder.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ const createPieChart = (columns, id, targetModal, colours) => {
107107
return newChart;
108108
}
109109

110-
const createBarChart = (labels, columns, id, targetModal, colours, dataType) => {
110+
const createBarChart = (t, labels, columns, id, targetModal, colours, dataType) => {
111111
let newChart = c3.generate({
112112
bindto: targetModal ? targetModal : id,
113113
data: {
@@ -134,7 +134,7 @@ const createBarChart = (labels, columns, id, targetModal, colours, dataType) =>
134134
},
135135
y: {
136136
label: {
137-
text: 'Candidates registered',
137+
text: t('Candidates registered', { ns: 'statistics'}),
138138
position: 'inner-top'
139139
},
140140
},
@@ -254,10 +254,11 @@ const getChartData = async (target, filters) => {
254254

255255
/**
256256
* unloadCharts - unload all charts in a section to clear their data
257+
* @param {t} The i18next translation callback
257258
* @param {object} chartDetails
258259
* @param {string} section
259260
*/
260-
const unloadCharts = (chartDetails, section) => {
261+
const unloadCharts = (t, chartDetails, section) => {
261262
Object.keys(chartDetails[section]).forEach((chartID) => {
262263
const chart = chartDetails[section][chartID].chartObject;
263264
if (chart && typeof chart.unload === 'function') {
@@ -266,7 +267,7 @@ const unloadCharts = (chartDetails, section) => {
266267
// Clear the chart container completely
267268
const element = document.getElementById(chartID);
268269
if (element) {
269-
element.innerHTML ='<p>Loading...</p>';
270+
element.innerHTML ='<p>' + t('Loading...', {ns: 'loris'}) + '</p>';
270271
}
271272
});
272273
};
@@ -278,7 +279,7 @@ const unloadCharts = (chartDetails, section) => {
278279
* This is determined by the original chart type of the data provided from the API
279280
* If data was provided as a Pie, and the requested chartType is Bar, then the data will be reformatted
280281
*/
281-
const setupCharts = async (targetIsModal, chartDetails, totalLabel) => {
282+
const setupCharts = async (t, targetIsModal, chartDetails, totalLabel) => {
282283
const chartPromises = [];
283284
let newChartDetails = {...chartDetails}
284285
Object.keys(chartDetails).forEach((section) => {
@@ -314,7 +315,7 @@ const setupCharts = async (targetIsModal, chartDetails, totalLabel) => {
314315
if (chart.chartType === 'pie') {
315316
chartObject = createPieChart(columns, `#${chartID}`, targetIsModal && '#dashboardModal', colours);
316317
} else if (chart.chartType === 'bar') {
317-
chartObject = createBarChart(labels, columns, `#${chartID}`, targetIsModal && '#dashboardModal', colours, chart.dataType);
318+
chartObject = createBarChart(t, labels, columns, `#${chartID}`, targetIsModal && '#dashboardModal', colours, chart.dataType);
318319
} else if (chart.chartType === 'line') {
319320
chartObject = createLineChart(chartData, columns, `#${chartID}`, chart.label, targetIsModal && '#dashboardModal', chart.titlePrefix);
320321
}
@@ -382,4 +383,4 @@ export {
382383
// recruitment.js and studyProgression.js
383384
setupCharts,
384385
unloadCharts,
385-
};
386+
};

modules/statistics/jsx/widgets/helpers/progressbarBuilder.js

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
/**
22
* progressBarBuilder - generates the graph content.
33
*
4-
* @param {object} data - data needed to generate the graph content.
4+
* @param {function} t - i18next React translation callback
5+
* @param {object} data - data needed to generate the graph content.
56
* @return {JSX.Element} the charts to render to the widget panel.
67
*/
7-
const progressBarBuilder = (data) => {
8+
const progressBarBuilder = (t, data) => {
89
let title;
910
let content;
1011
title = <h5>
@@ -54,14 +55,23 @@ const progressBarBuilder = (data) => {
5455
</div>
5556
}
5657
<p className ='pull-right small target'>
57-
Target: {data['recruitment_target']}
58+
{t(
59+
'Target: {{target}}',
60+
{'target': data['recruitment_target'], 'ns': 'statistics'}
61+
)}
5862
</p>
5963
</div>
6064
{
6165
data['recruitment_target'] &&
6266
<small>
63-
Recruitment target of {data['recruitment_target']} was reached.
64-
{' '}{data['total_recruitment']} total participants.
67+
{t(
68+
'Recruitment target of {{target}} was reached.',
69+
{'target': data['recruitment_target'], 'ns': 'statistics'}
70+
)}
71+
{' '}{t(
72+
'{{total}} total participants.',
73+
{'total': data['total_recruitment'], 'ns': 'statistics'}
74+
)}
6575
</small>
6676
}
6777
</div>
@@ -112,18 +122,27 @@ const progressBarBuilder = (data) => {
112122
{
113123
data['recruitment_target'] ?
114124
<p className ='pull-right small target'>
115-
Target: {data['recruitment_target']}
125+
{t(
126+
'Target: {{target}}',
127+
{'target': data['recruitment_target'], 'ns': 'statistics'}
128+
)}
116129
</p>
117130
: <p className ='pull-right small target'>
118-
No target set
131+
{t('No target set', {ns: 'statistics'})}
119132
</p>
120133
}
121134
</div>
122135
{
123136
data['recruitment_target'] &&
124137
<small>
125-
Recruitment target of {data['recruitment_target']} not reached.
126-
{' '}{data['total_recruitment']} total participants.
138+
{t(
139+
'Recruitment target of {{target}} was not reached.',
140+
{'target': data['recruitment_target'], 'ns': 'statistics'}
141+
)}
142+
{' '}{t(
143+
'{{total}} total participants.',
144+
{'total': data['total_recruitment'], 'ns': 'statistics'}
145+
)}
127146
</small>
128147
}
129148
</>

modules/statistics/jsx/widgets/helpers/queryChartForm.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ const QueryChartForm = (props) => {
9090
{t('Project', {ns: 'loris'})}</label>
9191
<SelectElement
9292
name ='selectedProjects'
93-
options ={{__clear__: '-- Clear Selection --',
93+
options ={{__clear__: clearSelection,
9494
...options.projects}}
9595
multiple ={true}
9696
emptyOption ={false}
@@ -110,7 +110,7 @@ const QueryChartForm = (props) => {
110110
<div>
111111
<label style ={{fontWeight: 'bold',
112112
marginBottom: '5px',
113-
display: 'block'}}>{t('Cohort', {ns: 'loris'})}</label>
113+
display: 'block'}}>{t('Cohort', {ns: 'loris', count: 1})}</label>
114114
<SelectElement
115115
name ='selectedCohorts'
116116
options ={{__clear__: clearSelection,
@@ -155,7 +155,7 @@ const QueryChartForm = (props) => {
155155
<div>
156156
<label style ={{fontWeight: 'bold',
157157
marginBottom: '5px',
158-
display: 'block'}}>Visit</label>
158+
display: 'block'}}>{t('Visit', {ns: 'loris'})}</label>
159159
<SelectElement
160160
name ='selectedVisits'
161161
options ={{__clear__: clearSelection,
@@ -203,7 +203,8 @@ const QueryChartForm = (props) => {
203203
<div>
204204
<label style ={{fontWeight: 'bold',
205205
marginBottom: '5px',
206-
display: 'block'}}>Date Registered</label>
206+
display: 'block'}}>
207+
{t('Date Registered', {ns: 'statistics'})}</label>
207208
<DateElement
208209
name='dateRegisteredStart'
209210
value={formDataObj['dateRegisteredStart'] || ''}
@@ -213,7 +214,7 @@ const QueryChartForm = (props) => {
213214
style={{width: '100%', padding: '8px',
214215
borderRadius: '5px',
215216
border: '1px solid #ccc'}}
216-
label={'Range Start'}
217+
label={t('Range Start', {ns: 'statistics'})}
217218
/>
218219
<DateElement
219220
name='dateRegisteredEnd'
@@ -224,7 +225,7 @@ const QueryChartForm = (props) => {
224225
style={{width: '100%', padding: '8px',
225226
borderRadius: '5px',
226227
border: '1px solid #ccc'}}
227-
label={'Range End'}
228+
label={t('Range End', {ns: 'statistics'})}
228229
/>
229230
</div>
230231
</div>

0 commit comments

Comments
 (0)