本文整理汇总了PHP中dngettext函数的典型用法代码示例。如果您正苦于以下问题:PHP dngettext函数的具体用法?PHP dngettext怎么用?PHP dngettext使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了dngettext函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getText
/**
* @param string $message1
* @param string|null $message2
* @param int|null $n
* @return string
*/
public function getText($message1, $message2 = null, $n = null)
{
if (!isset($message2)) {
return dgettext($this->domain, $message1);
} else {
return dngettext($this->domain, $message1, $message2, $n);
}
}
示例2: nt
/**
* Plural version of t()
*
* @param string $string1
* @param string $string2
* @param int $n
* @param string $textDomain Textdomain to use
* @return string
*/
public function nt($string1, $string2, $n, $textDomain = null)
{
if (empty($textDomain)) {
return ngettext($string1, $string2, $n);
} else {
return dngettext($textDomain, $string1, $string2, $n);
}
}
示例3: nmsg
/**
* Busca un mensaje único, en singular y plural, traducido en el dominio 'nml'.
* El mensaje puede contener cadenas de formato.
*
* @param string $singular Mensaje con formato que se va a buscar cuando $n
* es uno (1).
* @param string $plural Mensaje con formato que se va a buscar cuando $n
* es distinto a (1).
* @param integer $n Cantidad
* @param array|mixed $args Un objeto, una lista de objetos o múltiples
* argumentos que se van a incluir en las cadenas de formato del mensaje.
*
* @return string
* @see dngettext
* */
function nmsg($singular, $plural, $n, $args = null)
{
$translated = dngettext(GETTEXT_DOMAIN, $singular, $plural, $n);
if (func_num_args() > 4) {
$args = array_slice(func_get_args(), 3);
}
return String::format($translated, $args);
}
示例4: display_content
function display_content()
{
echo '<p><a href="' . urlStrRedirect('samba/config/sambastatus') . '">';
printf(dngettext("samba", "%d open session", "%d open sessions", $this->data['sessions']), $this->data['sessions']);
echo '</a><br/>';
echo '<a href="' . urlStrRedirect('samba/config/sambastatus') . '">';
printf(dngettext("samba", "%d share connection", "%d share connections", $this->data['shares']), $this->data['shares']);
echo '</a></p>';
}
示例5: 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 compatible
* 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 $singular singular English source singular form
* @param string $plural plural English source plural form
* @param int $count number of items to control plural selection
*
* @return string translated message or original if translation not found
*/
function dnpgettext($domain, $context, $singular, $plural, $count)
{
$msgid = $context . Translator::GETTEXT_CONTEXT_GLUE . $singular;
$out = dngettext($domain, $msgid, $plural, $count);
if ($out === $msgid) {
if ($count == 1) {
return $singular;
}
return $plural;
}
return $out;
}
示例6: translatePlural
/**
* Translate a plural string
*
* Falls back to the default domain in case the string cannot be translated using the given domain
*
* @param string $textSingular The string in singular form to translate
* @param string $textPlural The string in plural form to translate
* @param integer $number The amount to determine from whether to return singular or plural
* @param string $domain The primary domain to use
* @param string|null $context Optional parameter for context based translation
*
* @return string The translated string
*/
public static function translatePlural($textSingular, $textPlural, $number, $domain, $context = null)
{
if ($context !== null) {
$res = self::pngettext($textSingular, $textPlural, $number, $domain, $context);
if (($res === $textSingular || $res === $textPlural) && $domain !== self::DEFAULT_DOMAIN) {
$res = self::pngettext($textSingular, $textPlural, $number, self::DEFAULT_DOMAIN, $context);
}
return $res;
}
$res = dngettext($domain, $textSingular, $textPlural, $number);
if (($res === $textSingular || $res === $textPlural) && $domain !== self::DEFAULT_DOMAIN) {
$res = dngettext(self::DEFAULT_DOMAIN, $textSingular, $textPlural, $number);
}
return $res;
}
示例7: display_content
function display_content()
{
$MMCApp =& MMCApp::getInstance();
$errors = '';
foreach ($this->data as $module => $services_infos) {
$moduleObj = $MMCApp->getModule($module);
if ($errors) {
$errors .= "<br/>";
}
$errors .= '<strong>' . $moduleObj->getDescription() . ' : <a class="error" href="' . urlStrRedirect('services/control/index') . '">' . sprintf(dngettext("services", "%d inactive service", "%d inactive services", count($services_infos)), count($services_infos)) . '</a></strong>';
}
if ($errors) {
echo '<p class="alert alert-error">' . $errors . '</p>';
} else {
echo '<p class="alert alert-success"><img src="img/common/icn_yes.gif" style="vertical-align: bottom" /> ' . _T("All services are up", "services") . '</p>';
}
}
示例8: smarty_block_t
/**
* 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;
}
示例9: dngettext
/**
* Override the current domain for a single plural message lookup
*
* Returns the given $count (e.g second, third,...) plural form of the
* given string. If the id is not found and $num == 1 $msg is returned,
* otherwise $msg_plural
*
* @param String $domain The domain to search in
* @param String $msg The message to search for
* @param String $msg_plural A fallback plural form
* @param Integer $count Which plural form
*
* @return Translated string
*/
public function dngettext($domain, $msg, $msg_plural, $count)
{
return dngettext($domain, $msg, $msg_plural, $count);
}
示例10: ngettext
/**
* Returns the plural translation of a message.
*
* @param string $singular The singular version to translate.
* @param string $plural The plural version to translate.
* @param integer $number The number that determines singular vs. plural.
*
* @return string The string translation, or the original string if no
* translation exists.
*/
public function ngettext($singular, $plural, $number)
{
return $this->_gettext ? dngettext($this->_domain, $singular, $plural, $number) : ($number > 1 ? $plural : $singular);
}
示例11: translate
/**
* Returns the gettext translation of msgid
*
* The default domain is "labels". Any other text domains must be passed
* in the second parameter.
*
* For entries in the PO that are plurals, you must pass msgid as an array
* $this->translate( ['msgid', 'msgid_plural', $num] )
*
* @param mixed $msgid String or Array
* @param string $domain Alternate domain
* @return string
*/
public function translate($msgid, $domain = null)
{
if (is_array($msgid)) {
return $domain ? dngettext($domain, $msgid[0], $msgid[1], $msgid[2]) : ngettext($msgid[0], $msgid[1], $msgid[2]);
} else {
return $domain ? dgettext($domain, $msgid) : gettext($msgid);
}
}
示例12: updateGroup
/**
* Updates the selected server group
*/
function updateGroup($post)
{
global $fmdb, $__FM_CONFIG;
if (empty($post['group_name'])) {
return __('No group name defined.');
}
/** Check name field length */
$field_length = getColumnLength('fm_' . $__FM_CONFIG['fmDNS']['prefix'] . 'groups', 'group_name');
if ($field_length !== false && strlen($post['group_name']) > $field_length) {
return sprintf(dngettext($_SESSION['module'], 'Group name is too long (maximum %d character).', 'Group name is too long (maximum %d characters).', $field_length), $field_length);
}
/** Does the record already exist for this account? */
basicGet('fm_' . $__FM_CONFIG['fmDNS']['prefix'] . 'server_groups', $post['group_name'], 'group_', 'group_name', "AND group_id!='{$post['server_id']}'");
if ($fmdb->num_rows) {
return __('This group name already exists.');
}
/** Process group masters */
$log_message_master_servers = null;
foreach ((array) $post['group_masters'] as $val) {
if ($val == 0) {
$group_masters = 0;
break;
}
$group_masters .= $val . ';';
$server_name = getNameFromID($val, 'fm_' . $__FM_CONFIG['fmDNS']['prefix'] . 'servers', 'server_', 'server_id', 'server_name');
$log_message_master_servers .= $val ? "{$server_name}; " : null;
}
$log_message_master_servers = rtrim($log_message_master_servers, '; ');
$post['group_masters'] = rtrim($group_masters, ';');
if (!isset($post['group_masters'])) {
$post['group_masters'] = 0;
}
/** Process group slaves */
$log_message_slave_servers = null;
foreach ((array) $post['group_slaves'] as $val) {
if ($val == 0) {
$group_slaves = 0;
break;
}
$group_slaves .= $val . ';';
$server_name = getNameFromID($val, 'fm_' . $__FM_CONFIG['fmDNS']['prefix'] . 'servers', 'server_', 'server_id', 'server_name');
$log_message_slave_servers .= $val ? "{$server_name}; " : null;
}
$log_message_slave_servers = rtrim($log_message_slave_servers, '; ');
$post['group_slaves'] = rtrim($group_slaves, ';');
if (!isset($post['group_slaves'])) {
$post['group_slaves'] = 0;
}
$post['account_id'] = $_SESSION['user']['account_id'];
$sql_edit = null;
$exclude = array('submit', 'action', 'server_id', 'group_id', 'compress', 'AUTHKEY', 'module_name', 'module_type', 'config', 'sub_type');
foreach ($post as $key => $data) {
if (!in_array($key, $exclude)) {
$sql_edit .= $key . "='" . sanitize($data) . "',";
}
}
$sql = rtrim($sql_edit, ',');
/** Update the server */
$old_name = getNameFromID($post['server_id'], 'fm_' . $__FM_CONFIG['fmDNS']['prefix'] . 'server_groups', 'group_', 'group_id', 'group_name');
$query = "UPDATE `fm_{$__FM_CONFIG['fmDNS']['prefix']}server_groups` SET {$sql} WHERE `group_id`={$post['server_id']} AND `account_id`='{$_SESSION['user']['account_id']}'";
$result = $fmdb->query($query);
if ($fmdb->sql_errors) {
return __('Could not update the group because a database error occurred.');
}
/** Return if there are no changes */
if (!$fmdb->rows_affected) {
return true;
}
addLogEntry(sprintf(__("Updated server group '%s' to"), $old_name) . ":\n" . __('Name') . ": {$post['group_name']}\n" . __('Masters') . ": {$log_message_master_servers}\n" . __('Slaves') . ": {$log_message_slave_servers}\n");
return true;
}
示例13: 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==
示例14: validatePost
function validatePost($post)
{
global $fmdb, $__FM_CONFIG;
if (empty($post['server_name'])) {
return __('No server name defined.');
}
/** Check name field length */
$field_length = getColumnLength('fm_' . $__FM_CONFIG[$_SESSION['module']]['prefix'] . 'servers', 'server_name');
if ($field_length !== false && strlen($post['server_name']) > $field_length) {
return sprintf(dngettext($_SESSION['module'], 'Server name is too long (maximum %d character).', 'Server name is too long (maximum %d characters).', $field_length), $field_length);
}
/** Does the record already exist for this account? */
basicGet('fm_' . $__FM_CONFIG[$_SESSION['module']]['prefix'] . 'servers', $post['server_name'], 'server_', 'server_name', "AND server_id!='{$post['server_id']}'");
if ($fmdb->num_rows) {
return __('This server name already exists.');
}
if (empty($post['server_config_file'])) {
$post['server_config_file'] = $__FM_CONFIG['fw']['config_file']['default'];
if (!is_array($__FM_CONFIG['fw']['config_file'][$post['server_type']]) && $__FM_CONFIG['fw']['config_file'][$post['server_type']]) {
$post['server_config_file'] = $__FM_CONFIG['fw']['config_file'][$post['server_type']];
} elseif (is_array($__FM_CONFIG['fw']['config_file'][$post['server_type']])) {
if (isset($post['server_os_distro'])) {
$distro = $post['server_os_distro'];
} else {
if ($post['action'] == 'edit') {
$distro = getNameFromID($post['server_id'], 'fm_' . $__FM_CONFIG[$_SESSION['module']]['prefix'] . 'servers', 'server_', 'server_id', 'server_os_distro');
}
}
if (isset($distro) && array_key_exists($distro, $__FM_CONFIG['fw']['config_file'][$post['server_type']])) {
$post['server_config_file'] = $__FM_CONFIG['fw']['config_file'][$post['server_type']][$distro];
}
}
}
/** Set default ports */
if (empty($post['server_update_port']) || isset($post['server_update_port']) && $post['server_update_method'] == 'cron') {
$post['server_update_port'] = 0;
}
if (!empty($post['server_update_port']) && !verifyNumber($post['server_update_port'], 1, 65535, false)) {
return __('Server update port must be a valid TCP port.');
}
if (empty($post['server_update_port']) && isset($post['server_update_method'])) {
if ($post['server_update_method'] == 'http') {
$post['server_update_port'] = 80;
} elseif ($post['server_update_method'] == 'https') {
$post['server_update_port'] = 443;
} elseif ($post['server_update_method'] == 'ssh') {
$post['server_update_port'] = 22;
}
}
return $post;
}
示例15: changes
public function changes($domain = '', $msgId1 = '', $msgId2 = '', $count = 0)
{
if (!is_string($domain) || !is_string($msgId1) || !is_string($msgId2)) {
return Error::set(lang('Error', 'stringParameter', '1.(domain) & 2.(msgId1) & 3.(msgId2)'));
}
return dngettext($domain, $msgId1, $msgId2, $count);
}