Use shorter text on the sidebar for files_sharing activities
This commit is contained in:
parent
f3864c5444
commit
17ab8e6c39
3 changed files with 69 additions and 5 deletions
|
@ -70,7 +70,8 @@ $eventDispatcher->addListener(
|
|||
\OC::$server->getActivityManager()->registerExtension(function() {
|
||||
return new \OCA\Files_Sharing\Activity(
|
||||
\OC::$server->query('L10NFactory'),
|
||||
\OC::$server->getURLGenerator()
|
||||
\OC::$server->getURLGenerator(),
|
||||
\OC::$server->getActivityManager()
|
||||
);
|
||||
});
|
||||
|
||||
|
|
|
@ -24,6 +24,8 @@
|
|||
namespace OCA\Files_Sharing;
|
||||
|
||||
use OCP\Activity\IExtension;
|
||||
use OCP\Activity\IManager;
|
||||
use OCP\IL10N;
|
||||
use OCP\IURLGenerator;
|
||||
use OCP\L10N\IFactory;
|
||||
|
||||
|
@ -67,13 +69,18 @@ class Activity implements IExtension {
|
|||
/** @var IURLGenerator */
|
||||
protected $URLGenerator;
|
||||
|
||||
/** @var IManager */
|
||||
protected $activityManager;
|
||||
|
||||
/**
|
||||
* @param IFactory $languageFactory
|
||||
* @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->URLGenerator = $URLGenerator;
|
||||
$this->activityManager = $activityManager;
|
||||
}
|
||||
|
||||
protected function getL10N($languageCode = null) {
|
||||
|
@ -149,9 +156,30 @@ class Activity implements IExtension {
|
|||
* @return string|false
|
||||
*/
|
||||
public function translate($app, $text, $params, $stripPath, $highlightParams, $languageCode) {
|
||||
if ($app !== self::FILES_SHARING_APP) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$l = $this->getL10N($languageCode);
|
||||
|
||||
if ($app === self::FILES_SHARING_APP) {
|
||||
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) {
|
||||
case self::SUBJECT_REMOTE_SHARE_RECEIVED:
|
||||
if (sizeof($params) === 2) {
|
||||
|
@ -186,11 +214,43 @@ class Activity implements IExtension {
|
|||
case self::SUBJECT_SHARED_EMAIL:
|
||||
return (string) $l->t('You shared %1$s with %2$s', $params);
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
*
|
||||
|
|
|
@ -36,7 +36,10 @@ class Activity extends \OCA\Files_Sharing\Tests\TestCase{
|
|||
parent::setUp();
|
||||
$this->activity = new \OCA\Files_Sharing\Activity(
|
||||
$this->getMock('\OC\L10N\Factory'),
|
||||
$this->getMockBuilder('\OC\URLGenerator')
|
||||
$this->getMockBuilder('\OCP\IURLGenerator')
|
||||
->disableOriginalConstructor()
|
||||
->getMock(),
|
||||
$this->getMockBuilder('\OCP\Activity\IManager')
|
||||
->disableOriginalConstructor()
|
||||
->getMock()
|
||||
);
|
||||
|
|
Loading…
Reference in a new issue