diff --git a/src/internationalization/PhutilTranslator.php b/src/internationalization/PhutilTranslator.php --- a/src/internationalization/PhutilTranslator.php +++ b/src/internationalization/PhutilTranslator.php @@ -7,6 +7,7 @@ private $locale; private $localeCode; private $shouldPostProcess; + private $willTranslateCallback; private $translations = array(); public static function getInstance() { @@ -27,10 +28,19 @@ return $this; } + public function setWillTranslateCallback($callback) { + $this->willTranslateCallback = $callback; + return $this; + } + + public function getWillTranslateCallback() { + return $this->willTranslateCallback; + } + /** * Add translations which will be later used by @{method:translate}. * The parameter is an array of strings (for simple translations) or arrays - * (for translastions with variants). The number of items in the array is + * (for translations with variants). The number of items in the array is * language specific. It is `array($singular, $plural)` for English. * * array( @@ -63,14 +73,18 @@ } public function translate($text /* , ... */) { + $args = func_get_args(); + + if ($this->willTranslateCallback) { + call_user_func_array($this->willTranslateCallback, $args); + } + if (isset($this->translations[$text])) { $translation = $this->translations[$text]; } else { $translation = $text; } - $args = func_get_args(); - while (is_array($translation)) { $arg = next($args); $translation = $this->chooseVariant($translation, $arg);