Skip to content

Commit a840650

Browse files
committed
Make exception messages translatable
Signed-off-by: Christopher Ng <chrng8@gmail.com>
1 parent 5598638 commit a840650

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

apps/dav/lib/Connector/Sabre/File.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
use OCP\Files\NotPermittedException;
6060
use OCP\Files\Storage;
6161
use OCP\Files\StorageNotAvailableException;
62+
use OCP\IL10N;
6263
use OCP\ILogger;
6364
use OCP\Lock\ILockingProvider;
6465
use OCP\Lock\LockedException;
@@ -73,6 +74,7 @@
7374

7475
class File extends Node implements IFile {
7576
protected $request;
77+
protected $l;
7678

7779
/**
7880
* Sets up the node, expects a full path name
@@ -81,9 +83,11 @@ class File extends Node implements IFile {
8183
* @param \OCP\Files\FileInfo $info
8284
* @param \OCP\Share\IManager $shareManager
8385
* @param \OC\AppFramework\Http\Request $request
86+
* @param IL10N $l
8487
*/
85-
public function __construct(View $view, FileInfo $info, IManager $shareManager = null, Request $request = null) {
88+
public function __construct(View $view, FileInfo $info, IManager $shareManager = null, Request $request = null, IL10N $l = null) {
8689
parent::__construct($view, $info, $shareManager);
90+
$this->l = $l;
8791

8892
if (isset($request)) {
8993
$this->request = $request;
@@ -242,7 +246,7 @@ public function put($data) {
242246
if (isset($_SERVER['CONTENT_LENGTH']) && $_SERVER['REQUEST_METHOD'] === 'PUT') {
243247
$expected = (int)$_SERVER['CONTENT_LENGTH'];
244248
if ($count !== $expected) {
245-
throw new BadRequest('Expected filesize of ' . $expected . ' bytes but read (from Nextcloud client) and wrote (to Nextcloud storage) ' . $count . ' bytes. Could either be a network problem on the sending side or a problem writing to the storage on the server side.');
249+
throw new BadRequest($this->l->t('Expected filesize of %1$d bytes but read (from Nextcloud client) and wrote (to Nextcloud storage) %2$d bytes. Could either be a network problem on the sending side or a problem writing to the storage on the server side.', [$expected, $count]));
246250
}
247251
}
248252
} catch (\Exception $e) {
@@ -533,7 +537,7 @@ private function createFileChunked($data) {
533537
$expected = (int)$_SERVER['CONTENT_LENGTH'];
534538
if ($bytesWritten !== $expected) {
535539
$chunk_handler->remove($info['index']);
536-
throw new BadRequest('Expected filesize of ' . $expected . ' bytes but read (from Nextcloud client) and wrote (to Nextcloud storage) ' . $bytesWritten . ' bytes. Could either be a network problem on the sending side or a problem writing to the storage on the server side.');
540+
throw new BadRequest($this->l->t('Expected filesize of %1$d bytes but read (from Nextcloud client) and wrote (to Nextcloud storage) %2$d bytes. Could either be a network problem on the sending side or a problem writing to the storage on the server side.', [$expected, $bytesWritten]));
537541
}
538542
}
539543
}

0 commit comments

Comments
 (0)