예제 #1
0
 /**
  * Do string translation.
  *
  * @param string  $string     the string to translate.
  * @param array   $args       a list of string to substitute.
  * @param string  $catalogue  get the translation from a particular message catalogue.
  * @return string translated string.
  */
 protected function formatString($string, $args = array(), $catalogue = null)
 {
     if (empty($args)) {
         $args = array();
     }
     if (empty($catalogue)) {
         $catalogue = empty($this->catalogue) ? 'messages' : $this->catalogue;
     }
     $this->loadCatalogue($catalogue);
     foreach ($this->messages[$catalogue] as $variant) {
         // we found it, so return the target translation
         if (isset($variant[$string])) {
             $target = $variant[$string];
             // check if it contains only strings.
             if (is_array($target)) {
                 $target = array_shift($target);
             }
             // found, but untranslated
             if (empty($target)) {
                 return $this->postscript[0] . $this->replaceArgs($string, $args) . $this->postscript[1];
             }
             return $this->replaceArgs($target, $args);
         }
     }
     // well we did not find the translation string.
     $this->source->append($string);
     return $this->postscript[0] . $this->replaceArgs($string, $args) . $this->postscript[1];
 }
예제 #2
0
 /**
  * Do string translation.
  *
  * @param string the string to translate.
  * @param array a list of string to substitute.
  * @param string get the translation from a particular message catalogue.
  * @return string translated string.
  */
 protected function formatString($string, $args = array(), $catalogue = null)
 {
     if (empty($args)) {
         $args = array();
     }
     $target = $this->getFormattedString($string, $args, $catalogue);
     // well we did not find the translation string.
     if (!$target) {
         $this->source->append($string);
         $target = $this->postscript[0] . $this->replaceArgs($string, $args) . $this->postscript[1];
     }
     return $target;
 }