コード例 #1
0
 public function testDpgettext()
 {
     if (self::$functionExists['dpgettext']) {
         $this->markTestSkipped('Function dpgettext already defined');
     }
     $domain = 'client';
     textdomain($domain);
     $translation = dpgettext($domain, 'firstContext', 'message with context');
     $this->assertEquals("client's message with context", $translation);
     $this->setlocaleCs();
     $translation = dpgettext($domain, 'firstContext', 'message with context');
     $this->assertEquals('klientská zpráva s kontextem', $translation);
 }
コード例 #2
0
ファイル: language.php プロジェクト: himmelex/NTW
/**
 * Shortcut for *gettext functions with smart domain detection.
 *
 * If calling from a plugin, this function checks which plugin was
 * being called from and uses that as text domain, which will have
 * been set up during plugin initialization.
 *
 * Also handles plurals and contexts depending on what parameters
 * are passed to it:
 *
 *   gettext -> _m($msg)
 *  ngettext -> _m($msg1, $msg2, $n)
 *  pgettext -> _m($ctx, $msg)
 * npgettext -> _m($ctx, $msg1, $msg2, $n)
 *
 * @fixme may not work properly in eval'd code
 *
 * @param string $msg
 * @return string
 */
function _m($msg)
{
    $domain = _mdomain(debug_backtrace());
    $args = func_get_args();
    switch (count($args)) {
        case 1:
            return dgettext($domain, $msg);
        case 2:
            return dpgettext($domain, $args[0], $args[1]);
        case 3:
            return dngettext($domain, $args[0], $args[1], $args[2]);
        case 4:
            return dnpgettext($domain, $args[0], $args[1], $args[2], $args[3]);
        default:
            throw new Exception("Bad parameter count to _m()");
    }
}
コード例 #3
0
function T_dpgettext($domain, $context, $msgid)
{
    if (_check_locale_and_function('dpgettext')) {
        return dpgettext($domain, $context, $msgid);
    } else {
        return _dpgettext($domain, $context, $msgid);
    }
}
コード例 #4
0
ファイル: pgettext.php プロジェクト: azatoth/php-pgettext
function pgettext($msg_ctxt, $msgid)
{
    return dpgettext(textdomain(null), $msg_ctxt, $msgid);
}
コード例 #5
0
ファイル: gettext.lib.php プロジェクト: jijkoun/ssscrape
/**
 * Translate a message with disambiguating context using the default text
 * domain.
 *
 * This function can be used to provide context to the translator.
 *
 * \param $ctx
 *   The context of the message.
 * \param $str
 *   The string to translate.
 *
 * \return
 *   The translated string, or the original string if no translation was
 *   found.
 *
 * \see dpgettext
 */
function pgettext($ctx, $str)
{
    return dpgettext(textdomain(null), $ctx, $str);
}
コード例 #6
0
ファイル: Translator.php プロジェクト: sharkodlak/php-gettext
 function pgettext($context, $message)
 {
     $domain = textdomain(null);
     return dpgettext($domain, $context, $message);
 }
コード例 #7
0
 public function dpgettext($domain, $context, $message)
 {
     $domain = $this->getDomain($domain);
     return dpgettext($domain, $context, $message);
 }
コード例 #8
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())
 *   - domain - Textdomain to be used, default if skipped (dgettext() instead of gettext())
 *   - context - gettext context. reserved for future use.
 *
 * @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 parameters 'plural' and 'count'.
    if (isset($params['plural'])) {
        $plural = $params['plural'];
        unset($params['plural']);
        // set count
        if (isset($params['count'])) {
            $count = $params['count'];
            unset($params['count']);
        }
    }
    // get domain param
    if (isset($params['domain'])) {
        $domain = $params['domain'];
        unset($params['domain']);
    } else {
        $domain = null;
    }
    // get context param
    if (isset($params['context'])) {
        $context = $params['context'];
        unset($params['context']);
    } else {
        $context = null;
    }
    // use plural if required parameters are set
    if (isset($count) && isset($plural)) {
        // use specified textdomain if available
        if (isset($domain) && isset($context)) {
            $text = dnpgettext($domain, $context, $text, $plural, $count);
        } elseif (isset($domain)) {
            $text = dngettext($domain, $text, $plural, $count);
        } elseif (isset($context)) {
            $text = npgettext($context, $text, $plural, $count);
        } else {
            $text = ngettext($text, $plural, $count);
        }
    } else {
        // use specified textdomain if available
        if (isset($domain) && isset($context)) {
            $text = dpgettext($domain, $context, $text);
        } elseif (isset($domain)) {
            $text = dgettext($domain, $text);
        } elseif (isset($context)) {
            $text = pgettext($context, $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;
}