Translate 'Busy' in CalDAV
Signed-off-by: Gary Kim <gary@garykim.dev>
This commit is contained in:
parent
d06014353d
commit
709e7447ed
4 changed files with 47 additions and 10 deletions
|
@ -48,6 +48,9 @@ class Calendar extends \Sabre\CalDAV\Calendar implements IShareable {
|
||||||
/** @var IConfig */
|
/** @var IConfig */
|
||||||
private $config;
|
private $config;
|
||||||
|
|
||||||
|
/** @var IL10N */
|
||||||
|
protected $l10n;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calendar constructor.
|
* Calendar constructor.
|
||||||
*
|
*
|
||||||
|
@ -68,6 +71,7 @@ class Calendar extends \Sabre\CalDAV\Calendar implements IShareable {
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->config = $config;
|
$this->config = $config;
|
||||||
|
$this->l10n = $l10n;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -289,7 +293,7 @@ class Calendar extends \Sabre\CalDAV\Calendar implements IShareable {
|
||||||
|
|
||||||
$obj['acl'] = $this->getChildACL();
|
$obj['acl'] = $this->getChildACL();
|
||||||
|
|
||||||
return new CalendarObject($this->caldavBackend, $this->calendarInfo, $obj);
|
return new CalendarObject($this->caldavBackend, $this->l10n, $this->calendarInfo, $obj);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -302,7 +306,7 @@ class Calendar extends \Sabre\CalDAV\Calendar implements IShareable {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
$obj['acl'] = $this->getChildACL();
|
$obj['acl'] = $this->getChildACL();
|
||||||
$children[] = new CalendarObject($this->caldavBackend, $this->calendarInfo, $obj);
|
$children[] = new CalendarObject($this->caldavBackend, $this->l10n, $this->calendarInfo, $obj);
|
||||||
}
|
}
|
||||||
return $children;
|
return $children;
|
||||||
|
|
||||||
|
@ -317,7 +321,7 @@ class Calendar extends \Sabre\CalDAV\Calendar implements IShareable {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
$obj['acl'] = $this->getChildACL();
|
$obj['acl'] = $this->getChildACL();
|
||||||
$children[] = new CalendarObject($this->caldavBackend, $this->calendarInfo, $obj);
|
$children[] = new CalendarObject($this->caldavBackend, $this->l10n, $this->calendarInfo, $obj);
|
||||||
}
|
}
|
||||||
return $children;
|
return $children;
|
||||||
|
|
||||||
|
|
|
@ -2,9 +2,11 @@
|
||||||
/**
|
/**
|
||||||
* @copyright Copyright (c) 2016, ownCloud, Inc.
|
* @copyright Copyright (c) 2016, ownCloud, Inc.
|
||||||
* @copyright Copyright (c) 2017, Georg Ehrke
|
* @copyright Copyright (c) 2017, Georg Ehrke
|
||||||
|
* @copyright Copyright (c) 2020, Gary Kim <gary@garykim.dev>
|
||||||
*
|
*
|
||||||
* @author Georg Ehrke <oc.list@georgehrke.com>
|
* @author Georg Ehrke <oc.list@georgehrke.com>
|
||||||
* @author Thomas Müller <thomas.mueller@tmit.eu>
|
* @author Thomas Müller <thomas.mueller@tmit.eu>
|
||||||
|
* @author Gary Kim <gary@garykim.dev>
|
||||||
*
|
*
|
||||||
* @license AGPL-3.0
|
* @license AGPL-3.0
|
||||||
*
|
*
|
||||||
|
@ -25,26 +27,34 @@
|
||||||
namespace OCA\DAV\CalDAV;
|
namespace OCA\DAV\CalDAV;
|
||||||
|
|
||||||
|
|
||||||
|
use OCP\IL10N;
|
||||||
use Sabre\VObject\Component;
|
use Sabre\VObject\Component;
|
||||||
use Sabre\VObject\Property;
|
use Sabre\VObject\Property;
|
||||||
use Sabre\VObject\Reader;
|
use Sabre\VObject\Reader;
|
||||||
|
|
||||||
class CalendarObject extends \Sabre\CalDAV\CalendarObject {
|
class CalendarObject extends \Sabre\CalDAV\CalendarObject {
|
||||||
|
|
||||||
|
/** @var IL10N */
|
||||||
|
protected $l10n;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* CalendarObject constructor.
|
* CalendarObject constructor.
|
||||||
*
|
*
|
||||||
* @param CalDavBackend $caldavBackend
|
* @param CalDavBackend $caldavBackend
|
||||||
|
* @param IL10N $l10n
|
||||||
* @param array $calendarInfo
|
* @param array $calendarInfo
|
||||||
* @param array $objectData
|
* @param array $objectData
|
||||||
*/
|
*/
|
||||||
public function __construct(CalDavBackend $caldavBackend, array $calendarInfo,
|
public function __construct(CalDavBackend $caldavBackend, IL10N $l10n,
|
||||||
|
array $calendarInfo,
|
||||||
array $objectData) {
|
array $objectData) {
|
||||||
parent::__construct($caldavBackend, $calendarInfo, $objectData);
|
parent::__construct($caldavBackend, $calendarInfo, $objectData);
|
||||||
|
|
||||||
if ($this->isShared()) {
|
if ($this->isShared()) {
|
||||||
unset($this->objectData['size']);
|
unset($this->objectData['size']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->l10n = $l10n;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -84,7 +94,7 @@ class CalendarObject extends \Sabre\CalDAV\CalendarObject {
|
||||||
* @param Component\VCalendar $vObject
|
* @param Component\VCalendar $vObject
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
private static function createConfidentialObject(Component\VCalendar $vObject) {
|
private function createConfidentialObject(Component\VCalendar $vObject) {
|
||||||
/** @var Component $vElement */
|
/** @var Component $vElement */
|
||||||
$vElement = null;
|
$vElement = null;
|
||||||
if(isset($vObject->VEVENT)) {
|
if(isset($vObject->VEVENT)) {
|
||||||
|
@ -109,7 +119,7 @@ class CalendarObject extends \Sabre\CalDAV\CalendarObject {
|
||||||
case 'UID':
|
case 'UID':
|
||||||
break;
|
break;
|
||||||
case 'SUMMARY':
|
case 'SUMMARY':
|
||||||
$property->setValue('Busy');
|
$property->setValue($this->l10n->t('Busy'));
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
$vElement->__unset($property->name);
|
$vElement->__unset($property->name);
|
||||||
|
|
|
@ -44,7 +44,7 @@ class PublicCalendar extends Calendar {
|
||||||
}
|
}
|
||||||
$obj['acl'] = $this->getChildACL();
|
$obj['acl'] = $this->getChildACL();
|
||||||
|
|
||||||
return new PublicCalendarObject($this->caldavBackend, $this->calendarInfo, $obj);
|
return new PublicCalendarObject($this->caldavBackend, $this->l10n, $this->calendarInfo, $obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -58,7 +58,7 @@ class PublicCalendar extends Calendar {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
$obj['acl'] = $this->getChildACL();
|
$obj['acl'] = $this->getChildACL();
|
||||||
$children[] = new PublicCalendarObject($this->caldavBackend, $this->calendarInfo, $obj);
|
$children[] = new PublicCalendarObject($this->caldavBackend, $this->l10n, $this->calendarInfo, $obj);
|
||||||
}
|
}
|
||||||
return $children;
|
return $children;
|
||||||
}
|
}
|
||||||
|
@ -75,7 +75,7 @@ class PublicCalendar extends Calendar {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
$obj['acl'] = $this->getChildACL();
|
$obj['acl'] = $this->getChildACL();
|
||||||
$children[] = new PublicCalendarObject($this->caldavBackend, $this->calendarInfo, $obj);
|
$children[] = new PublicCalendarObject($this->caldavBackend, $this->l10n, $this->calendarInfo, $obj);
|
||||||
}
|
}
|
||||||
return $children;
|
return $children;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,12 +1,14 @@
|
||||||
<?php
|
<?php
|
||||||
/**
|
/**
|
||||||
* @copyright Copyright (c) 2016, ownCloud, Inc.
|
* @copyright Copyright (c) 2016, ownCloud, Inc.
|
||||||
|
* @copyright Copyright (c) 2020, Gary Kim <gary@garykim.dev>
|
||||||
*
|
*
|
||||||
* @author Georg Ehrke <oc.list@georgehrke.com>
|
* @author Georg Ehrke <oc.list@georgehrke.com>
|
||||||
* @author Joas Schilling <coding@schilljs.com>
|
* @author Joas Schilling <coding@schilljs.com>
|
||||||
* @author Morris Jobke <hey@morrisjobke.de>
|
* @author Morris Jobke <hey@morrisjobke.de>
|
||||||
* @author Roeland Jago Douma <roeland@famdouma.nl>
|
* @author Roeland Jago Douma <roeland@famdouma.nl>
|
||||||
* @author Thomas Müller <thomas.mueller@tmit.eu>
|
* @author Thomas Müller <thomas.mueller@tmit.eu>
|
||||||
|
* @author Gary Kim <gary@garykim.dev>
|
||||||
*
|
*
|
||||||
* @license AGPL-3.0
|
* @license AGPL-3.0
|
||||||
*
|
*
|
||||||
|
@ -73,7 +75,7 @@ class CalendarTest extends TestCase {
|
||||||
$c->delete();
|
$c->delete();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function testDeleteFromGroup() {
|
public function testDeleteFromGroup() {
|
||||||
$this->expectException(\Sabre\DAV\Exception\Forbidden::class);
|
$this->expectException(\Sabre\DAV\Exception\Forbidden::class);
|
||||||
|
|
||||||
|
@ -427,6 +429,27 @@ EOD;
|
||||||
} else {
|
} else {
|
||||||
$this->assertEquals('Test Event', $event->VEVENT->SUMMARY->getValue());
|
$this->assertEquals('Test Event', $event->VEVENT->SUMMARY->getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Test l10n
|
||||||
|
$l10n = $this->createMock(IL10N::class);
|
||||||
|
if ($isShared) {
|
||||||
|
$l10n->expects($this->once())
|
||||||
|
->method('t')
|
||||||
|
->with('Busy')
|
||||||
|
->willReturn("Translated busy");
|
||||||
|
} else {
|
||||||
|
$l10n->expects($this->never());
|
||||||
|
}
|
||||||
|
$c = new Calendar($backend, $calendarInfo, $l10n, $this->config);
|
||||||
|
|
||||||
|
$calData = $c->getChild('event-1')->get();
|
||||||
|
$event = Reader::read($calData);
|
||||||
|
|
||||||
|
if ($isShared) {
|
||||||
|
$this->assertEquals('Translated busy', $event->VEVENT->SUMMARY->getValue());
|
||||||
|
} else {
|
||||||
|
$this->assertEquals('Test Event', $event->VEVENT->SUMMARY->getValue());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function providesConfidentialClassificationData() {
|
public function providesConfidentialClassificationData() {
|
||||||
|
|
Loading…
Reference in a new issue