Translate the Contacts addressbook when it's default
Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
parent
a4f82f13f3
commit
ce964f0a10
6 changed files with 57 additions and 6 deletions
|
@ -22,6 +22,8 @@
|
||||||
namespace OCA\DAV\CardDAV;
|
namespace OCA\DAV\CardDAV;
|
||||||
|
|
||||||
use OCA\DAV\DAV\Sharing\IShareable;
|
use OCA\DAV\DAV\Sharing\IShareable;
|
||||||
|
use OCP\IL10N;
|
||||||
|
use Sabre\CardDAV\Backend\BackendInterface;
|
||||||
use Sabre\CardDAV\Card;
|
use Sabre\CardDAV\Card;
|
||||||
use Sabre\DAV\Exception\Forbidden;
|
use Sabre\DAV\Exception\Forbidden;
|
||||||
use Sabre\DAV\Exception\NotFound;
|
use Sabre\DAV\Exception\NotFound;
|
||||||
|
@ -29,6 +31,22 @@ use Sabre\DAV\PropPatch;
|
||||||
|
|
||||||
class AddressBook extends \Sabre\CardDAV\AddressBook implements IShareable {
|
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.
|
* Updates the list of shares.
|
||||||
*
|
*
|
||||||
|
|
|
@ -21,8 +21,23 @@
|
||||||
*/
|
*/
|
||||||
namespace OCA\DAV\CardDAV;
|
namespace OCA\DAV\CardDAV;
|
||||||
|
|
||||||
|
use OCP\IL10N;
|
||||||
|
|
||||||
class AddressBookRoot extends \Sabre\CardDAV\AddressBookRoot {
|
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.
|
* This method returns a node for a principal.
|
||||||
*
|
*
|
||||||
|
@ -35,7 +50,7 @@ class AddressBookRoot extends \Sabre\CardDAV\AddressBookRoot {
|
||||||
*/
|
*/
|
||||||
function getChildForPrincipal(array $principal) {
|
function getChildForPrincipal(array $principal) {
|
||||||
|
|
||||||
return new UserAddressBooks($this->carddavBackend, $principal['uri']);
|
return new UserAddressBooks($this->carddavBackend, $principal['uri'], $this->l10n);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -48,6 +48,9 @@ use Symfony\Component\EventDispatcher\GenericEvent;
|
||||||
|
|
||||||
class CardDavBackend implements BackendInterface, SyncSupport {
|
class CardDavBackend implements BackendInterface, SyncSupport {
|
||||||
|
|
||||||
|
const PERSONAL_ADDRESSBOOK_URI = 'contacts';
|
||||||
|
const PERSONAL_ADDRESSBOOK_NAME = 'Contacts';
|
||||||
|
|
||||||
/** @var Principal */
|
/** @var Principal */
|
||||||
private $principalBackend;
|
private $principalBackend;
|
||||||
|
|
||||||
|
|
|
@ -25,19 +25,25 @@
|
||||||
namespace OCA\DAV\CardDAV;
|
namespace OCA\DAV\CardDAV;
|
||||||
|
|
||||||
use OCP\Contacts\IManager;
|
use OCP\Contacts\IManager;
|
||||||
|
use OCP\IL10N;
|
||||||
use OCP\IURLGenerator;
|
use OCP\IURLGenerator;
|
||||||
|
|
||||||
class ContactsManager {
|
class ContactsManager {
|
||||||
/** @var CardDavBackend */
|
/** @var CardDavBackend */
|
||||||
private $backend;
|
private $backend;
|
||||||
|
|
||||||
|
/** @var IL10N */
|
||||||
|
private $l10n;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ContactsManager constructor.
|
* ContactsManager constructor.
|
||||||
*
|
*
|
||||||
* @param CardDavBackend $backend
|
* @param CardDavBackend $backend
|
||||||
|
* @param IL10N $l10n
|
||||||
*/
|
*/
|
||||||
public function __construct(CardDavBackend $backend) {
|
public function __construct(CardDavBackend $backend, IL10N $l10n) {
|
||||||
$this->backend = $backend;
|
$this->backend = $backend;
|
||||||
|
$this->l10n = $l10n;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -59,7 +65,7 @@ class ContactsManager {
|
||||||
*/
|
*/
|
||||||
private function register(IManager $cm, $addressBooks, $urlGenerator) {
|
private function register(IManager $cm, $addressBooks, $urlGenerator) {
|
||||||
foreach ($addressBooks as $addressBookInfo) {
|
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(
|
$cm->registerAddressBook(
|
||||||
new AddressBookImpl(
|
new AddressBookImpl(
|
||||||
$addressBook,
|
$addressBook,
|
||||||
|
|
|
@ -21,19 +21,27 @@
|
||||||
*/
|
*/
|
||||||
namespace OCA\DAV\CardDAV;
|
namespace OCA\DAV\CardDAV;
|
||||||
|
|
||||||
|
use OCP\IL10N;
|
||||||
|
|
||||||
class UserAddressBooks extends \Sabre\CardDAV\AddressBookHome {
|
class UserAddressBooks extends \Sabre\CardDAV\AddressBookHome {
|
||||||
|
|
||||||
|
/** @var IL10N */
|
||||||
|
protected $l10n;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a list of addressbooks
|
* Returns a list of addressbooks
|
||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
function getChildren() {
|
function getChildren() {
|
||||||
|
if ($this->l10n === null) {
|
||||||
|
$this->l10n = \OC::$server->getL10N('dav');
|
||||||
|
}
|
||||||
|
|
||||||
$addressBooks = $this->carddavBackend->getAddressBooksForUser($this->principalUri);
|
$addressBooks = $this->carddavBackend->getAddressBooksForUser($this->principalUri);
|
||||||
$objects = [];
|
$objects = [];
|
||||||
foreach($addressBooks as $addressBook) {
|
foreach($addressBooks as $addressBook) {
|
||||||
$objects[] = new AddressBook($this->carddavBackend, $addressBook);
|
$objects[] = new AddressBook($this->carddavBackend, $addressBook, $this->l10n);
|
||||||
}
|
}
|
||||||
return $objects;
|
return $objects;
|
||||||
|
|
||||||
|
|
|
@ -132,8 +132,9 @@ class HookManager {
|
||||||
}
|
}
|
||||||
if ($this->cardDav->getAddressBooksForUserCount($principal) === 0) {
|
if ($this->cardDav->getAddressBooksForUserCount($principal) === 0) {
|
||||||
try {
|
try {
|
||||||
$this->cardDav->createAddressBook($principal, 'contacts', [
|
$this->cardDav->createAddressBook($principal, CardDavBackend::PERSONAL_ADDRESSBOOK_URI, [
|
||||||
'{DAV:}displayname' => 'Contacts']);
|
'{DAV:}displayname' => CardDavBackend::PERSONAL_ADDRESSBOOK_NAME,
|
||||||
|
]);
|
||||||
} catch (\Exception $ex) {
|
} catch (\Exception $ex) {
|
||||||
\OC::$server->getLogger()->logException($ex);
|
\OC::$server->getLogger()->logException($ex);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue