Skip to content

Commit e2818f6

Browse files
fix: add localization to uptime strings
Fixes #592 Signed-off-by: jedrzejdocs-code <jedrzejdocs@gmail.com>
1 parent a89adbe commit e2818f6

1 file changed

Lines changed: 12 additions & 5 deletions

File tree

lib/Controller/ApiController.php

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
use OCP\AppFramework\OCSController;
2323
use OCP\IConfig;
2424
use OCP\IGroupManager;
25+
use OCP\IL10N;
2526
use OCP\IRequest;
2627
use OCP\IUserSession;
2728

@@ -40,6 +41,7 @@ public function __construct(
4041
private DatabaseStatistics $databaseStatistics,
4142
private ShareStatistics $shareStatistics,
4243
private SessionStatistics $sessionStatistics,
44+
private IL10N $l10n,
4345
) {
4446
parent::__construct($appName, $request);
4547
}
@@ -131,19 +133,24 @@ private function getWebserver(): string {
131133
*/
132134
private function formatUptime(int $uptime): string {
133135
if ($uptime === -1) {
134-
return 'Unknown';
136+
return $this->l10n->t('Unknown');
135137
}
136138

137139
try {
138140
$boot = new \DateTime($uptime . ' seconds ago');
139141
} catch (\Exception $e) {
140-
return 'Unknown';
142+
return $this->l10n->t('Unknown');
141143
}
142144

143145
$interval = $boot->diff(new \DateTime());
144-
if ($interval->days > 0) {
145-
return $interval->format('%a days, %h hours, %i minutes, %s seconds');
146+
$days = $interval->days;
147+
$hours = $interval->h;
148+
$minutes = $interval->i;
149+
$seconds = $interval->s;
150+
151+
if ($days > 0) {
152+
return $this->l10n->t('%1$d days, %2$d hours, %3$d minutes, %4$d seconds', [$days, $hours, $minutes, $seconds]);
146153
}
147-
return $interval->format('%h hours, %i minutes, %s seconds');
154+
return $this->l10n->t('%1$d hours, %2$d minutes, %3$d seconds', [$hours, $minutes, $seconds]);
148155
}
149156
}

0 commit comments

Comments
 (0)