diff --git a/lib/Controller/ApiController.php b/lib/Controller/ApiController.php index 7abc6653..d6393e6b 100644 --- a/lib/Controller/ApiController.php +++ b/lib/Controller/ApiController.php @@ -22,6 +22,7 @@ use OCP\AppFramework\OCSController; use OCP\IConfig; use OCP\IGroupManager; +use OCP\IL10N; use OCP\IRequest; use OCP\IUserSession; @@ -40,6 +41,7 @@ public function __construct( private DatabaseStatistics $databaseStatistics, private ShareStatistics $shareStatistics, private SessionStatistics $sessionStatistics, + private IL10N $l10n, ) { parent::__construct($appName, $request); } @@ -131,19 +133,24 @@ private function getWebserver(): string { */ private function formatUptime(int $uptime): string { if ($uptime === -1) { - return 'Unknown'; + return $this->l10n->t('Unknown'); } try { $boot = new \DateTime($uptime . ' seconds ago'); } catch (\Exception $e) { - return 'Unknown'; + return $this->l10n->t('Unknown'); } $interval = $boot->diff(new \DateTime()); - if ($interval->days > 0) { - return $interval->format('%a days, %h hours, %i minutes, %s seconds'); + $days = $interval->days; + $hours = $interval->h; + $minutes = $interval->i; + $seconds = $interval->s; + + if ($days > 0) { + return $this->l10n->t('%1$d days, %2$d hours, %3$d minutes, %4$d seconds', [$days, $hours, $minutes, $seconds]); } - return $interval->format('%h hours, %i minutes, %s seconds'); + return $this->l10n->t('%1$d hours, %2$d minutes, %3$d seconds', [$hours, $minutes, $seconds]); } } diff --git a/tests/lib/ApiControllerTest.php b/tests/lib/ApiControllerTest.php index 9a559da1..2af79b3f 100644 --- a/tests/lib/ApiControllerTest.php +++ b/tests/lib/ApiControllerTest.php @@ -21,6 +21,7 @@ use OCP\AppFramework\Http; use OCP\IConfig; use OCP\IGroupManager; +use OCP\IL10N; use OCP\IRequest; use OCP\IUser; use OCP\IUserSession; @@ -38,6 +39,7 @@ class ApiControllerTest extends \Test\TestCase { private DatabaseStatistics&MockObject $databaseStatistics; private ShareStatistics&MockObject $shareStatistics; private SessionStatistics&MockObject $sessionStatistics; + private IL10N&MockObject $l10n; protected function setUp(): void { parent::setUp(); @@ -53,6 +55,7 @@ protected function setUp(): void { $this->databaseStatistics = $this->createMock(DatabaseStatistics::class); $this->shareStatistics = $this->createMock(ShareStatistics::class); $this->sessionStatistics = $this->createMock(SessionStatistics::class); + $this->l10n = $this->createMock(IL10N::class); } private function getController($userSession) { @@ -69,7 +72,8 @@ private function getController($userSession) { $this->fpmStatistics, $this->databaseStatistics, $this->shareStatistics, - $this->sessionStatistics + $this->sessionStatistics, + $this->l10n ); }