Exemple #1
0
/**
 * Smarty block function, provides gettext support for smarty.
 *
 * The block content is the text that should be translated.
 *
 * Any parameter that is sent to the function will be represented as %n in the translation text,
 * where n is 1 for the first parameter. The following parameters are reserved:
 *   - escape - sets escape mode:
 *       - 'html' for HTML escaping, this is the default.
 *       - 'js' for javascript escaping.
 *       - 'url' for url escaping.
 *       - 'no'/'off'/0 - turns off escaping
 *   - plural - The plural version of the text (2nd parameter of ngettext())
 *   - count - The item count for plural mode (3rd parameter of ngettext())
 */
function smarty_block_t($params, $text, &$smarty)
{
    if (!$text) {
        return;
    }
    $text = stripslashes($text);
    // set escape mode
    if (isset($params['escape'])) {
        $escape = $params['escape'];
        unset($params['escape']);
    }
    // set plural version
    if (isset($params['plural'])) {
        $plural = $params['plural'];
        unset($params['plural']);
        // set count
        if (isset($params['count'])) {
            $count = $params['count'];
            unset($params['count']);
        }
    }
    // use plural if required parameters are set
    if (isset($count) && isset($plural)) {
        $text = T_ngettext($text, $plural, $count);
    } else {
        // use normal
        $text = T_gettext($text);
    }
    // run strarg if there are parameters
    if (count($params)) {
        $text = smarty_gettext_strarg($text, $params);
    }
    if (!isset($escape) || $escape == 'html') {
        // html escape, default
        $text = nl2br(htmlspecialchars($text));
    } elseif (isset($escape)) {
        switch ($escape) {
            case 'javascript':
            case 'js':
                // javascript escape
                $text = str_replace('\'', '\\\'', stripslashes($text));
                break;
            case 'url':
                // url escape
                $text = urlencode($text);
                break;
        }
    }
    return $text;
}
Exemple #2
0
 /**
  * Gets the text of an id
  *
  * @param	String	String to be localized
  * @return	String	Localized String
  * @author 	Lars Michelsen <*****@*****.**>
  */
 private function getTextOfId($s)
 {
     return T_gettext($s);
 }
function setTranslation($string)
{
    return preg_replace_callback('/_e\\("([^\\"\\"]+)"\\)/', function ($m) {
        return '_e("' . addslashes(removeNewLines(T_gettext(stripslashes($m[1])))) . '")';
    }, $string);
}
Exemple #4
0
/**
 * Smarty block function, provides gettext support for smarty.
 *
 * The block content is the text that should be translated.
 *
 * Any parameter that is sent to the function will be represented as %n in the translation text,
 * where n is 1 for the first parameter. The following parameters are reserved:
 *   - escape - sets escape mode:
 *       - 'html' for HTML escaping, this is the default.
 *       - 'js' for javascript escaping.
 *       - 'url' for url escaping.
 *       - 'no'/'off'/0 - turns off escaping
 *   - plural - The plural version of the text (2nd parameter of ngettext())
 *   - count - The item count for plural mode (3rd parameter of ngettext())
 */
function smarty_block_t($params, $text, $smarty)
{
    // stop smarty from rendering on the opening tag
    if (!$text) {
        return;
    }
    $text = stripslashes($text);
    // set escape mode
    if ($params['escape'] !== null) {
        $escape = $params['escape'];
        unset($params['escape']);
    }
    // set plural version
    if ($params['plural'] !== null) {
        $plural = $params['plural'];
        unset($params['plural']);
        // set count
        if ($params['count'] !== null) {
            $count = $params['count'];
            unset($params['count']);
        }
    }
    // use plural if required parameters are set
    if ($count !== null and $plural !== null) {
        $text = T_ngettext($text, $plural, $count);
        // vain: prefixed "T_" for usage of php-gettext
    } else {
        // use normal
        $text = T_gettext($text);
        // vain: prefixed "T_" for usage of php-gettext
    }
    // run strarg if there are parameters
    if (count($params)) {
        $text = smarty_gettext_strarg($text, $params);
    }
    if (false === isset($escape) or $escape == 'html') {
        // html escape, default
        $text = nl2br(htmlspecialchars($text));
    } elseif ($escape !== null) {
        switch ($escape) {
            case 'javascript':
            case 'js':
                // javascript escape
                $text = str_replace('\'', '\\\'', stripslashes($text));
                break;
            case 'url':
                // url escape
                $text = urlencode($text);
                break;
        }
    }
    if ($text !== null) {
        return $text;
    }
}
/**
 * Smarty block function, provides gettext support for smarty.
 *
 * The block content is the text that should be translated.
 *
 * Any parameter that is sent to the function will be represented as %n in the translation text, 
 * where n is 1 for the first parameter. The following parameters are reserved:
 *   - escape - sets escape mode:
 *       - 'html' for HTML escaping, this is the default.
 *       - 'js' for javascript escaping.
 *       - 'url' for url escaping.
 *       - 'no'/'off'/0 - turns off escaping
 *   - plural - The plural version of the text (2nd parameter of ngettext())
 *   - count - The item count for plural mode (3rd parameter of ngettext())
 */
function smarty_block_t($params, $text, &$smarty)
{
    $text = stripslashes($text);
    // set escape mode
    if (isset($params['escape'])) {
        $escape = $params['escape'];
        unset($params['escape']);
    }
    // set plural version
    if (isset($params['plural'])) {
        $plural = $params['plural'];
        unset($params['plural']);
        // set count
        if (isset($params['count'])) {
            $count = $params['count'];
            unset($params['count']);
        }
    }
    // use plural if required parameters are set
    if (isset($count) && isset($plural)) {
        $text = T_ngettext($text, $plural, $count);
    } else {
        // use normal
        $text = T_gettext($text);
    }
    // run strarg if there are parameters
    if (count($params)) {
        $text = smarty_gettext_strarg($text, $params);
    }
    if (!isset($escape) || $escape == 'html') {
        // html escape, default
        $text = nl2br(htmlspecialchars($text));
    } elseif (isset($escape)) {
        switch ($escape) {
            case 'javascript':
            case 'js':
            case 'json':
                // javascript escape {12-12-2007, mike: modified for JSON support in ZMG}
                $json =& zmgFactory::getJSON();
                $text = $json->encode($text);
                break;
            case 'url':
                // url escape
                $text = urlencode($text);
                break;
        }
    }
    return $text;
}
 function msg($msgid, $lang = "")
 {
     T_setlocale(LC_ALL, $this->getLang($lang));
     T_bindtextdomain($this->domain, $this->directory);
     T_textdomain($this->domain);
     T_bind_textdomain_codeset($this->domain, 'UTF-8');
     if ($msgid == "") {
         return "";
     } else {
         return T_gettext($msgid);
     }
 }
Exemple #7
0
function _e($string)
{
    echo T_gettext($string);
}
Exemple #8
0
 /**
  * Prepare data for use by client pie charts
  * @param array $result Array of data
  * @param type $sum user count
  * @return array (clients => (name, count, y), versions (name, version, cat, count, y))
  */
 public function makeClientPieData($result, $sum)
 {
     $clients = array();
     foreach ($result as $client) {
         // Determine client name and version
         $matches = array();
         preg_match('/^(.*?)\\s*(\\S*\\d\\S*)/', str_replace(array('(', ')', '[', ']', '{', '}'), '', $client['client']), $matches);
         if (count($matches) == 3) {
             $name = $matches[1];
             $version = $matches[2][0] == 'v' ? substr($matches[2], 1) : $matches[2];
         } else {
             $name = $client['client'] ? $client['client'] : T_gettext('Unknown');
             $version = '';
         }
         $name = trim($name);
         $version = trim($version);
         // Categorize the versions
         if (!array_key_exists($name, $clients)) {
             $clients[$name] = array('count' => $client['count'], 'versions' => array());
         } else {
             $clients[$name]['count'] += $client['count'];
         }
         if (isset($clients[$name]['versions'][$version])) {
             $clients[$name]['versions'][$version] += $client['count'];
         } else {
             $clients[$name]['versions'][$version] = $client['count'];
         }
     }
     // Sort by count descending
     uasort($clients, function ($a, $b) {
         return $a['count'] < $b['count'];
     });
     foreach ($clients as $key => $val) {
         arsort($clients[$key]['versions']);
         unset($val);
     }
     // Prepare data for output
     $min_count = ceil($sum / 300);
     $data = array('clients' => array(), 'versions' => array());
     $other = array('count' => 0, 'versions' => array());
     $other_various = 0;
     foreach ($clients as $name => $client) {
         $percent = round($client['count'] / $sum * 100, 2);
         if ($percent < 2 || $name == T_gettext('Unknown')) {
             // Too small or unknown
             $other['count'] += $client['count'];
             foreach ($client['versions'] as $version => $count) {
                 if ($count < $min_count) {
                     $other_various += $count;
                 } else {
                     $other['versions'][] = array('name' => $name, 'version' => $version, 'cat' => T_gettext('Other'), 'count' => (int) $count, 'y' => (double) round($count / $sum * 100, 2));
                 }
             }
         } else {
             $data_various = 0;
             $data['clients'][] = array('name' => $name, 'count' => (int) $client['count'], 'y' => (double) $percent);
             foreach ($client['versions'] as $version => $count) {
                 if ($count < $min_count) {
                     $data_various += $count;
                 } else {
                     $data['versions'][] = array('name' => $name, 'version' => $version, 'cat' => $name, 'count' => (int) $count, 'y' => (double) round($count / $sum * 100, 2));
                 }
             }
             if ($data_various) {
                 $data['versions'][] = array('name' => $name, 'version' => '(' . T_gettext('various') . ')', 'cat' => $name, 'count' => (int) $data_various, 'y' => (double) round($data_various / $sum * 100, 2));
             }
         }
     }
     if ($other_various) {
         $other['versions'][] = array('name' => T_gettext('Various'), 'version' => '', 'cat' => T_gettext('Other'), 'count' => (int) $other_various, 'y' => (double) round($other_various / $sum * 100, 2));
     }
     // Append other slices
     if ($other['count'] > 0) {
         $other['percent'] = round($other['count'] / $sum * 100, 2);
         $data['clients'][] = array('name' => T_gettext('Other'), 'count' => (int) $other['count'], 'y' => (double) $other['percent']);
         $data['versions'] = array_merge($data['versions'], $other['versions']);
     }
     return $data;
 }