1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-19 05:12:41 +01:00

Make notification counts properly translatable

Summary:
Ref T9132. When I've touched `PhabricatorApplication` I keep hitting this bad `pht()` junk.

The warning is correct, these strings are not extactable and can not be translated.

Fix it so they can be extracted and translated.

Broadly, in all cases we want to render one of these:

> 95 Things (for fewer than some limit)
> 99+ Things (when we hit the limit)

Test Plan: Looked at homepage status counts, moused over them, saw reasonable strings. Grepped for removed method.

Reviewers: chad

Reviewed By: chad

Subscribers: joshuaspence

Maniphest Tasks: T9132

Differential Revision: https://secure.phabricator.com/D14638
This commit is contained in:
epriestley 2015-12-02 11:35:24 -08:00
parent a1c7ba6b8b
commit 618cec23d8
10 changed files with 110 additions and 103 deletions

View file

@ -47,6 +47,7 @@ final class PhabricatorAuditApplication extends PhabricatorApplication {
public function loadStatus(PhabricatorUser $user) { public function loadStatus(PhabricatorUser $user) {
$status = array(); $status = array();
$limit = self::MAX_STATUS_ITEMS;
$phids = PhabricatorAuditCommentEditor::loadAuditPHIDsForUser($user); $phids = PhabricatorAuditCommentEditor::loadAuditPHIDsForUser($user);
@ -54,14 +55,16 @@ final class PhabricatorAuditApplication extends PhabricatorApplication {
->setViewer($user) ->setViewer($user)
->withAuthorPHIDs(array($user->getPHID())) ->withAuthorPHIDs(array($user->getPHID()))
->withAuditStatus(DiffusionCommitQuery::AUDIT_STATUS_CONCERN) ->withAuditStatus(DiffusionCommitQuery::AUDIT_STATUS_CONCERN)
->setLimit(self::MAX_STATUS_ITEMS); ->setLimit($limit);
$commits = $query->execute(); $commits = $query->execute();
$count = count($commits); $count = count($commits);
$count_str = self::formatStatusCount( if ($count >= $limit) {
$count, $count_str = pht('%s+ Problem Commit(s)', new PhutilNumber($limit - 1));
'%s Problem Commits', } else {
'%d Problem Commit(s)'); $count_str = pht('%s Problem Commit(s)', new PhutilNumber($count));
}
$type = PhabricatorApplicationStatusView::TYPE_NEEDS_ATTENTION; $type = PhabricatorApplicationStatusView::TYPE_NEEDS_ATTENTION;
$status[] = id(new PhabricatorApplicationStatusView()) $status[] = id(new PhabricatorApplicationStatusView())
->setType($type) ->setType($type)
@ -72,14 +75,16 @@ final class PhabricatorAuditApplication extends PhabricatorApplication {
->setViewer($user) ->setViewer($user)
->withNeedsAuditByPHIDs($phids) ->withNeedsAuditByPHIDs($phids)
->withAuditStatus(DiffusionCommitQuery::AUDIT_STATUS_OPEN) ->withAuditStatus(DiffusionCommitQuery::AUDIT_STATUS_OPEN)
->setLimit(self::MAX_STATUS_ITEMS); ->setLimit($limit);
$commits = $query->execute(); $commits = $query->execute();
$count = count($commits); $count = count($commits);
$count_str = self::formatStatusCount( if ($count >= $limit) {
$count, $count_str = pht('%s+ Problem Commit(s)', new PhutilNumber($limit - 1));
'%s Commits Awaiting Audit', } else {
'%d Commit(s) Awaiting Audit'); $count_str = pht('%s Problem Commit(s)', new PhutilNumber($count));
}
$type = PhabricatorApplicationStatusView::TYPE_WARNING; $type = PhabricatorApplicationStatusView::TYPE_WARNING;
$status[] = id(new PhabricatorApplicationStatusView()) $status[] = id(new PhabricatorApplicationStatusView())
->setType($type) ->setType($type)

View file

@ -288,22 +288,6 @@ abstract class PhabricatorApplication
return array(); return array();
} }
/**
* @return string
* @task ui
*/
final public static function formatStatusCount(
$count,
$limit_string = '%s',
$base_string = '%d') {
if ($count == self::MAX_STATUS_ITEMS) {
$count_str = pht($limit_string, ($count - 1).'+');
} else {
$count_str = pht($base_string, $count);
}
return $count_str;
}
/** /**
* You can provide an optional piece of flavor text for the application. This * You can provide an optional piece of flavor text for the application. This

View file

@ -104,21 +104,23 @@ final class PhabricatorDifferentialApplication extends PhabricatorApplication {
} }
public function loadStatus(PhabricatorUser $user) { public function loadStatus(PhabricatorUser $user) {
$limit = self::MAX_STATUS_ITEMS;
$revisions = id(new DifferentialRevisionQuery()) $revisions = id(new DifferentialRevisionQuery())
->setViewer($user) ->setViewer($user)
->withResponsibleUsers(array($user->getPHID())) ->withResponsibleUsers(array($user->getPHID()))
->withStatus(DifferentialRevisionQuery::STATUS_OPEN) ->withStatus(DifferentialRevisionQuery::STATUS_OPEN)
->needRelationships(true) ->needRelationships(true)
->setLimit(self::MAX_STATUS_ITEMS) ->setLimit($limit)
->execute(); ->execute();
$status = array(); $status = array();
if (count($revisions) == self::MAX_STATUS_ITEMS) { if (count($revisions) >= $limit) {
$all_count = count($revisions); $all_count = count($revisions);
$all_count_str = self::formatStatusCount( $all_count_str = pht(
$all_count, '%s+ Active Review(s)',
'%s Active Reviews', new PhutilNumber($limit - 1));
'%d Active Review(s)');
$type = PhabricatorApplicationStatusView::TYPE_WARNING; $type = PhabricatorApplicationStatusView::TYPE_WARNING;
$status[] = id(new PhabricatorApplicationStatusView()) $status[] = id(new PhabricatorApplicationStatusView())
->setType($type) ->setType($type)
@ -131,10 +133,10 @@ final class PhabricatorDifferentialApplication extends PhabricatorApplication {
array($user->getPHID())); array($user->getPHID()));
$blocking = count($blocking); $blocking = count($blocking);
$blocking_str = self::formatStatusCount( $blocking_str = pht(
$blocking, '%s Review(s) Blocking Others',
'%s Reviews Blocking Others', new PhutilNumber($blocking));
'%d Review(s) Blocking Others');
$type = PhabricatorApplicationStatusView::TYPE_NEEDS_ATTENTION; $type = PhabricatorApplicationStatusView::TYPE_NEEDS_ATTENTION;
$status[] = id(new PhabricatorApplicationStatusView()) $status[] = id(new PhabricatorApplicationStatusView())
->setType($type) ->setType($type)
@ -142,10 +144,10 @@ final class PhabricatorDifferentialApplication extends PhabricatorApplication {
->setCount($blocking); ->setCount($blocking);
$active = count($active); $active = count($active);
$active_str = self::formatStatusCount( $active_str = pht(
$active, '%s Review(s) Need Attention',
'%s Reviews Need Attention', new PhutilNumber($active));
'%d Review(s) Need Attention');
$type = PhabricatorApplicationStatusView::TYPE_WARNING; $type = PhabricatorApplicationStatusView::TYPE_WARNING;
$status[] = id(new PhabricatorApplicationStatusView()) $status[] = id(new PhabricatorApplicationStatusView())
->setType($type) ->setType($type)
@ -153,10 +155,10 @@ final class PhabricatorDifferentialApplication extends PhabricatorApplication {
->setCount($active); ->setCount($active);
$waiting = count($waiting); $waiting = count($waiting);
$waiting_str = self::formatStatusCount( $waiting_str = pht(
$waiting, '%s Review(s) Waiting on Others',
'%s Reviews Waiting on Others', new PhutilNumber($waiting));
'%d Review(s) Waiting on Others');
$type = PhabricatorApplicationStatusView::TYPE_INFO; $type = PhabricatorApplicationStatusView::TYPE_INFO;
$status[] = id(new PhabricatorApplicationStatusView()) $status[] = id(new PhabricatorApplicationStatusView())
->setType($type) ->setType($type)

View file

@ -34,6 +34,7 @@ final class PhabricatorFlagsApplication extends PhabricatorApplication {
public function loadStatus(PhabricatorUser $user) { public function loadStatus(PhabricatorUser $user) {
$status = array(); $status = array();
$limit = self::MAX_STATUS_ITEMS;
$flags = id(new PhabricatorFlagQuery()) $flags = id(new PhabricatorFlagQuery())
->setViewer($user) ->setViewer($user)
@ -42,10 +43,12 @@ final class PhabricatorFlagsApplication extends PhabricatorApplication {
->execute(); ->execute();
$count = count($flags); $count = count($flags);
$count_str = self::formatStatusCount( if ($count >= $limit) {
$count, $count_str = pht('%s+ Flagged Object(s)', new PhutilNumber($limit - 1));
'%s Flagged Objects', } else {
'%d Flagged Object(s)'); $count_str = pht('%s Flagged Object(s)', new PhutilNumber($count));
}
$type = PhabricatorApplicationStatusView::TYPE_WARNING; $type = PhabricatorApplicationStatusView::TYPE_WARNING;
$status[] = id(new PhabricatorApplicationStatusView()) $status[] = id(new PhabricatorApplicationStatusView())
->setType($type) ->setType($type)

View file

@ -80,16 +80,20 @@ final class PhabricatorManiphestApplication extends PhabricatorApplication {
return $status; return $status;
} }
$limit = self::MAX_STATUS_ITEMS;
$query = id(new ManiphestTaskQuery()) $query = id(new ManiphestTaskQuery())
->setViewer($user) ->setViewer($user)
->withStatuses(ManiphestTaskStatus::getOpenStatusConstants()) ->withStatuses(ManiphestTaskStatus::getOpenStatusConstants())
->withOwners(array($user->getPHID())) ->withOwners(array($user->getPHID()))
->setLimit(self::MAX_STATUS_ITEMS); ->setLimit($limit);
$count = count($query->execute()); $count = count($query->execute());
$count_str = self::formatStatusCount( if ($count >= $limit) {
$count, $count_str = pht('%s+ Assigned Task(s)', new PhutilNumber($limit - 1));
'%s Assigned Tasks', } else {
'%d Assigned Task(s)'); $count_str = pht('%s Assigned Task(s)', new PhutilNumber($count));
}
$type = PhabricatorApplicationStatusView::TYPE_WARNING; $type = PhabricatorApplicationStatusView::TYPE_WARNING;
$status[] = id(new PhabricatorApplicationStatusView()) $status[] = id(new PhabricatorApplicationStatusView())

View file

@ -72,7 +72,7 @@ final class PhabricatorApplicationLaunchView extends AphrontTagView {
array( array(
'class' => 'phabricator-application-attention-count', 'class' => 'phabricator-application-attention-count',
), ),
PhabricatorApplication::formatStatusCount($count)); $this->formatStatusItemCount($count));
} }
@ -82,8 +82,9 @@ final class PhabricatorApplicationLaunchView extends AphrontTagView {
array( array(
'class' => 'phabricator-application-warning-count', 'class' => 'phabricator-application-warning-count',
), ),
PhabricatorApplication::formatStatusCount($counts[$warning])); $this->formatStatusItemCount($counts[$warning]));
} }
if (nonempty($count1) && nonempty($count2)) { if (nonempty($count1) && nonempty($count2)) {
$numbers = array($count1, ' / ', $count2); $numbers = array($count1, ' / ', $count2);
} else { } else {
@ -132,4 +133,13 @@ final class PhabricatorApplicationLaunchView extends AphrontTagView {
); );
} }
private function formatStatusItemCount($count) {
$limit = PhabricatorApplication::MAX_STATUS_ITEMS;
if ($count >= $limit) {
return pht('%s+', new PhutilNumber($limit - 1));
} else {
return pht('%s', new PhutilNumber($count));
}
}
} }

View file

@ -95,14 +95,14 @@ final class PhabricatorPeopleApplication extends PhabricatorApplication {
if (!$user->getIsAdmin()) { if (!$user->getIsAdmin()) {
return array(); return array();
} }
$limit = self::MAX_STATUS_ITEMS;
$need_approval = id(new PhabricatorPeopleQuery()) $need_approval = id(new PhabricatorPeopleQuery())
->setViewer($user) ->setViewer($user)
->withIsApproved(false) ->withIsApproved(false)
->withIsDisabled(false) ->withIsDisabled(false)
->setLimit(self::MAX_STATUS_ITEMS) ->setLimit($limit)
->execute(); ->execute();
if (!$need_approval) { if (!$need_approval) {
return array(); return array();
} }
@ -110,10 +110,16 @@ final class PhabricatorPeopleApplication extends PhabricatorApplication {
$status = array(); $status = array();
$count = count($need_approval); $count = count($need_approval);
$count_str = self::formatStatusCount( if ($count >= $limit) {
$count, $count_str = pht(
'%s Users Need Approval', '%s+ User(s) Need Approval',
'%d User(s) Need Approval'); new PhutilNumber($limit - 1));
} else {
$count_str = pht(
'%s User(s) Need Approval',
new PhutilNumber($count));
}
$type = PhabricatorApplicationStatusView::TYPE_NEEDS_ATTENTION; $type = PhabricatorApplicationStatusView::TYPE_NEEDS_ATTENTION;
$status[] = id(new PhabricatorApplicationStatusView()) $status[] = id(new PhabricatorApplicationStatusView())
->setType($type) ->setType($type)

View file

@ -48,17 +48,18 @@ final class PhabricatorPhrequentApplication extends PhabricatorApplication {
public function loadStatus(PhabricatorUser $user) { public function loadStatus(PhabricatorUser $user) {
$status = array(); $status = array();
$limit = self::MAX_STATUS_ITEMS;
// Show number of objects that are currently // Show number of objects that are currently
// being tracked for a user. // being tracked for a user.
$count = PhrequentUserTimeQuery::getUserTotalObjectsTracked( $count = PhrequentUserTimeQuery::getUserTotalObjectsTracked($user, $limit);
$user, if ($count >= $limit) {
self::MAX_STATUS_ITEMS); $count_str = pht('%s+ Object(s) Tracked', new PhutilNumber($limit - 1));
$count_str = self::formatStatusCount( } else {
$count, $count_str = pht('%s Object(s) Tracked', new PhutilNumber($count));
'%s Objects Tracked', }
'%d Object(s) Tracked');
$type = PhabricatorApplicationStatusView::TYPE_NEEDS_ATTENTION; $type = PhabricatorApplicationStatusView::TYPE_NEEDS_ATTENTION;
$status[] = id(new PhabricatorApplicationStatusView()) $status[] = id(new PhabricatorApplicationStatusView())
->setType($type) ->setType($type)

View file

@ -28,14 +28,6 @@ final class PhabricatorPonderApplication extends PhabricatorApplication {
return "\xE2\x97\xB3"; return "\xE2\x97\xB3";
} }
public function loadStatus(PhabricatorUser $user) {
// Replace with "x new unanswered questions" or some such
// make sure to use `self::formatStatusCount` and friends...!
$status = array();
return $status;
}
public function getRemarkupRules() { public function getRemarkupRules() {
return array( return array(
new PonderRemarkupRule(), new PonderRemarkupRule(),

View file

@ -55,49 +55,49 @@ final class PhabricatorUSEnglishTranslation
'There are %d aggregate facts in storage.', 'There are %d aggregate facts in storage.',
), ),
'%d Commit(s) Awaiting Audit' => array( '%s Commit(s) Awaiting Audit' => array(
'%d Commit Awaiting Audit', '%s Commit Awaiting Audit',
'%d Commits Awaiting Audit', '%s Commits Awaiting Audit',
), ),
'%d Problem Commit(s)' => array( '%s Problem Commit(s)' => array(
'%d Problem Commit', '%s Problem Commit',
'%d Problem Commits', '%s Problem Commits',
), ),
'%d Review(s) Blocking Others' => array( '%s Review(s) Blocking Others' => array(
'%d Review Blocking Others', '%s Review Blocking Others',
'%d Reviews Blocking Others', '%s Reviews Blocking Others',
), ),
'%d Review(s) Need Attention' => array( '%s Review(s) Need Attention' => array(
'%d Review Needs Attention', '%s Review Needs Attention',
'%d Reviews Need Attention', '%s Reviews Need Attention',
), ),
'%d Review(s) Waiting on Others' => array( '%s Review(s) Waiting on Others' => array(
'%d Review Waiting on Others', '%s Review Waiting on Others',
'%d Reviews Waiting on Others', '%s Reviews Waiting on Others',
), ),
'%d Active Review(s)' => array( '%s Active Review(s)' => array(
'%d Active Review', '%s Active Review',
'%d Active Reviews', '%s Active Reviews',
), ),
'%d Flagged Object(s)' => array( '%s Flagged Object(s)' => array(
'%d Flagged Object', '%s Flagged Object',
'%d Flagged Objects', '%s Flagged Objects',
), ),
'%d Object(s) Tracked' => array( '%s Object(s) Tracked' => array(
'%d Object Tracked', '%s Object Tracked',
'%d Objects Tracked', '%s Objects Tracked',
), ),
'%d Assigned Task(s)' => array( '%s Assigned Task(s)' => array(
'%d Assigned Task', '%s Assigned Task',
'%d Assigned Tasks', '%s Assigned Tasks',
), ),
'Show %d Lint Message(s)' => array( 'Show %d Lint Message(s)' => array(