summaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
authorJoas Schilling <coding@schilljs.com>2016-09-20 14:15:23 +0200
committerJoas Schilling <coding@schilljs.com>2016-10-06 14:20:01 +0200
commitce964f0a10dc2d160a67e8b4e86c5f0c18195d57 (patch)
treebdef6db36f7ee3ef873d555b77ed75d993659aed /apps
parenta4f82f13f396fc063643ab4a9dfcf17b52019332 (diff)
downloadnextcloud-server-ce964f0a10dc2d160a67e8b4e86c5f0c18195d57.tar.gz
nextcloud-server-ce964f0a10dc2d160a67e8b4e86c5f0c18195d57.zip
Translate the Contacts addressbook when it's default
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'apps')
-rw-r--r--apps/dav/lib/CardDAV/AddressBook.php18
-rw-r--r--apps/dav/lib/CardDAV/AddressBookRoot.php17
-rw-r--r--apps/dav/lib/CardDAV/CardDavBackend.php3
-rw-r--r--apps/dav/lib/CardDAV/ContactsManager.php10
-rw-r--r--apps/dav/lib/CardDAV/UserAddressBooks.php10
-rw-r--r--apps/dav/lib/HookManager.php5
6 files changed, 57 insertions, 6 deletions
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 0ea5e47dd95..92aa4fce7fa 100644
--- a/apps/dav/lib/HookManager.php
+++ b/apps/dav/lib/HookManager.php
@@ -132,8 +132,9 @@ class HookManager {
}
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);
}