Page MenuHomePhabricator

D11121.diff
No OneTemporary

D11121.diff

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;
+ }
+
}

File Metadata

Mime Type
text/plain
Expires
Sat, Oct 26, 4:43 AM (3 w, 2 d ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6745363
Default Alt Text
D11121.diff (2 KB)

Event Timeline