Merge pull request #23998 from owncloud/translate-birthday

Translate contacts birthday
This commit is contained in:
Thomas Müller 2016-04-14 23:41:03 +02:00
commit b23037ec5c
5 changed files with 54 additions and 17 deletions

View File

@ -22,17 +22,19 @@
namespace OCA\DAV\CalDAV; namespace OCA\DAV\CalDAV;
use OCA\DAV\DAV\Sharing\IShareable; use OCA\DAV\DAV\Sharing\IShareable;
use OCP\IL10N;
use Sabre\CalDAV\Backend\BackendInterface; use Sabre\CalDAV\Backend\BackendInterface;
use Sabre\DAV\Exception\Forbidden; use Sabre\DAV\Exception\Forbidden;
use Sabre\DAV\PropPatch; use Sabre\DAV\PropPatch;
class Calendar extends \Sabre\CalDAV\Calendar implements IShareable { class Calendar extends \Sabre\CalDAV\Calendar implements IShareable {
public function __construct(BackendInterface $caldavBackend, $calendarInfo) { public function __construct(BackendInterface $caldavBackend, $calendarInfo, IL10N $l10n) {
parent::__construct($caldavBackend, $calendarInfo); parent::__construct($caldavBackend, $calendarInfo);
if ($this->getName() === BirthdayService::BIRTHDAY_CALENDAR_URI) { if ($this->getName() === BirthdayService::BIRTHDAY_CALENDAR_URI) {
$this->calendarInfo['{http://sabredav.org/ns}read-only'] = true; $this->calendarInfo['{http://sabredav.org/ns}read-only'] = true;
$this->calendarInfo['{DAV:}displayname'] = $l10n->t('Contact birthdays');
} }
} }

View File

@ -21,6 +21,7 @@
*/ */
namespace OCA\DAV\CalDAV; namespace OCA\DAV\CalDAV;
use Sabre\CalDAV\Backend\BackendInterface;
use Sabre\CalDAV\Backend\NotificationSupport; use Sabre\CalDAV\Backend\NotificationSupport;
use Sabre\CalDAV\Backend\SchedulingSupport; use Sabre\CalDAV\Backend\SchedulingSupport;
use Sabre\CalDAV\Backend\SubscriptionSupport; use Sabre\CalDAV\Backend\SubscriptionSupport;
@ -31,34 +32,42 @@ use Sabre\DAV\Exception\NotFound;
class CalendarHome extends \Sabre\CalDAV\CalendarHome { class CalendarHome extends \Sabre\CalDAV\CalendarHome {
/** @var \OCP\IL10N */
private $l10n;
public function __construct(BackendInterface $caldavBackend, $principalInfo) {
parent::__construct($caldavBackend, $principalInfo);
$this->l10n = \OC::$server->getL10N('dav');
}
/** /**
* @inheritdoc * @inheritdoc
*/ */
function getChildren() { function getChildren() {
$calendars = $this->caldavBackend->getCalendarsForUser($this->principalInfo['uri']); $calendars = $this->caldavBackend->getCalendarsForUser($this->principalInfo['uri']);
$objs = []; $objects = [];
foreach ($calendars as $calendar) { foreach ($calendars as $calendar) {
$objs[] = new Calendar($this->caldavBackend, $calendar); $objects[] = new Calendar($this->caldavBackend, $calendar, $this->l10n);
} }
if ($this->caldavBackend instanceof SchedulingSupport) { if ($this->caldavBackend instanceof SchedulingSupport) {
$objs[] = new Inbox($this->caldavBackend, $this->principalInfo['uri']); $objects[] = new Inbox($this->caldavBackend, $this->principalInfo['uri']);
$objs[] = new Outbox($this->principalInfo['uri']); $objects[] = new Outbox($this->principalInfo['uri']);
} }
// We're adding a notifications node, if it's supported by the backend. // We're adding a notifications node, if it's supported by the backend.
if ($this->caldavBackend instanceof NotificationSupport) { if ($this->caldavBackend instanceof NotificationSupport) {
$objs[] = new \Sabre\CalDAV\Notifications\Collection($this->caldavBackend, $this->principalInfo['uri']); $objects[] = new \Sabre\CalDAV\Notifications\Collection($this->caldavBackend, $this->principalInfo['uri']);
} }
// If the backend supports subscriptions, we'll add those as well, // If the backend supports subscriptions, we'll add those as well,
if ($this->caldavBackend instanceof SubscriptionSupport) { if ($this->caldavBackend instanceof SubscriptionSupport) {
foreach ($this->caldavBackend->getSubscriptionsForUser($this->principalInfo['uri']) as $subscription) { foreach ($this->caldavBackend->getSubscriptionsForUser($this->principalInfo['uri']) as $subscription) {
$objs[] = new Subscription($this->caldavBackend, $subscription); $objects[] = new Subscription($this->caldavBackend, $subscription);
} }
} }
return $objs; return $objects;
} }
/** /**
@ -79,7 +88,7 @@ class CalendarHome extends \Sabre\CalDAV\CalendarHome {
// Calendars // Calendars
foreach ($this->caldavBackend->getCalendarsForUser($this->principalInfo['uri']) as $calendar) { foreach ($this->caldavBackend->getCalendarsForUser($this->principalInfo['uri']) as $calendar) {
if ($calendar['uri'] === $name) { if ($calendar['uri'] === $name) {
return new Calendar($this->caldavBackend, $calendar); return new Calendar($this->caldavBackend, $calendar, $this->l10n);
} }
} }

View File

@ -136,14 +136,23 @@ class CalDavBackendTest extends TestCase {
*/ */
public function testCalendarSharing($userCanRead, $userCanWrite, $groupCanRead, $groupCanWrite, $add) { public function testCalendarSharing($userCanRead, $userCanWrite, $groupCanRead, $groupCanWrite, $add) {
$l10n = $this->getMockBuilder('\OCP\IL10N')
->disableOriginalConstructor()->getMock();
$l10n
->expects($this->any())
->method('t')
->will($this->returnCallback(function ($text, $parameters = array()) {
return vsprintf($text, $parameters);
}));
$calendarId = $this->createTestCalendar(); $calendarId = $this->createTestCalendar();
$books = $this->backend->getCalendarsForUser(self::UNIT_TEST_USER); $books = $this->backend->getCalendarsForUser(self::UNIT_TEST_USER);
$this->assertEquals(1, count($books)); $this->assertEquals(1, count($books));
$calendar = new Calendar($this->backend, $books[0]); $calendar = new Calendar($this->backend, $books[0], $l10n);
$this->backend->updateShares($calendar, $add, []); $this->backend->updateShares($calendar, $add, []);
$books = $this->backend->getCalendarsForUser(self::UNIT_TEST_USER1); $books = $this->backend->getCalendarsForUser(self::UNIT_TEST_USER1);
$this->assertEquals(1, count($books)); $this->assertEquals(1, count($books));
$calendar = new Calendar($this->backend, $books[0]); $calendar = new Calendar($this->backend, $books[0], $l10n);
$acl = $calendar->getACL(); $acl = $calendar->getACL();
$this->assertAcl(self::UNIT_TEST_USER, '{DAV:}read', $acl); $this->assertAcl(self::UNIT_TEST_USER, '{DAV:}read', $acl);
$this->assertAcl(self::UNIT_TEST_USER, '{DAV:}write', $acl); $this->assertAcl(self::UNIT_TEST_USER, '{DAV:}write', $acl);

View File

@ -23,11 +23,27 @@ namespace OCA\DAV\Tests\Unit\CalDAV;
use OCA\DAV\CalDAV\CalDavBackend; use OCA\DAV\CalDAV\CalDavBackend;
use OCA\DAV\CalDAV\Calendar; use OCA\DAV\CalDAV\Calendar;
use OCP\IL10N;
use Sabre\DAV\PropPatch; use Sabre\DAV\PropPatch;
use Test\TestCase; use Test\TestCase;
class CalendarTest extends TestCase { class CalendarTest extends TestCase {
/** @var IL10N */
private $l10n;
public function setUp() {
parent::setUp();
$this->l10n = $this->getMockBuilder('\OCP\IL10N')
->disableOriginalConstructor()->getMock();
$this->l10n
->expects($this->any())
->method('t')
->will($this->returnCallback(function ($text, $parameters = array()) {
return vsprintf($text, $parameters);
}));
}
public function testDelete() { public function testDelete() {
/** @var \PHPUnit_Framework_MockObject_MockObject | CalDavBackend $backend */ /** @var \PHPUnit_Framework_MockObject_MockObject | CalDavBackend $backend */
$backend = $this->getMockBuilder('OCA\DAV\CalDAV\CalDavBackend')->disableOriginalConstructor()->getMock(); $backend = $this->getMockBuilder('OCA\DAV\CalDAV\CalDavBackend')->disableOriginalConstructor()->getMock();
@ -41,7 +57,7 @@ class CalendarTest extends TestCase {
'id' => 666, 'id' => 666,
'uri' => 'cal', 'uri' => 'cal',
]; ];
$c = new Calendar($backend, $calendarInfo); $c = new Calendar($backend, $calendarInfo, $this->l10n);
$c->delete(); $c->delete();
} }
@ -61,7 +77,7 @@ class CalendarTest extends TestCase {
'id' => 666, 'id' => 666,
'uri' => 'cal', 'uri' => 'cal',
]; ];
$c = new Calendar($backend, $calendarInfo); $c = new Calendar($backend, $calendarInfo, $this->l10n);
$c->delete(); $c->delete();
} }
@ -93,7 +109,7 @@ class CalendarTest extends TestCase {
'id' => 666, 'id' => 666,
'uri' => 'default' 'uri' => 'default'
]; ];
$c = new Calendar($backend, $calendarInfo); $c = new Calendar($backend, $calendarInfo, $this->l10n);
if ($throws) { if ($throws) {
$this->setExpectedException('\Sabre\DAV\Exception\Forbidden'); $this->setExpectedException('\Sabre\DAV\Exception\Forbidden');
@ -122,7 +138,7 @@ class CalendarTest extends TestCase {
if ($hasOwnerSet) { if ($hasOwnerSet) {
$calendarInfo['{http://owncloud.org/ns}owner-principal'] = 'user1'; $calendarInfo['{http://owncloud.org/ns}owner-principal'] = 'user1';
} }
$c = new Calendar($backend, $calendarInfo); $c = new Calendar($backend, $calendarInfo, $this->l10n);
$acl = $c->getACL(); $acl = $c->getACL();
$childAcl = $c->getChildACL(); $childAcl = $c->getChildACL();

View File

@ -74,6 +74,7 @@ use OC\Security\SecureRandom;
use OC\Security\TrustedDomainHelper; use OC\Security\TrustedDomainHelper;
use OC\Session\CryptoWrapper; use OC\Session\CryptoWrapper;
use OC\Tagging\TagMapper; use OC\Tagging\TagMapper;
use OCP\IL10N;
use OCP\IServerContainer; use OCP\IServerContainer;
use OCP\Security\IContentSecurityPolicyManager; use OCP\Security\IContentSecurityPolicyManager;
use Symfony\Component\EventDispatcher\EventDispatcher; use Symfony\Component\EventDispatcher\EventDispatcher;
@ -857,7 +858,7 @@ class Server extends ServerContainer implements IServerContainer {
* *
* @param string $app appid * @param string $app appid
* @param string $lang * @param string $lang
* @return \OC_L10N * @return IL10N
*/ */
public function getL10N($app, $lang = null) { public function getL10N($app, $lang = null) {
return $this->getL10NFactory()->get($app, $lang); return $this->getL10NFactory()->get($app, $lang);