本文整理汇总了PHP中dcngettext函数的典型用法代码示例。如果您正苦于以下问题:PHP dcngettext函数的具体用法?PHP dcngettext怎么用?PHP dcngettext使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了dcngettext函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: dcnpgettext
function dcnpgettext($domain, $msg_ctxt, $msgid, $msgid_plural, $n, $category)
{
$msg_ctxt_id = "{$msg_ctxt}{$msgid}";
$translation = dcngettext($domain, $msg_ctxt_id, $msgid_plural, $n, $category);
if ($translation == $msg_ctxt_id || $translation == $msgid_plural) {
return $n == 1 ? $msgid : $msgid_plural;
} else {
return $translation;
}
}
示例2: dnpgettext
/**
* Context-aware dngettext wrapper; use when messages in different contexts
* won't be distinguished from the English source but need different translations.
* The context string will appear as msgctxt in the .po files.
*
* Not currently exposed in PHP's gettext module; implemented to be compat
* with gettext.h's macros.
*
* @param string $domain domain identifier, or null for default domain
* @param string $context context identifier, should be some key like "menu|file"
* @param string $msg singular English source text
* @param string $plural plural English source text
* @param int $n number of items to control plural selection
* @return string original or translated message
*/
function dnpgettext($domain, $context, $msg, $plural, $n)
{
$msgid = $context . "" . $msg;
$out = dcngettext($domain, $msgid, $plural, $n, LC_MESSAGES);
if ($out == $msgid) {
return $msg;
} else {
return $out;
}
}
示例3: cnget
/**
* Obtiene una traduccion al plural por categoria, cuando se pasan argumentos adicionales se remplaza con sprintf
*
* @param string $sentence1 mensaje en singular
* @param string $sentence2 mensaje en plural
* @param int $n conteo
* @param int $category categoria del mensaje (LC_CTYPE, LC_NUMERIC, LC_TIME, LC_COLLATE, LC_MONETARY, LC_MESSAGES, LC_ALL)
* @return string
* */
public function cnget($sentence1, $sentence2, $n, $category)
{
/**
* Obtengo la traduccion en funcion del dominio
* */
$sentence = dcngettext(textdomain(null), $sentence1, $sentence2, $n, $category);
/**
* Si se pasan multiples parametros
* */
if (func_num_args() > 4) {
$args = func_get_args();
/**
* Se remplaza con vsprintf
* */
unset($args[0], $args[1], $args[2], $args[3]);
$sentence = vsprintf($sentence, $args);
}
return $sentence;
}
示例4: searches
public function searches($domain = '', $msgId1 = '', $msgId2 = '', $count = 0, $category = 0)
{
if (!is_string($domain) || !is_string($msgId1) || !is_string($msgId2)) {
return Error::set(lang('Error', 'stringParameter', '1.(domain) & 2.(msgId1) & 3.(msgId2)'));
}
return dcngettext($domain, $msgId1, $msgId2, $count, $category);
}
示例5: cnquery
/**
* {@inheritdoc}
*
* @param string $msgid1
* @param string $msgid2
* @param integer $count
* @param string $msgctxt Optional. If ommitted or NULL, this method behaves as nquery().
* @param array $placeholders Optional.
* @param string $category Optional. Specify the locale category. Defaults to LC_MESSAGES
* @return string
* @throws \InvalidArgumentException
*/
public function cnquery($msgid1, $msgid2, $count, $msgctxt = null, $placeholders = null, $category = LC_MESSAGES, $domain = null)
{
if (!is_int($count) || $count < 0) {
throw new \InvalidArgumentException("Count must be a nonnegative integer. {$count} given.");
}
if ($domain !== null && !in_array($domain, $this->domains)) {
throw new \InvalidArgumentException($domain . ' is invalid translation domain');
}
if ($msgctxt === null) {
return $this->nquery($msgid1, $msgid2, $count, $placeholders, $domain);
}
if ($domain === null) {
$domain = textdomain(null);
}
$contextString1 = "{$msgctxt}{$msgid1}";
$contextString2 = "{$msgctxt}{$msgid2}";
$translation = dcngettext($domain, $contextString1, $contextString2, $count, $category);
if ($translation == $contextString) {
$translation = $msgid;
}
if (is_array($placeholders)) {
foreach ($placeholders as $key => $value) {
$translation = str_replace('%' . $key . '%', $value, $translation);
}
}
return $translation;
}
示例6: T_dcngettext
function T_dcngettext($domain, $singular, $plural, $number, $category)
{
if (_check_locale_and_function()) {
return dcngettext($domain, $singular, $plural, $number, $category);
} else {
return _dcngettext($domain, $singular, $plural, $number, $category);
}
}
示例7: dCNPGetText
/**
* Override the domain and category for a plural context-based lookup.
*
* @param string $domain
* @param string $context
* @param string $msgid1
* @param string $msgid2
* @param int $n
* @param int $category
* @return string
*/
public function dCNPGetText($domain, $context, $msgid1, $msgid2, $n, $category)
{
if ($this->driver->hasLocaleAndFunction('dcngettext')) {
$context_id = "{$context}{$msgid1}";
$translation = dcngettext($domain, $context_id, $msgid2, $n, $category);
if ($translation == $context_id || $translation == $msgid2) {
return $n == 1 ? $msgid1 : $msgid2;
}
return $translation;
}
return $this->driver->dCNPGetText($domain, $context, $msgid1, $msgid2, $n, $category);
}
示例8: pngettext
/**
* Emulated pngettext()
*
* @link http://php.net/manual/de/book.gettext.php#89975
*
* @param $textSingular
* @param $textPlural
* @param $number
* @param $domain
* @param $context
*
* @return string
*/
public static function pngettext($textSingular, $textPlural, $number, $domain, $context)
{
$contextString = "{$context}{$textSingular}";
$translation = dcngettext($domain, $contextString, $textPlural, $number, defined('LC_MESSAGES') ? LC_MESSAGES : LC_ALL);
if ($translation == $contextString || $translation == $textPlural) {
return $number == 1 ? $textSingular : $textPlural;
} else {
return $translation;
}
}
示例9: cnquery
/**
* {@inheritdoc}
*
* @param string $msgid1
* @param string $msgid2
* @param integer $count
* @param string $msgctxt Optional. If ommitted or NULL, this method behaves as nquery().
* @param array $placeholders Optional.
* @param string $category Optional. Specify the locale category. Defaults to LC_MESSAGES
* @param string $domain Optional.
*
* @return string
* @throws \InvalidArgumentException
*/
public function cnquery($msgid1, $msgid2, $count, $msgctxt = null, $placeholders = null, $category = LC_MESSAGES, $domain = null)
{
self::validateCount($count);
if ($msgctxt === null) {
return $this->nquery($msgid1, $msgid2, $count, $placeholders, $domain);
}
$this->setDomain($domain);
$context = "{$msgctxt}";
$translation = dcngettext($domain, $context . $msgid1, $context . $msgid2, $count, $category);
if (strpos($translation, $context, 0) === 0) {
$translation = substr($translation, strlen($context));
}
return self::setPlaceholders($translation, $placeholders);
}
示例10: cnget
/**
* Obtiene una traduccion al plural por categoria, cuando se pasan argumentos adicionales se remplaza con sprintf
*
* @param string $sentence1 mensaje en singular
* @param string $sentence2 mensaje en plural
* @param int $n conteo
* @param int $category categoria del mensaje (LC_CTYPE, LC_NUMERIC, LC_TIME, LC_COLLATE, LC_MONETARY, LC_MESSAGES, LC_ALL)
* @return string
* */
public static function cnget($sentence1, $sentence2, $n, $category)
{
/**
* Obtengo la traduccion en funcion del dominio
* */
$sentence = dcngettext(textdomain(null), $sentence1, $sentence2, $n, $category);
/**
* Si se pasan multiples parametros
* */
if (func_num_args() > 4) {
$sentence = self::sprintf($sentence, func_get_args(), 4);
}
return $sentence;
}
示例11: str_repeat
<?php
$overflown = str_repeat('C', 8476509);
$msgid = "msgid";
$domain = "domain";
$category = "cat";
var_dump(bindtextdomain($overflown, 'path'));
var_dump(dngettext($overflown, $msgid, $msgid, 1));
var_dump(dngettext($domain, $overflown, $msgid, 1));
var_dump(dngettext($domain, $msgid, $overflown, 1));
var_dump(gettext($overflown));
var_dump(ngettext($overflown, $msgid, -1));
var_dump(ngettext($msgid, $overflown, -1));
var_dump(dcgettext($overflown, $msgid, -1));
var_dump(dcgettext($domain, $overflown, -1));
var_dump(dcngettext($overflown, $msgid, $msgid, -1, -1));
var_dump(dcngettext($domain, $overflown, $msgid, -1, -1));
var_dump(dcngettext($domain, $msgid, $overflown, -1, -1));
var_dump(dgettext($overflown, $msgid));
var_dump(dgettext($domain, $overflown));
var_dump(textdomain($overflown));
?>
==DONE==
示例12: searches
public function searches(string $domain, string $msgId1, string $msgId2, int $count = 0, int $category = 0) : string
{
return dcngettext($domain, $msgId1, $msgId2, $count, $category);
}
示例13: dcnpgettext
public function dcnpgettext($context, $domain, $msgid1, $msgid2, $n, $category)
{
return dcngettext($domain, $context . "" . $msgid1, $context . "" . $msgid2, $n, constant($category));
}
示例14: nlang
/**
* Return a translated string, with proper singular/plural form.
*
* @param String $singular Identifier for the singular version of
* the string
* @param String $plural Identifier for the plural version of
* the string
* @param Integer $amount The amount the translation should be based on
* @param String $context Context information fot the requested string
*
* @return String $string Translated string, identifier by default
*/
public function nlang($singular, $plural, $amount, $context = '')
{
if (strlen($singular) + strlen($context) + 1 > self::GETTEXT_MAX_MSGID_LENGTH) {
$this->logger->warning('Identifier too long: ' . $singular);
return $singular;
}
$this->init($this->language);
if ($context == '') {
return ngettext($singular, $plural, $amount);
}
// Glue msgctxt and msgid together, with ASCII character 4
// (EOT, End Of Text)
$composed = "{$context}{$singular}";
$output = dcngettext($this->domain, $composed, $plural, $amount, LC_MESSAGES);
if (($output == $composed || $output == $plural) && $this->language != $this->default_language) {
return $amount == 1 ? $singular : $plural;
} else {
return $output;
}
}
示例15: var_dump
<?php
var_dump(dcngettext(1, 1, 1, 1));
var_dump(dcngettext(1, 1, 1, 1, 1));
var_dump(dcngettext("test", "test", "test", 1, 1));
var_dump(dcngettext("test", "test", "test", 0, 0));
var_dump(dcngettext("test", "test", "test", -1, -1));
var_dump(dcngettext("", "", "", 1, 1));
var_dump(dcngettext("", "", "", 0, 0));
echo "Done\n";