public function testDnpgettext() { if (self::$functionExists['dnpgettext']) { $this->markTestSkipped('Function dnpgettext already defined'); } $domain = 'client'; textdomain($domain); $translation = dnpgettext($domain, 'firstContext', 'singular with context', '%d plurals with context', 1); $this->assertEquals("client's singular with context", $translation); $translation = dnpgettext($domain, 'firstContext', 'singular with context', '%d plurals with context', 2); $this->assertEquals("%d client's plurals with context", $translation); $this->setlocaleCs(); $translation = dnpgettext($domain, 'firstContext', 'singular with context', '%d plurals with context', 1); $this->assertEquals('klientské jednotné číslo s kontextem', $translation); $translation = dnpgettext($domain, 'firstContext', 'singular with context', '%d plurals with context', 2); $this->assertEquals('%d klientská množná čísla s kontextem', $translation); $translation = dnpgettext($domain, 'firstContext', 'singular with context', '%d plurals with context', 5); $this->assertEquals('%d klientských množných čísel s kontextem', $translation); }
/** * 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()"); } }
function T_dnpgettext($domain, $context, $singular, $plural, $number) { if (_check_locale_and_function('dnpgettext')) { return dnpgettext($domain, $context, $singular, $plural, $number); } else { return _dnpgettext($domain, $context, $singular, $plural, $number); } }
function npgettext($msg_ctxt, $msgid, $msgid_plural, $n) { return dnpgettext(textdomain(null), $msg_ctxt, $msgid, $msgid_plural, $n); }
/** * Translate a plural 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 $msgid1 * The singular string to translate. * \param $msgid1 * The plural string to translate. * \param $n * The count * * \return * The translated string, or the original string if no translation was * found. * * \see ngettext * \see dpgettext * \see npgettext */ function npgettext($ctx, $msgid1, $msgid2, $n) { return dnpgettext(textdomain(null), $ctx, $msgid1, $msgid2, $n); }
function npgettext($context, $singular, $plural, $count) { $domain = textdomain(null); return dnpgettext($domain, $context, $singular, $plural, $count); }
public function dnpgettext($domain, $context, $singular, $plural, $count) { $domain = $this->getDomain($domain); return dnpgettext($domain, $context, $singular, $plural, abs($count)); }
/** * 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; }