Beispiel #1
0
 /**
  * Localize given statement
  *
  * @param string      $str  Statement to translate
  * @param array|mixed $args Array or any number of sprintf-like arguments
  *
  * @return string translated statement
  */
 static function tr($str, $args = null)
 {
     if (empty($str)) {
         return "";
     }
     $str = trim($str);
     // Defined and not empty
     if (self::$localize) {
         list($_prefix, $_rest) = CAppUI::splitLocale($str);
         $_lang_prefix = self::$lang . $_prefix;
         // Not in self::$locales cache
         if (empty(self::$locales_loaded[$_lang_prefix])) {
             $shared_name = "locales-" . self::$lang . "-" . $_prefix;
             if (SHM::exists($shared_name)) {
                 $_loc = SHM::get($shared_name);
                 if (empty(self::$locales[$_prefix])) {
                     self::$locales[$_prefix] = $_loc;
                 } else {
                     self::$locales[$_prefix] = array_merge(self::$locales[$_prefix], $_loc);
                 }
             }
             self::$locales_loaded[$_lang_prefix] = true;
         }
         // dereferecing makes the systme a lots slower ! :(
         //$by_prefix = array_key_exists($_prefix, self::$locales) ? self::$locales[$_prefix] : null;
         //$by_prefix = self::$locales[$_prefix];
         if (isset(self::$locales[$_prefix][$_rest]) && self::$locales[$_prefix][$_rest] !== "") {
             $str = self::$locales[$_prefix][$_rest];
         } elseif (self::$lang) {
             if (!in_array($str, self::$unlocalized) && !preg_match(self::$localize_ignore, $str)) {
                 self::$unlocalized[] = $str;
             }
             // ... and decorate
             if (self::$locale_mask) {
                 $str = sprintf(self::$locale_mask, $str);
             }
         }
     }
     if ($args !== null) {
         if (!is_array($args)) {
             $args = func_get_args();
             unset($args[0]);
         }
         if ($args) {
             $str = vsprintf($str, $args);
         }
     }
     return nl2br($str);
 }