mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-22 21:40:55 +01:00
Allow PhutilTranslator::translate() to return defaults
Summary: Allow PhutilTranslator::translate() to return defaults Test Plan: Just check some strings returned correctly. Reviewers: epriestley, #blessed_reviewers Reviewed By: epriestley, #blessed_reviewers Subscribers: Korvin, Zolli, epriestley Projects: #localization Maniphest Tasks: T6845 Differential Revision: https://secure.phabricator.com/D11121
This commit is contained in:
parent
f33e2de092
commit
19845395d8
3 changed files with 30 additions and 2 deletions
|
@ -102,7 +102,7 @@ abstract class PhabricatorController extends AphrontController {
|
|||
$translation = newv($translation, array());
|
||||
PhutilTranslator::getInstance()
|
||||
->setLanguage($translation->getLanguage())
|
||||
->addTranslations($translation->getTranslations());
|
||||
->addTranslations($translation->getCleanTranslations());
|
||||
}
|
||||
|
||||
$preferences = $user->loadPreferences();
|
||||
|
|
2
src/infrastructure/env/PhabricatorEnv.php
vendored
2
src/infrastructure/env/PhabricatorEnv.php
vendored
|
@ -117,7 +117,7 @@ final class PhabricatorEnv {
|
|||
$translation = PhabricatorEnv::newObjectFromConfig('translation.provider');
|
||||
PhutilTranslator::getInstance()
|
||||
->setLanguage($translation->getLanguage())
|
||||
->addTranslations($translation->getTranslations());
|
||||
->addTranslations($translation->getCleanTranslations());
|
||||
}
|
||||
|
||||
private static function buildConfigurationSourceStack() {
|
||||
|
|
|
@ -6,4 +6,32 @@ abstract class PhabricatorTranslation {
|
|||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue