Example #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 - Valid is "js" to escape a string for usage inside JS string
 *   - 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, &$repeat)
{
    global $opt;
    if ($repeat) {
        return;
    }
    $escape = isset($params['escape']) ? $params['escape'] : '';
    unset($params['escape']);
    // use plural if required parameters are set
    if (isset($params['count']) && isset($params['plural']) && $params['count'] != 1) {
        $text = $params['plural'];
    }
    unset($params['plural']);
    unset($params['count']);
    // run strarg if there are parameters
    if (count($params)) {
        $text = smarty_gettext_strarg($text, $params);
    }
    // escape the string, now
    // see also modifier.escpapejs.php
    if ($escape == 'js') {
        $text = str_replace('\\', '\\\\', $text);
        $text = str_replace('\'', '\\\'', $text);
        $text = str_replace('"', '"', $text);
    }
    return $text;
}
Example #2
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)
{
    $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
    //$text = gettext($text);
    $text = \Sifo\I18N::getTranslation($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;
}
Example #3
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)
{
    $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']);
        }
    }
    //debut modif lolo
    // use plural if required parameters are set
    /*if (isset($count) && isset($plural)) {
    		$text = ngettext($text, $plural, $count);
    	} else { // use normal
    		$text = gettext($text);
    	}*/
    //$text=I18n::getInstance()->translate($text);
    $module = $smarty->_tpl_vars['module'];
    $key = strtoupper('STRING_' . md5($text));
    $text = I18n::t($text, $key, $module);
    //fin modif lolo
    // 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;
}
Example #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;
}
Example #6
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)
{
    // attempt to load user defined gettext functions
    $gettext_plural_func = $smarty->_gettext_plural_func;
    $gettext_func = $smarty->_gettext_func;
    $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)) {
        if (isset($gettext_plural_func)) {
            $text = call_user_func($gettext_plural_func, $text, $plural, $count);
        } else {
            $text = ngettext($text, $plural, $count);
        }
    } else {
        // use normal
        if (isset($gettext_func)) {
            $text = call_user_func($gettext_func, $text);
        } else {
            $text = 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;
}
Example #7
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, &$repeat)
{
    if (!$repeat) {
        $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']);
            }
        }
        $resource = $smarty->getTemplateVars('resource');
        // use plural if required parameters are set
        if (isset($count) && isset($plural)) {
            if ($resource) {
                $text = $resource->ngettext($text, $plural, $count);
            } else {
                $text = $count == 1 ? $text : $plural;
            }
        } else {
            // use normal
            if ($resource) {
                $text = $resource->translate($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;
    }
}
/**
 * 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())
 *   - domain - Textdomain to be used, default if skipped (dgettext() instead of gettext())
 *
 * @param array $params
 * @param string $text
 * @link http://www.smarty.net/docs/en/plugins.block.functions.tpl
 * @return string
 */
function smarty_block_t($params, $text)
{
    if (!isset($text)) {
        return $text;
    }
    // set escape mode, default html escape
    if (isset($params['escape'])) {
        $escape = $params['escape'];
        unset($params['escape']);
    } else {
        $escape = 'html';
    }
    // 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']);
        }
    }
    // set domain
    if (isset($params['domain'])) {
        $domain = $params['domain'];
        unset($params['domain']);
    } else {
        $domain = null;
    }
    // use plural if required parameters are set
    if (isset($count) && isset($plural)) {
        // use specified textdomain if available
        if (isset($domain)) {
            $text = dngettext($domain, $text, $plural, $count);
        } else {
            $text = ngettext($text, $plural, $count);
        }
    } else {
        // use specified textdomain if available
        if (isset($domain)) {
            $text = dgettext($domain, $text);
        } else {
            $text = gettext($text);
        }
    }
    // run strarg if there are parameters
    if (count($params)) {
        $text = smarty_gettext_strarg($text, $params);
    }
    switch ($escape) {
        case 'html':
            $text = nl2br(htmlspecialchars($text));
            break;
        case 'javascript':
        case 'js':
            // javascript escape
            $text = strtr($text, array('\\' => '\\\\', "'" => "\\'", '"' => '\\"', "\r" => '\\r', "\n" => '\\n', '</' => '<\\/'));
            break;
        case 'url':
            // url escape
            $text = urlencode($text);
            break;
    }
    return $text;
}
Example #9
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)
{
    $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']);
        }
    }
    // *** Start TimeTrex Mod - Calls TT specific gettext function if defined.
    if (class_exists('TTi18n')) {
        $text = TTi18n::gettext($text);
    }
    //else  // this becomes an "else if" when flow continues to the orginal "if" below.
    // *** End TimeTrex Mod
    // use plural if required parameters are set
    if (isset($count) && isset($plural)) {
        $text = ngettext($text, $plural, $count);
    } else {
        // use normal
        $text = 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;
}
Example #10
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)
{
    $text = stripslashes($text);
    $params['escape'] = 'off';
    $lower = false;
    // set escape mode
    if (isset($params['escape'])) {
        $escape = $params['escape'];
        unset($params['escape']);
    }
    // set lowercase
    if (isset($params['lower'])) {
        $lower = true;
        unset($params['lower']);
    }
    // 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 = ngettext($text, $plural, $count);
    } else {
        // use normal
        $text = _gettext($text);
    }
    // run strarg if there are parameters
    if (count($params)) {
        $text = smarty_gettext_strarg($text, $params);
    }
    if ($lower === true) {
        $text = strtolower($text);
    }
    if (isset($escape)) {
        switch ($escape) {
            case 'javascript':
            case 'js':
                // javascript escape
                $text = str_replace('\'', '\\\'', stripslashes($text));
                break;
            case 'url':
                // url escape
                $text = urlencode($text);
                break;
            case 'html':
                //html escape
                $text = nl2br(htmlspecialchars($text));
                break;
        }
    }
    return $text;
}
Example #11
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)
{
    //ADDING PHP-GETTEXT SUPPORT
    //error_reporting(E_ALL | E_STRICT);  //for debugging
    $settings = setupPhpGettext();
    extract($settings);
    /*	
    	if(!defined('PROJECT_DIR')) define('PROJECT_DIR', $project_dir);
    	if(!defined('LOCALE_DIR')) define('LOCALE_DIR', $locale_dir);
    	if(!defined('DEFAULT_LOCALE')) define('DEFAULT_LOCALE', $default_locale);
    */
    // gettext setup
    T_setlocale(LC_MESSAGES, $locale);
    // Set the text domain as 'messages'
    $domain = 'messages';
    _bindtextdomain($domain, LOCALE_DIR);
    // bind_textdomain_codeset is supported only in PHP 4.2.0+
    if (function_exists('bind_textdomain_codeset')) {
        _bind_textdomain_codeset($domain, $encoding);
    }
    _textdomain($domain);
    // end PHP-GETTEXT SUPPORT
    $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 = _ngettext($text, $plural, $count);
    } else {
        // use normal
        $text = _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;
}