示例#1
0
 /** Fill the places Holder withs vars */
 private static function fill($text, $vars)
 {
     if ($vars != null and !empty($vars)) {
         $hFormater = msgfmt_create('fr_FR', $text);
         $text = msgfmt_format($hFormater, $vars);
     }
     return $text;
 }
示例#2
0
 private function format($key, $params)
 {
     if ($this->translations[$key] == '') {
         return '';
     }
     $fmt = msgfmt_create($this->locale, $this->translations[$key]);
     if (!$fmt) {
         throw new \Exception('msgfmt_create() failed');
     }
     $result = msgfmt_format($fmt, $params);
     if (false === $result) {
         throw new \Exception('msgfmt_format() failed: ' . msgfmt_get_error_message($fmt) . ' (' . msgfmt_get_error_code($fmt) . ')');
     }
     return $result;
 }
 protected function parse($str, $args, $locale)
 {
     if (empty($str)) {
         return "";
     }
     // This is one of those weird ICU formatting standard things.
     $msg = msgfmt_create($locale, $str);
     $output = msgfmt_format($msg, $args);
     return $output;
 }
示例#4
0
文件: i18n.php 项目: seyyah/f3kayOLD
 /**
 		Template directive handler
 			@param $_tree DOMDocument
 			@public
 	**/
 public static function locale($_tree)
 {
     $_node =& $_tree->nodeptr;
     foreach ($_node->attributes as $_attr) {
         $_vars[$_attr->name] = $_attr->value;
     }
     $_vars = is_array($_vars) ? array_map('F3::resolve', $_vars) : array();
     if (!count(self::$dict)) {
         // Load default dictionary
         self::loadDict();
     }
     $_msg = msgfmt_create(self::getDefault(), self::$dict[$_node->nodeValue]);
     $_block = $_msg ? F3::xmlEncode($_msg->format($_vars), TRUE) : '';
     $_len = strlen($_block);
     if ($_len) {
         $_tree->fragment->appendXML($_block);
         // Insert fragment before current node
         $_node->parentNode->insertBefore($_tree->fragment, $_node);
     }
 }