Merge pull request #1144 from nextcloud/translate-default-calendar

translate default calendar & default address book displaynames & add …
This commit is contained in:
Morris Jobke 2016-10-06 23:00:26 +02:00 committed by GitHub
commit 6278d3bbfd
13 changed files with 97 additions and 20 deletions

0
apps/dav/l10n/.gitkeep Normal file
View file

View file

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

View file

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

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

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

View file

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

View file

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

View file

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

View file

@ -26,6 +26,12 @@ source_file = templates/lib.pot
source_lang = en
type = PO
[nextcloud.dav]
file_filter = <lang>/dav.po
source_file = templates/dav.pot
source_lang = en
type = PO
[nextcloud.files_encryption]
file_filter = <lang>/encryption.po
source_file = templates/encryption.pot