Skip to content

Commit 15842fa

Browse files
Make strings translatable
1 parent f3e66dc commit 15842fa

File tree

3 files changed

+83
-86
lines changed

3 files changed

+83
-86
lines changed

modules/dqt/php/module.class.inc

Lines changed: 0 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -58,71 +58,4 @@ class Module extends \Module
5858
{
5959
return dgettext("dqt", "Data Query Tool");
6060
}
61-
62-
/**
63-
* {@inheritDoc}
64-
*
65-
* @param string $type The type of widgets to get.
66-
* @param \User $user The user widgets are being retrieved for.
67-
* @param array $options A type dependent list of options to provide
68-
* to the widget.
69-
*
70-
* @return \LORIS\GUI\Widget[]
71-
*/
72-
public function getWidgets(string $type, \User $user, array $options) : array
73-
{
74-
$factory = \NDB_Factory::singleton();
75-
$baseURL = $factory->settings()->getBaseURL();
76-
$projects = $user->getProjects();
77-
78-
switch ($type) {
79-
case 'study-progression':
80-
$DB = $factory->database();
81-
$cachedSizeData = json_decode(
82-
html_entity_decode(
83-
$DB->pselectOne(
84-
"SELECT Value
85-
FROM cached_data
86-
JOIN cached_data_type USING (CachedDataTypeID)
87-
WHERE Name='projects_disk_space'",
88-
[]
89-
) ?? ''
90-
),
91-
true
92-
);
93-
94-
$data = [];
95-
96-
if (!is_null($cachedSizeData)) {
97-
foreach ($projects as $project) {
98-
$projectName = $project->getName();
99-
if (!in_array($projectName, array_keys($cachedSizeData))) {
100-
continue;
101-
}
102-
103-
$datasetSize = "{$cachedSizeData[$projectName]['total']} GB";
104-
$data[] = [
105-
'ProjectID' => $project->getId(),
106-
'ProjectName' => $projectName,
107-
'count' => $datasetSize,
108-
'url' => "$baseURL/dqt",
109-
];
110-
}
111-
}
112-
113-
return [
114-
new \LORIS\dashboard\DataWidget(
115-
new \LORIS\GUI\LocalizableString(
116-
"dqt",
117-
"Dataset Size",
118-
"Dataset Size",
119-
),
120-
$data,
121-
"",
122-
'rgb(186,225,255)',
123-
)
124-
];
125-
}
126-
return [];
127-
}
12861
}

modules/statistics/jsx/widgets/studyprogression.js

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ const StudyProgression = (props) => {
4646
options: {line: 'line'},
4747
chartObject: null,
4848
yLabel: t('Candidates registered', {ns: 'statistics'}),
49-
titlePrefix: 'Month',
49+
titlePrefix: t('Month', {ns: 'loris'}),
5050
},
5151
},
5252
'total_recruitment': {
@@ -60,24 +60,24 @@ const StudyProgression = (props) => {
6060
options: {line: 'line'},
6161
chartObject: null,
6262
yLabel: t('Candidates registered', {ns: 'statistics'}),
63-
titlePrefix: 'Month',
63+
titlePrefix: t('Month', {ns: 'loris'}),
6464
},
6565
},
66-
'project_sizes': { // This should be a class
66+
'project_sizes': {
6767
'size_byproject': {
6868
sizing: 11,
69-
title: 'Dataset size breakdown by project',
69+
title: t('Dataset size breakdown by project', {ns: 'statistics'}),
7070
filters: '',
7171
chartType: 'pie',
7272
dataType: 'pie',
73-
label: 'Size (GB)',
74-
units: 'GB',
73+
label: t('Size (GB)', {ns: 'statistics'}),
74+
units: t('GB', {ns: 'loris'}),
7575
showPieLabelRatio: false,
7676
legend: '',
7777
options: {pie: 'pie', bar: 'bar'},
7878
chartObject: null,
7979
yLabel: t('Size (GB)', {ns: 'statistics'}),
80-
titlePrefix: 'Project',
80+
titlePrefix: t('Project', {ns: 'loris'}),
8181
},
8282
},
8383
});
@@ -192,11 +192,16 @@ const StudyProgression = (props) => {
192192
{showChart('total_scans', 'scans_bymonth')}
193193
</div>
194194
) : (
195-
<p>There have been no scans yet.</p>
195+
<p>{t('There have been no scans yet.', {ns: 'statistics'})}</p>
196196
),
197197
title: title('Site Scans'),
198-
subtitle: 'Total scans: '
199-
+ json['studyprogression']['total_scans'],
198+
subtitle: t(
199+
'Total Scans: {{count}}',
200+
{
201+
ns: 'statistics',
202+
count: json['studyprogression']['total_scans'],
203+
}
204+
),
200205
onToggleFilters: () => setShowFiltersScans((prev) => !prev),
201206
},
202207
{
@@ -233,7 +238,12 @@ const StudyProgression = (props) => {
233238
{showChart('total_recruitment', 'siterecruitment_bymonth')}
234239
</div>
235240
) : (
236-
<p>There have been no candidates registered yet.</p>
241+
<p>
242+
{t(
243+
'There have been no candidates registered yet.',
244+
{ns: 'statistics'}
245+
)}
246+
</p>
237247
),
238248
title: title('Site Recruitment'),
239249
onToggleFilters: () => showFiltersBreakdown((prev) => !prev),
@@ -264,12 +274,16 @@ const StudyProgression = (props) => {
264274
{showChart('project_sizes', 'size_byproject')}
265275
</div>
266276
) : (
267-
<p>There is no data yet.</p>
277+
<p>{t('There is no data yet.', {ns: 'statistics'})}</p>
268278
),
269-
title: 'Study Progression - project dataset sizes',
270-
subtitle: 'Total size: '
271-
+ (json['studyprogression']['total_size'] ?? -1)
272-
+ ' GB',
279+
title: title('Project Dataset Sizes'),
280+
subtitle: t(
281+
'Total Size: {{count}} GB',
282+
{
283+
ns: 'statistics',
284+
count: json['studyprogression']['total_size'] ?? -1,
285+
}
286+
),
273287
},
274288
]}
275289
/>

modules/statistics/php/module.class.inc

Lines changed: 53 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,11 @@ class Module extends \Module
7171
*/
7272
public function getWidgets(string $type, \User $user, array $options) : array
7373
{
74+
$factory = \NDB_Factory::singleton();
75+
$baseURL = $factory->settings()->getBaseURL();
7476
switch ($type) {
7577
case 'dashboard':
76-
$factory = \NDB_Factory::singleton();
77-
$baseURL = $factory->settings()->getBaseURL();
78-
$widget = new \LORIS\dashboard\Widget(
78+
$widget = new \LORIS\dashboard\Widget(
7979
new \LORIS\dashboard\WidgetContent(
8080
'',
8181
'',
@@ -100,6 +100,56 @@ class Module extends \Module
100100
$widget->setTemplateVariables(['id' => 'statistics_widgets']);
101101

102102
return [$widget];
103+
case 'study-progression':
104+
$DB = $factory->database();
105+
$cachedSizeData = json_decode(
106+
html_entity_decode(
107+
$DB->pselectOne(
108+
"SELECT Value
109+
FROM cached_data
110+
JOIN cached_data_type USING (CachedDataTypeID)
111+
WHERE Name='projects_disk_space'",
112+
[]
113+
) ?? ''
114+
),
115+
true
116+
);
117+
118+
$data = [];
119+
120+
$projects = $user->getProjects();
121+
if (!is_null($cachedSizeData)) {
122+
foreach ($projects as $project) {
123+
$projectName = $project->getName();
124+
if (!in_array($projectName, array_keys($cachedSizeData))) {
125+
continue;
126+
}
127+
128+
$datasetSize = sprintf(
129+
dgettext('statistics', '%s GB'),
130+
$cachedSizeData[$projectName]['total']
131+
);
132+
$data[] = [
133+
'ProjectID' => $project->getId(),
134+
'ProjectName' => $projectName,
135+
'count' => $datasetSize,
136+
'url' => "$baseURL/dqt",
137+
];
138+
}
139+
}
140+
141+
return [
142+
new \LORIS\dashboard\DataWidget(
143+
new \LORIS\GUI\LocalizableString(
144+
"dqt",
145+
"Dataset Size",
146+
"Dataset Size",
147+
),
148+
$data,
149+
"",
150+
'rgb(186,225,255)',
151+
)
152+
];
103153
}
104154
return [];
105155
}

0 commit comments

Comments
 (0)