diff --git a/src/applications/base/controller/PhabricatorController.php b/src/applications/base/controller/PhabricatorController.php --- a/src/applications/base/controller/PhabricatorController.php +++ b/src/applications/base/controller/PhabricatorController.php @@ -102,7 +102,7 @@ $translation = newv($translation, array()); PhutilTranslator::getInstance() ->setLanguage($translation->getLanguage()) - ->addTranslations($translation->getTranslations()); + ->addTranslations($translation->getCleanTranslations()); } $preferences = $user->loadPreferences(); diff --git a/src/infrastructure/env/PhabricatorEnv.php b/src/infrastructure/env/PhabricatorEnv.php --- a/src/infrastructure/env/PhabricatorEnv.php +++ b/src/infrastructure/env/PhabricatorEnv.php @@ -117,7 +117,7 @@ $translation = PhabricatorEnv::newObjectFromConfig('translation.provider'); PhutilTranslator::getInstance() ->setLanguage($translation->getLanguage()) - ->addTranslations($translation->getTranslations()); + ->addTranslations($translation->getCleanTranslations()); } private static function buildConfigurationSourceStack() { diff --git a/src/infrastructure/internationalization/translation/PhabricatorTranslation.php b/src/infrastructure/internationalization/translation/PhabricatorTranslation.php --- a/src/infrastructure/internationalization/translation/PhabricatorTranslation.php +++ b/src/infrastructure/internationalization/translation/PhabricatorTranslation.php @@ -6,4 +6,32 @@ abstract public function getName(); abstract public function getTranslations(); + + /** + * Return the cleaned translation array. + * + * @return dict<string, wild> Translation map with empty translations removed. + */ + public function getCleanTranslations() { + return $this->clean($this->getTranslations()); + } + + + /** + * Removes NULL-valued translation keys from the translation map, to prevent + * echoing out empty strings. + * + * @param dict<string, wild> Translation map, with empty translations. + * @return dict<string, wild> Map with empty translations removed. + */ + protected function clean(array $translation_array) { + foreach ($translation_array as $key => $translation_string) { + if ($translation_string === null) { + unset($translation_array[$key]); + } + } + + return $translation_array; + } + }