Translate the Contacts addressbook when it's default

Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
Joas Schilling 2016-09-20 14:15:23 +02:00
parent a4f82f13f3
commit ce964f0a10
No known key found for this signature in database
GPG Key ID: E166FD8976B3BAC8
6 changed files with 57 additions and 6 deletions

View File

@ -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;
@ -29,6 +31,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.
*

View File

@ -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);
}

View File

@ -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;

View File

@ -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,

View File

@ -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;

View File

@ -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);
}