Page MenuHomePhabricator

Badge translation error
Closed, ResolvedPublic

Description

Seeing this in my sandbox currently. Investigating.

Object of class PhutilSafeHTML could not be converted to int
Stack trace:
PhutilTranslator::chooseVariant called at [/Users/familyroom/Sites/libphutil/src/internationalization/PhutilTranslator.php:69]
PhutilTranslator::translate
call_user_func_array called at [/Users/familyroom/Sites/libphutil/src/internationalization/pht.php:17]
pht called at [/Users/familyroom/Sites/phabricator/src/applications/badges/storage/PhabricatorBadgesTransaction.php:227]
PhabricatorBadgesTransaction::getTitleForFeed called at [/Users/familyroom/Sites/phabricator/src/applications/transactions/feed/PhabricatorApplicationTransactionFeedStory.php:90]
PhabricatorApplicationTransactionFeedStory::renderView called at [/Users/familyroom/Sites/phabricator/src/applications/feed/builder/PhabricatorFeedBuilder.php:62]
PhabricatorFeedBuilder::buildView called at [/Users/familyroom/Sites/phabricator/src/applications/people/controller/PhabricatorPeopleProfileViewController.php:257]
PhabricatorPeopleProfileViewController::buildPeopleFeed called at [/Users/familyroom/Sites/phabricator/src/applications/people/controller/PhabricatorPeopleProfileViewController.php:54]
PhabricatorPeopleProfileViewController::handleRequest called at [/Users/familyroom/Sites/phabricator/src/aphront/configuration/AphrontApplicationConfiguration.php:237]
AphrontApplicationConfiguration::processRequest called at [/Users/familyroom/Sites/phabricator/src/aphront/configuration/AphrontApplicationConfiguration.php:149]
AphrontApplicationConfiguration::runHTTPRequest called at [/Users/familyroom/Sites/phabricator/webroot/index.php:17]

Event Timeline

D15544 (changing %s to %d) shouldn't be the fix for this -- %s is correct, because we want to render "1,234,567" if the number is large:

https://secure.phabricator.com/book/phabcontrib/article/internationalization/#using-phutilnumber

Let me see what's going on here.

Oh, I believe the actual issue is that the translations are variant on the wrong parameter. I think this is the correct fix (adding an extra array()):

diff --git a/src/infrastructure/internationalization/translation/PhabricatorUSEnglishTranslation.php b/src/infrastructure/internationalization/translation/PhabricatorUSEnglishTranslation.php
index 492d68d..2b7d48c 100644
--- a/src/infrastructure/internationalization/translation/PhabricatorUSEnglishTranslation.php
+++ b/src/infrastructure/internationalization/translation/PhabricatorUSEnglishTranslation.php
@@ -1545,16 +1545,20 @@ final class PhabricatorUSEnglishTranslation
 
       '%s awarded %s to %s recipient(s): %s.' => array(
         array(
-          '%s awarded %s to recipient: %4$s.',
-          '%s awarded %s to recipients: %4$s.',
-        ),
+          array(
+            '%s awarded %s to recipient: %4$s.',
+            '%s awarded %s to recipients: %4$s.',
+          ),
+        )
       ),
 
       '%s revoked %s from %s recipient(s): %s.' => array(
         array(
-          '%s revoked %s from recipient: %4$s.',
-          '%s revoked %s from recipients: %4$s.',
-        ),
+          array(
+            '%s revoked %s from recipient: %4$s.',
+            '%s revoked %s from recipients: %4$s.',
+          ),
+        )
       ),
     );
   }

I'll see if I can improve the error handling.

D15545 should fix the infrastructure part of this, and make this error more clear by returning an explicit diagnostic error rather than a mostly-working string and a log.

We should also fix the translation data part of this: these translations should be corrected in the translation data file so they vary on the correct parameter.

I think these steps should reproduce the issue:

  • Update libphutil.
  • Change language to "English (US)" if not already set to that.
  • View feed stories about badge awards.

At HEAD, stories with a data issue should render obviously:

Prior to D15545, these same steps reproduced the issue, except that it wasn't nearly as obvious that there was an issue, since the error got handled pretty quietly. You had to have DarkConsole set up and/or be looking at the error log.