Merge pull request #19522 from owncloud/activity-395-less-sidebar-text

Activity 395 less sidebar text
This commit is contained in:
Thomas Müller 2015-10-02 12:13:53 +02:00
Родитель daf9a63d43 e478d925c3
Коммит ccbdcf0ab3
6 изменённых файлов: 176 добавлений и 37 удалений

Просмотреть файл

@ -145,6 +145,24 @@ class Activity implements IExtension {
} }
$l = $this->getL10N($languageCode); $l = $this->getL10N($languageCode);
if ($this->activityManager->isFormattingFilteredObject()) {
$translation = $this->translateShort($text, $l, $params);
if ($translation !== false) {
return $translation;
}
}
return $this->translateLong($text, $l, $params);
}
/**
* @param string $text
* @param IL10N $l
* @param array $params
* @return bool|string
*/
protected function translateLong($text, IL10N $l, array $params) {
switch ($text) { switch ($text) {
case 'created_self': case 'created_self':
return (string) $l->t('You created %1$s', $params); return (string) $l->t('You created %1$s', $params);
@ -170,6 +188,26 @@ class Activity implements IExtension {
} }
} }
/**
* @param string $text
* @param IL10N $l
* @param array $params
* @return bool|string
*/
protected function translateShort($text, IL10N $l, array $params) {
switch ($text) {
case 'changed_by':
return (string) $l->t('Changed by %2$s', $params);
case 'deleted_by':
return (string) $l->t('Deleted by %2$s', $params);
case 'restored_by':
return (string) $l->t('Restored by %2$s', $params);
default:
return false;
}
}
/** /**
* The extension can define the type of parameters for translation * The extension can define the type of parameters for translation
* *

Просмотреть файл

@ -70,7 +70,8 @@ $eventDispatcher->addListener(
\OC::$server->getActivityManager()->registerExtension(function() { \OC::$server->getActivityManager()->registerExtension(function() {
return new \OCA\Files_Sharing\Activity( return new \OCA\Files_Sharing\Activity(
\OC::$server->query('L10NFactory'), \OC::$server->query('L10NFactory'),
\OC::$server->getURLGenerator() \OC::$server->getURLGenerator(),
\OC::$server->getActivityManager()
); );
}); });

Просмотреть файл

@ -24,6 +24,8 @@
namespace OCA\Files_Sharing; namespace OCA\Files_Sharing;
use OCP\Activity\IExtension; use OCP\Activity\IExtension;
use OCP\Activity\IManager;
use OCP\IL10N;
use OCP\IURLGenerator; use OCP\IURLGenerator;
use OCP\L10N\IFactory; use OCP\L10N\IFactory;
@ -67,13 +69,18 @@ class Activity implements IExtension {
/** @var IURLGenerator */ /** @var IURLGenerator */
protected $URLGenerator; protected $URLGenerator;
/** @var IManager */
protected $activityManager;
/** /**
* @param IFactory $languageFactory * @param IFactory $languageFactory
* @param IURLGenerator $URLGenerator * @param IURLGenerator $URLGenerator
* @param IManager $activityManager
*/ */
public function __construct(IFactory $languageFactory, IURLGenerator $URLGenerator) { public function __construct(IFactory $languageFactory, IURLGenerator $URLGenerator, IManager $activityManager) {
$this->languageFactory = $languageFactory; $this->languageFactory = $languageFactory;
$this->URLGenerator = $URLGenerator; $this->URLGenerator = $URLGenerator;
$this->activityManager = $activityManager;
} }
protected function getL10N($languageCode = null) { protected function getL10N($languageCode = null) {
@ -149,48 +156,101 @@ class Activity implements IExtension {
* @return string|false * @return string|false
*/ */
public function translate($app, $text, $params, $stripPath, $highlightParams, $languageCode) { public function translate($app, $text, $params, $stripPath, $highlightParams, $languageCode) {
if ($app !== self::FILES_SHARING_APP) {
return false;
}
$l = $this->getL10N($languageCode); $l = $this->getL10N($languageCode);
if ($app === self::FILES_SHARING_APP) { if ($this->activityManager->isFormattingFilteredObject()) {
switch ($text) { $translation = $this->translateShort($text, $l, $params);
case self::SUBJECT_REMOTE_SHARE_RECEIVED: if ($translation !== false) {
if (sizeof($params) === 2) { return $translation;
// New activity ownCloud 8.2+
return (string) $l->t('You received a new remote share %2$s from %1$s', $params);
}
return (string) $l->t('You received a new remote share from %s', $params);
case self::SUBJECT_REMOTE_SHARE_ACCEPTED:
return (string) $l->t('%1$s accepted remote share %2$s', $params);
case self::SUBJECT_REMOTE_SHARE_DECLINED:
return (string) $l->t('%1$s declined remote share %2$s', $params);
case self::SUBJECT_REMOTE_SHARE_UNSHARED:
return (string) $l->t('%1$s unshared %2$s from you', $params);
case self::SUBJECT_PUBLIC_SHARED_FOLDER_DOWNLOADED:
return (string) $l->t('Public shared folder %1$s was downloaded', $params);
case self::SUBJECT_PUBLIC_SHARED_FILE_DOWNLOADED:
return (string) $l->t('Public shared file %1$s was downloaded', $params);
case self::SUBJECT_SHARED_USER_SELF:
return (string) $l->t('You shared %1$s with %2$s', $params);
case self::SUBJECT_SHARED_GROUP_SELF:
return (string) $l->t('You shared %1$s with group %2$s', $params);
case self::SUBJECT_RESHARED_USER_BY:
return (string) $l->t('%2$s shared %1$s with %3$s', $params);
case self::SUBJECT_RESHARED_GROUP_BY:
return (string) $l->t('%2$s shared %1$s with group %3$s', $params);
case self::SUBJECT_RESHARED_LINK_BY:
return (string) $l->t('%2$s shared %1$s via link', $params);
case self::SUBJECT_SHARED_WITH_BY:
return (string) $l->t('%2$s shared %1$s with you', $params);
case self::SUBJECT_SHARED_LINK_SELF:
return (string) $l->t('You shared %1$s via link', $params);
case self::SUBJECT_SHARED_EMAIL:
return (string) $l->t('You shared %1$s with %2$s', $params);
} }
} }
return $this->translateLong($text, $l, $params);
}
/**
* @param string $text
* @param IL10N $l
* @param array $params
* @return bool|string
*/
protected function translateLong($text, IL10N $l, array $params) {
switch ($text) {
case self::SUBJECT_REMOTE_SHARE_RECEIVED:
if (sizeof($params) === 2) {
// New activity ownCloud 8.2+
return (string) $l->t('You received a new remote share %2$s from %1$s', $params);
}
return (string) $l->t('You received a new remote share from %s', $params);
case self::SUBJECT_REMOTE_SHARE_ACCEPTED:
return (string) $l->t('%1$s accepted remote share %2$s', $params);
case self::SUBJECT_REMOTE_SHARE_DECLINED:
return (string) $l->t('%1$s declined remote share %2$s', $params);
case self::SUBJECT_REMOTE_SHARE_UNSHARED:
return (string) $l->t('%1$s unshared %2$s from you', $params);
case self::SUBJECT_PUBLIC_SHARED_FOLDER_DOWNLOADED:
return (string) $l->t('Public shared folder %1$s was downloaded', $params);
case self::SUBJECT_PUBLIC_SHARED_FILE_DOWNLOADED:
return (string) $l->t('Public shared file %1$s was downloaded', $params);
case self::SUBJECT_SHARED_USER_SELF:
return (string) $l->t('You shared %1$s with %2$s', $params);
case self::SUBJECT_SHARED_GROUP_SELF:
return (string) $l->t('You shared %1$s with group %2$s', $params);
case self::SUBJECT_RESHARED_USER_BY:
return (string) $l->t('%2$s shared %1$s with %3$s', $params);
case self::SUBJECT_RESHARED_GROUP_BY:
return (string) $l->t('%2$s shared %1$s with group %3$s', $params);
case self::SUBJECT_RESHARED_LINK_BY:
return (string) $l->t('%2$s shared %1$s via link', $params);
case self::SUBJECT_SHARED_WITH_BY:
return (string) $l->t('%2$s shared %1$s with you', $params);
case self::SUBJECT_SHARED_LINK_SELF:
return (string) $l->t('You shared %1$s via link', $params);
case self::SUBJECT_SHARED_EMAIL:
return (string) $l->t('You shared %1$s with %2$s', $params);
}
return false; return false;
} }
/**
* @param string $text
* @param IL10N $l
* @param array $params
* @return bool|string
*/
protected function translateShort($text, IL10N $l, array $params) {
switch ($text) {
case self::SUBJECT_PUBLIC_SHARED_FOLDER_DOWNLOADED:
case self::SUBJECT_PUBLIC_SHARED_FILE_DOWNLOADED:
return (string) $l->t('Downloaded via public link');
case self::SUBJECT_SHARED_USER_SELF:
return (string) $l->t('Shared with %2$s', $params);
case self::SUBJECT_SHARED_GROUP_SELF:
return (string) $l->t('Shared with group %2$s', $params);
case self::SUBJECT_RESHARED_USER_BY:
return (string) $l->t('Shared with %3$s by %2$s', $params);
case self::SUBJECT_RESHARED_GROUP_BY:
return (string) $l->t('Shared with group %3$s by %2$s', $params);
case self::SUBJECT_RESHARED_LINK_BY:
return (string) $l->t('Shared via link by %2$s', $params);
case self::SUBJECT_SHARED_WITH_BY:
return (string) $l->t('Shared by %2$s', $params);
case self::SUBJECT_SHARED_LINK_SELF:
return (string) $l->t('Shared via public link');
case self::SUBJECT_SHARED_EMAIL:
return (string) $l->t('Shared with %2$s', $params);
default:
return false;
}
}
/** /**
* The extension can define the type of parameters for translation * The extension can define the type of parameters for translation
* *

Просмотреть файл

@ -36,7 +36,10 @@ class Activity extends \OCA\Files_Sharing\Tests\TestCase{
parent::setUp(); parent::setUp();
$this->activity = new \OCA\Files_Sharing\Activity( $this->activity = new \OCA\Files_Sharing\Activity(
$this->getMock('\OC\L10N\Factory'), $this->getMock('\OC\L10N\Factory'),
$this->getMockBuilder('\OC\URLGenerator') $this->getMockBuilder('\OCP\IURLGenerator')
->disableOriginalConstructor()
->getMock(),
$this->getMockBuilder('\OCP\Activity\IManager')
->disableOriginalConstructor() ->disableOriginalConstructor()
->getMock() ->getMock()
); );

Просмотреть файл

@ -44,6 +44,12 @@ class ActivityManager implements IManager {
/** @var IConfig */ /** @var IConfig */
protected $config; protected $config;
/** @var string */
protected $formattingObjectType;
/** @var int */
protected $formattingObjectId;
/** /**
* constructor of the controller * constructor of the controller
* *
@ -303,6 +309,24 @@ class ActivityManager implements IManager {
return ''; return '';
} }
/**
* @param string $type
* @param int $id
*/
public function setFormattingObject($type, $id) {
$this->formattingObjectType = $type;
$this->formattingObjectId = $id;
}
/**
* @return bool
*/
public function isFormattingFilteredObject() {
return 'filter' === $this->request->getParam('filter')
&& $this->formattingObjectType === $this->request->getParam('objecttype')
&& $this->formattingObjectId === $this->request->getParam('objectid');
}
/** /**
* @param string $app * @param string $app
* @param string $text * @param string $text

Просмотреть файл

@ -137,6 +137,19 @@ interface IManager {
*/ */
public function getTypeIcon($type); public function getTypeIcon($type);
/**
* @param string $type
* @param int $id
* @since 8.2.0
*/
public function setFormattingObject($type, $id);
/**
* @return bool
* @since 8.2.0
*/
public function isFormattingFilteredObject();
/** /**
* @param string $app * @param string $app
* @param string $text * @param string $text