Page MenuHomePhabricator

D16821.diff
No OneTemporary

D16821.diff

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);

File Metadata

Mime Type
text/plain
Expires
Fri, May 10, 4:41 AM (2 w, 4 d ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6281595
Default Alt Text
D16821.diff (1 KB)

Event Timeline