diff options
author | Morris Jobke <hey@morrisjobke.de> | 2016-10-06 23:00:26 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-10-06 23:00:26 +0200 |
commit | 6278d3bbfdc406a5f5c790472336d4c515f70894 (patch) | |
tree | 95ef453eed37c2c0a77b6015d45c547a04309c58 /apps | |
parent | c4b26395859939ab07b875ab6ccff6598c12f2b2 (diff) | |
parent | 70e0074e5c78fd2be02721c4df7971c11b567530 (diff) | |
download | nextcloud-server-6278d3bbfdc406a5f5c790472336d4c515f70894.tar.gz nextcloud-server-6278d3bbfdc406a5f5c790472336d4c515f70894.zip |
Merge pull request #1144 from nextcloud/translate-default-calendar
translate default calendar & default address book displaynames & add …
Diffstat (limited to 'apps')
-rw-r--r-- | apps/dav/l10n/.gitkeep | 0 | ||||
-rw-r--r-- | apps/dav/lib/CalDAV/CalDavBackend.php | 3 | ||||
-rw-r--r-- | apps/dav/lib/CalDAV/Calendar.php | 4 | ||||
-rw-r--r-- | apps/dav/lib/CardDAV/AddressBook.php | 18 | ||||
-rw-r--r-- | apps/dav/lib/CardDAV/AddressBookRoot.php | 17 | ||||
-rw-r--r-- | apps/dav/lib/CardDAV/CardDavBackend.php | 3 | ||||
-rw-r--r-- | apps/dav/lib/CardDAV/ContactsManager.php | 10 | ||||
-rw-r--r-- | apps/dav/lib/CardDAV/UserAddressBooks.php | 10 | ||||
-rw-r--r-- | apps/dav/lib/HookManager.php | 11 | ||||
-rw-r--r-- | apps/dav/tests/unit/CardDAV/AddressBookTest.php | 22 | ||||
-rw-r--r-- | apps/dav/tests/unit/CardDAV/CardDavBackendTest.php | 7 | ||||
-rw-r--r-- | apps/dav/tests/unit/CardDAV/ContactsManagerTest.php | 6 |
12 files changed, 91 insertions, 20 deletions
diff --git a/apps/dav/l10n/.gitkeep b/apps/dav/l10n/.gitkeep new file mode 100644 index 00000000000..e69de29bb2d --- /dev/null +++ b/apps/dav/l10n/.gitkeep diff --git a/apps/dav/lib/CalDAV/CalDavBackend.php b/apps/dav/lib/CalDAV/CalDavBackend.php index d742061428b..07b61285eca 100644 --- a/apps/dav/lib/CalDAV/CalDavBackend.php +++ b/apps/dav/lib/CalDAV/CalDavBackend.php @@ -59,6 +59,9 @@ use Sabre\VObject\Recur\EventIterator; */ class CalDavBackend extends AbstractBackend implements SyncSupport, SubscriptionSupport, SchedulingSupport { + const PERSONAL_CALENDAR_URI = 'personal'; + const PERSONAL_CALENDAR_NAME = 'Personal'; + /** * We need to specify a max date, because we need to stop *somewhere* * diff --git a/apps/dav/lib/CalDAV/Calendar.php b/apps/dav/lib/CalDAV/Calendar.php index 3fbcd87acc0..fc08c9ac87a 100644 --- a/apps/dav/lib/CalDAV/Calendar.php +++ b/apps/dav/lib/CalDAV/Calendar.php @@ -38,6 +38,10 @@ class Calendar extends \Sabre\CalDAV\Calendar implements IShareable { if ($this->getName() === BirthdayService::BIRTHDAY_CALENDAR_URI) { $this->calendarInfo['{DAV:}displayname'] = $l10n->t('Contact birthdays'); } + if ($this->getName() === CalDavBackend::PERSONAL_CALENDAR_URI && + $this->calendarInfo['{DAV:}displayname'] === CalDavBackend::PERSONAL_CALENDAR_NAME) { + $this->calendarInfo['{DAV:}displayname'] = $l10n->t('Personal'); + } } /** diff --git a/apps/dav/lib/CardDAV/AddressBook.php b/apps/dav/lib/CardDAV/AddressBook.php index 76633511504..1c13ac00aec 100644 --- a/apps/dav/lib/CardDAV/AddressBook.php +++ b/apps/dav/lib/CardDAV/AddressBook.php @@ -22,6 +22,8 @@ namespace OCA\DAV\CardDAV; use OCA\DAV\DAV\Sharing\IShareable; +use OCP\IL10N; +use Sabre\CardDAV\Backend\BackendInterface; use Sabre\CardDAV\Card; use Sabre\DAV\Exception\Forbidden; use Sabre\DAV\Exception\NotFound; @@ -30,6 +32,22 @@ use Sabre\DAV\PropPatch; class AddressBook extends \Sabre\CardDAV\AddressBook implements IShareable { /** + * AddressBook constructor. + * + * @param BackendInterface $carddavBackend + * @param array $addressBookInfo + * @param IL10N $l10n + */ + public function __construct(BackendInterface $carddavBackend, array $addressBookInfo, IL10N $l10n) { + parent::__construct($carddavBackend, $addressBookInfo); + + if ($this->getName() === CardDavBackend::PERSONAL_ADDRESSBOOK_URI && + $this->addressBookInfo['{DAV:}displayname'] === CardDavBackend::PERSONAL_ADDRESSBOOK_NAME) { + $this->addressBookInfo['{DAV:}displayname'] = $l10n->t('Contacts'); + } + } + + /** * Updates the list of shares. * * The first array is a list of people that are to be added to the diff --git a/apps/dav/lib/CardDAV/AddressBookRoot.php b/apps/dav/lib/CardDAV/AddressBookRoot.php index 41c858e35ec..88435165a88 100644 --- a/apps/dav/lib/CardDAV/AddressBookRoot.php +++ b/apps/dav/lib/CardDAV/AddressBookRoot.php @@ -21,8 +21,23 @@ */ namespace OCA\DAV\CardDAV; +use OCP\IL10N; + class AddressBookRoot extends \Sabre\CardDAV\AddressBookRoot { + /** @var IL10N */ + protected $l10n; + + /** + * @param \Sabre\DAVACL\PrincipalBackend\BackendInterface $principalBackend + * @param \Sabre\CardDAV\Backend\BackendInterface $carddavBackend + * @param string $principalPrefix + */ + public function __construct(\Sabre\DAVACL\PrincipalBackend\BackendInterface $principalBackend, \Sabre\CardDAV\Backend\BackendInterface $carddavBackend, $principalPrefix = 'principals') { + parent::__construct($principalBackend, $carddavBackend, $principalPrefix); + $this->l10n = \OC::$server->getL10N('dav'); + } + /** * This method returns a node for a principal. * @@ -35,7 +50,7 @@ class AddressBookRoot extends \Sabre\CardDAV\AddressBookRoot { */ function getChildForPrincipal(array $principal) { - return new UserAddressBooks($this->carddavBackend, $principal['uri']); + return new UserAddressBooks($this->carddavBackend, $principal['uri'], $this->l10n); } diff --git a/apps/dav/lib/CardDAV/CardDavBackend.php b/apps/dav/lib/CardDAV/CardDavBackend.php index 3aab2712125..de717a17642 100644 --- a/apps/dav/lib/CardDAV/CardDavBackend.php +++ b/apps/dav/lib/CardDAV/CardDavBackend.php @@ -48,6 +48,9 @@ use Symfony\Component\EventDispatcher\GenericEvent; class CardDavBackend implements BackendInterface, SyncSupport { + const PERSONAL_ADDRESSBOOK_URI = 'contacts'; + const PERSONAL_ADDRESSBOOK_NAME = 'Contacts'; + /** @var Principal */ private $principalBackend; diff --git a/apps/dav/lib/CardDAV/ContactsManager.php b/apps/dav/lib/CardDAV/ContactsManager.php index 3f2019d582b..b2e3544b287 100644 --- a/apps/dav/lib/CardDAV/ContactsManager.php +++ b/apps/dav/lib/CardDAV/ContactsManager.php @@ -25,19 +25,25 @@ namespace OCA\DAV\CardDAV; use OCP\Contacts\IManager; +use OCP\IL10N; use OCP\IURLGenerator; class ContactsManager { /** @var CardDavBackend */ private $backend; + /** @var IL10N */ + private $l10n; + /** * ContactsManager constructor. * * @param CardDavBackend $backend + * @param IL10N $l10n */ - public function __construct(CardDavBackend $backend) { + public function __construct(CardDavBackend $backend, IL10N $l10n) { $this->backend = $backend; + $this->l10n = $l10n; } /** @@ -59,7 +65,7 @@ class ContactsManager { */ private function register(IManager $cm, $addressBooks, $urlGenerator) { foreach ($addressBooks as $addressBookInfo) { - $addressBook = new \OCA\DAV\CardDAV\AddressBook($this->backend, $addressBookInfo); + $addressBook = new \OCA\DAV\CardDAV\AddressBook($this->backend, $addressBookInfo, $this->l10n); $cm->registerAddressBook( new AddressBookImpl( $addressBook, diff --git a/apps/dav/lib/CardDAV/UserAddressBooks.php b/apps/dav/lib/CardDAV/UserAddressBooks.php index 2ac89f302fd..4c7626ba42b 100644 --- a/apps/dav/lib/CardDAV/UserAddressBooks.php +++ b/apps/dav/lib/CardDAV/UserAddressBooks.php @@ -21,19 +21,27 @@ */ namespace OCA\DAV\CardDAV; +use OCP\IL10N; + class UserAddressBooks extends \Sabre\CardDAV\AddressBookHome { + /** @var IL10N */ + protected $l10n; + /** * Returns a list of addressbooks * * @return array */ function getChildren() { + if ($this->l10n === null) { + $this->l10n = \OC::$server->getL10N('dav'); + } $addressBooks = $this->carddavBackend->getAddressBooksForUser($this->principalUri); $objects = []; foreach($addressBooks as $addressBook) { - $objects[] = new AddressBook($this->carddavBackend, $addressBook); + $objects[] = new AddressBook($this->carddavBackend, $addressBook, $this->l10n); } return $objects; diff --git a/apps/dav/lib/HookManager.php b/apps/dav/lib/HookManager.php index 364db19d76a..92aa4fce7fa 100644 --- a/apps/dav/lib/HookManager.php +++ b/apps/dav/lib/HookManager.php @@ -21,7 +21,6 @@ */ namespace OCA\DAV; -use OCA\DAV\CalDAV\BirthdayService; use OCA\DAV\CalDAV\CalDavBackend; use OCA\DAV\CardDAV\CardDavBackend; use OCA\DAV\CardDAV\SyncService; @@ -124,16 +123,18 @@ class HookManager { $principal = 'principals/users/' . $user->getUID(); if ($this->calDav->getCalendarsForUserCount($principal) === 0) { try { - $this->calDav->createCalendar($principal, 'personal', [ - '{DAV:}displayname' => 'Personal']); + $this->calDav->createCalendar($principal, CalDavBackend::PERSONAL_CALENDAR_URI, [ + '{DAV:}displayname' => CalDavBackend::PERSONAL_CALENDAR_NAME, + ]); } catch (\Exception $ex) { \OC::$server->getLogger()->logException($ex); } } if ($this->cardDav->getAddressBooksForUserCount($principal) === 0) { try { - $this->cardDav->createAddressBook($principal, 'contacts', [ - '{DAV:}displayname' => 'Contacts']); + $this->cardDav->createAddressBook($principal, CardDavBackend::PERSONAL_ADDRESSBOOK_URI, [ + '{DAV:}displayname' => CardDavBackend::PERSONAL_ADDRESSBOOK_NAME, + ]); } catch (\Exception $ex) { \OC::$server->getLogger()->logException($ex); } diff --git a/apps/dav/tests/unit/CardDAV/AddressBookTest.php b/apps/dav/tests/unit/CardDAV/AddressBookTest.php index 8a608e277e2..22992d564f6 100644 --- a/apps/dav/tests/unit/CardDAV/AddressBookTest.php +++ b/apps/dav/tests/unit/CardDAV/AddressBookTest.php @@ -25,6 +25,7 @@ namespace OCA\DAV\Tests\unit\CardDAV; use OCA\DAV\CardDAV\AddressBook; use OCA\DAV\CardDAV\CardDavBackend; +use OCP\IL10N; use Sabre\DAV\PropPatch; use Test\TestCase; @@ -40,9 +41,11 @@ class AddressBookTest extends TestCase { $calendarInfo = [ '{http://owncloud.org/ns}owner-principal' => 'user1', 'principaluri' => 'user2', - 'id' => 666 + 'id' => 666, + 'uri' => 'default', ]; - $c = new AddressBook($backend, $calendarInfo); + $l = $this->createMock(IL10N::class); + $c = new AddressBook($backend, $calendarInfo, $l); $c->delete(); } @@ -59,9 +62,11 @@ class AddressBookTest extends TestCase { $calendarInfo = [ '{http://owncloud.org/ns}owner-principal' => 'user1', 'principaluri' => 'user2', - 'id' => 666 + 'id' => 666, + 'uri' => 'default', ]; - $c = new AddressBook($backend, $calendarInfo); + $l = $this->createMock(IL10N::class); + $c = new AddressBook($backend, $calendarInfo, $l); $c->delete(); } @@ -74,9 +79,11 @@ class AddressBookTest extends TestCase { $calendarInfo = [ '{http://owncloud.org/ns}owner-principal' => 'user1', 'principaluri' => 'user2', - 'id' => 666 + 'id' => 666, + 'uri' => 'default', ]; - $c = new AddressBook($backend, $calendarInfo); + $l = $this->createMock(IL10N::class); + $c = new AddressBook($backend, $calendarInfo, $l); $c->propPatch(new PropPatch([])); } @@ -98,7 +105,8 @@ class AddressBookTest extends TestCase { if ($hasOwnerSet) { $calendarInfo['{http://owncloud.org/ns}owner-principal'] = 'user1'; } - $c = new AddressBook($backend, $calendarInfo); + $l = $this->createMock(IL10N::class); + $c = new AddressBook($backend, $calendarInfo, $l); $acl = $c->getACL(); $childAcl = $c->getChildACL(); diff --git a/apps/dav/tests/unit/CardDAV/CardDavBackendTest.php b/apps/dav/tests/unit/CardDAV/CardDavBackendTest.php index cf5972f79bf..890b70d6afa 100644 --- a/apps/dav/tests/unit/CardDAV/CardDavBackendTest.php +++ b/apps/dav/tests/unit/CardDAV/CardDavBackendTest.php @@ -33,6 +33,7 @@ use OCA\DAV\CardDAV\CardDavBackend; use OCA\DAV\Connector\Sabre\Principal; use OCP\DB\QueryBuilder\IQueryBuilder; use OCP\IDBConnection; +use OCP\IL10N; use Sabre\DAV\PropPatch; use Sabre\VObject\Component\VCard; use Sabre\VObject\Property\Text; @@ -146,7 +147,8 @@ class CardDavBackendTest extends TestCase { $this->backend->createAddressBook(self::UNIT_TEST_USER, 'Example', []); $books = $this->backend->getAddressBooksForUser(self::UNIT_TEST_USER); $this->assertEquals(1, count($books)); - $addressBook = new AddressBook($this->backend, $books[0]); + $l = $this->createMock(IL10N::class); + $addressBook = new AddressBook($this->backend, $books[0], $l); $this->backend->updateShares($addressBook, [ [ 'href' => 'principal:' . self::UNIT_TEST_USER1, @@ -329,7 +331,8 @@ class CardDavBackendTest extends TestCase { $books = $this->backend->getAddressBooksForUser(self::UNIT_TEST_USER); $this->assertEquals(1, count($books)); - $exampleBook = new AddressBook($this->backend, $books[0]); + $l = $this->createMock(IL10N::class); + $exampleBook = new AddressBook($this->backend, $books[0], $l); $this->backend->updateShares($exampleBook, [['href' => 'principal:principals/best-friend']], []); $shares = $this->backend->getShares($exampleBook->getResourceId()); diff --git a/apps/dav/tests/unit/CardDAV/ContactsManagerTest.php b/apps/dav/tests/unit/CardDAV/ContactsManagerTest.php index 6859d0686df..062ef72dbf0 100644 --- a/apps/dav/tests/unit/CardDAV/ContactsManagerTest.php +++ b/apps/dav/tests/unit/CardDAV/ContactsManagerTest.php @@ -27,6 +27,7 @@ namespace OCA\DAV\Tests\unit\CardDAV; use OCA\DAV\CardDAV\CardDavBackend; use OCA\DAV\CardDAV\ContactsManager; use OCP\Contacts\IManager; +use OCP\IL10N; use Test\TestCase; class ContactsManagerTest extends TestCase { @@ -38,10 +39,11 @@ class ContactsManagerTest extends TestCase { /** @var CardDavBackend | \PHPUnit_Framework_MockObject_MockObject $backEnd */ $backEnd = $this->getMockBuilder('OCA\DAV\CardDAV\CardDavBackend')->disableOriginalConstructor()->getMock(); $backEnd->method('getAddressBooksForUser')->willReturn([ - [] + ['uri' => 'default'], ]); - $app = new ContactsManager($backEnd); + $l = $this->createMock(IL10N::class); + $app = new ContactsManager($backEnd, $l); $app->setupContactsProvider($cm, 'user01', $urlGenerator); } } |