/** * @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); } }
/** * 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); } }
/** * 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); }
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>'; }
/** 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; }
/** * 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; }
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>'; } }
/** * 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; }
/** * 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); }
/** * 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); }
/** * 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); } }
/** * 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; }
<?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==
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; }
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); }
public static function timeWaiting($rel) { if ($rel < 0) { return dgettext('checkin', 'Time error'); } $hours = floor($rel / 3600); if ($hours) { $rel = $rel % 3600; } $mins = floor($rel / 60); if ($hours) { $waiting[] = sprintf(dngettext('checkin', '%s hour', '%s hours', (int) $hours), $hours); } if ($mins) { $waiting[] = sprintf(dgettext('checkin', '%s min.'), $mins); } if (!isset($waiting)) { if (!$rel) { $waiting[] = dgettext('checkin', 'No meeting'); } else { $waiting[] = dgettext('checkin', '< 1 min.'); } } return implode(', ', $waiting); }
function dcngettext($domain, $msgid1, $msgid2, $n, $category) { global $po_msg, $po_filename, $po_category; global $po_charset; global $po_domain; // Current Domain $str_category = _po_set_category_file($domain, $category); if (!$str_category) { return $n % 2 ? sprintf($msgid1, $n) : sprintf($msgid2, $n); } // locale backup $bk_category = $po_category; $po_category = $str_category; $rc = dngettext($domain, $msgid1, $msgid2, $n); $po_category = $bk_category; unset($bk_category); return $rc; }
/** * {@inheritdoc} * * @param string $msgid1 * @param string $msgid2 * @param integer $count * @param array $placeholders * @param string $domain * * @return string */ public function nquery($msgid1, $msgid2, $count, $placeholders = null, $domain = null) { self::validateCount($count); if ($domain === null) { $translation = ngettext($msgid1, $msgid2, $count); } else { $translation = dngettext($domain, $msgid1, $msgid2, $count); } return self::setPlaceholders($translation, $placeholders); }
function validatePost($post) { global $fmdb, $__FM_CONFIG; if (!$post['domain_id']) { unset($post['domain_id']); } /** Empty domain names are not allowed */ if (empty($post['domain_name'])) { return __('No zone name defined.'); } if ($post['domain_template'] != 'yes') { $post['domain_name'] = rtrim(strtolower($post['domain_name']), '.'); /** Perform domain name validation */ if (!isset($post['domain_mapping'])) { global $map; $post['domain_mapping'] = $map; } if ($post['domain_mapping'] == 'reverse') { $post['domain_name'] = $this->fixDomainTypos($post['domain_name']); } else { $post['domain_name'] = function_exists('idn_to_ascii') ? idn_to_ascii($post['domain_name']) : $post['domain_name']; } if (!$this->validateDomainName($post['domain_name'], $post['domain_mapping'])) { return __('Invalid zone name.'); } } /** Is this based on a template? */ if ($post['domain_template_id']) { $include = array('action', 'domain_template_id', 'domain_name', 'domain_template', 'domain_mapping'); foreach ($include as $key) { $new_post[$key] = $post[$key]; } $post = $new_post; unset($new_post, $post['domain_template']); $post['domain_type'] = getNameFromID($post['domain_template_id'], 'fm_' . $__FM_CONFIG['fmDNS']['prefix'] . 'domains', 'domain_', 'domain_id', 'domain_type'); $post['domain_view'] = getNameFromID($post['domain_template_id'], 'fm_' . $__FM_CONFIG['fmDNS']['prefix'] . 'domains', 'domain_', 'domain_id', 'domain_view'); return $post; } else { $post['domain_template_id'] = 0; } /** Format domain_clone_domain_id */ if (!$post['domain_clone_domain_id'] && $post['action'] == 'add') { $post['domain_clone_domain_id'] = 0; } /** domain_clone_dname override */ if (!$post['domain_clone_dname_override']) { $post['domain_clone_dname'] = null; } else { unset($post['domain_clone_dname_override']); } /** Ensure domain_view is set */ if (!array_key_exists('domain_view', $post)) { $post['domain_view'] = $post['domain_clone_domain_id'] ? -1 : 0; } /** Reverse zones should have form of x.x.x.in-addr.arpa */ if ($post['domain_mapping'] == 'reverse') { $post['domain_name'] = $this->setReverseZoneName($post['domain_name']); } /** Does the record already exist for this account? */ $domain_id_sql = isset($post['domain_id']) ? 'AND domain_id!=' . sanitize($post['domain_id']) : null; basicGet('fm_' . $__FM_CONFIG[$_SESSION['module']]['prefix'] . 'views', $_SESSION['user']['account_id'], 'view_', 'account_id'); if (!$fmdb->num_rows) { /** No views defined - all zones must be unique */ basicGet('fm_' . $__FM_CONFIG[$_SESSION['module']]['prefix'] . 'domains', sanitize($post['domain_name']), 'domain_', 'domain_name', $domain_id_sql); if ($fmdb->num_rows) { return __('Zone already exists.'); } } else { /** All zones must be unique per view */ $defined_views = $fmdb->last_result; /** Format domain_view */ if (!$post['domain_view'] || in_array(0, $post['domain_view'])) { basicGet('fm_' . $__FM_CONFIG[$_SESSION['module']]['prefix'] . 'domains', sanitize($post['domain_name']), 'domain_', 'domain_name', $domain_id_sql); if ($fmdb->num_rows) { /** Zone exists for views, but what about on the same server? */ if (!$post['domain_name_servers'] || in_array('0', $post['domain_name_servers'])) { return __('Zone already exists for all views.'); } } } if (is_array($post['domain_view'])) { $domain_view = null; foreach ($post['domain_view'] as $val) { if ($val == 0 || $val == '') { $domain_view = 0; break; } $domain_view .= $val . ';'; basicGet('fm_' . $__FM_CONFIG[$_SESSION['module']]['prefix'] . 'domains', sanitize($post['domain_name']), 'domain_', 'domain_name', "AND (domain_view='{$val}' OR domain_view=0 OR domain_view LIKE '{$val};%' OR domain_view LIKE '%;{$val};%' OR domain_view LIKE '%;{$val}') {$domain_id_sql}"); if ($fmdb->num_rows) { $view_name = getNameFromID($val, 'fm_' . $__FM_CONFIG[$_SESSION['module']]['prefix'] . 'views', 'view_', 'view_id', 'view_name'); return sprintf(__("Zone already exists for the '%s' view."), $view_name); } } $post['domain_view'] = rtrim($domain_view, ';'); } } /** Check name field length */ $field_length = getColumnLength('fm_' . $__FM_CONFIG[$_SESSION['module']]['prefix'] . 'domains', 'domain_name'); if ($field_length !== false && strlen($post['domain_name']) > $field_length) { return sprintf(dngettext($_SESSION['module'], 'Zone name is too long (maximum %d character).', 'Zone name is too long (maximum %d characters).', $field_length), $field_length); } /** No need to process more if zone is cloned */ if ($post['domain_clone_domain_id']) { return $post; } /** Cleans up acl_addresses for future parsing **/ $clean_fields = array('forwarders', 'masters'); foreach ($clean_fields as $val) { $post['domain_required_servers'][$val] = verifyAndCleanAddresses($post['domain_required_servers'][$val], 'no-subnets-allowed'); if (strpos($post['domain_required_servers'][$val], 'not valid') !== false) { return $post['domain_required_servers'][$val]; } } /** Forward zones require forward servers */ if ($post['domain_type'] == 'forward') { if (empty($post['domain_required_servers']['forwarders'])) { return __('No forward servers defined.'); } $post['domain_required_servers'] = $post['domain_required_servers']['forwarders']; } /** Slave and stub zones require master servers */ if (in_array($post['domain_type'], array('slave', 'stub'))) { if (empty($post['domain_required_servers']['masters'])) { return __('No master servers defined.'); } $post['domain_required_servers'] = $post['domain_required_servers']['masters']; } return $post; }
/** * Translate a plural message with disambiguating context using the default text * domain. * * This function can be used to provide context to the translator. * * \param $domain * The text domain used for the lookup * \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 dnpgettext($domain, $ctx, $msgid1, $msgid2, $n) { /* See dpgettext() implementation above */ $msgid1_with_ctx = sprintf("%s%s", $ctx, $msgid1); $msgid2_with_ctx = sprintf("%s%s", $ctx, $msgid2); $translated = dngettext($domain, $msgid1_with_ctx, $msgid2_with_ctx, $n); $prefix = sprintf("%s", $ctx); $translated = str_strip_prefix($translated, $prefix); return $translated; }
function T_dngettext($domain, $singular, $plural, $number) { if (_check_locale_and_function()) { return dngettext($domain, $singular, $plural, $number); } else { return _dngettext($domain, $singular, $plural, $number); } }
public static function domainGet($domain, $singular, $plural, $count = 1, $fallbackSingular = null, $fallbackPlural = null) { $count = abs($count); if (!\extension_loaded('gettext')) { return static::onMissingGettext($singular, $plural, $count, $fallbackSingular, $fallbackPlural); } if (!$domain && trim($domain) === '') { $domain = self::current()->getDomain(); } $translated = dngettext($domain, $singular, $plural, $count); return static::processTranslated($domain, $translated, $singular, $plural, $count, $fallbackSingular, $fallbackPlural); }
/** * {@inheritdoc} * * @param string $msgid1 * @param string $msgid2 * @param integer $count * @param array $placeholders * @param string $domain * @return string */ public function nquery($msgid1, $msgid2, $count, $placeholders = null, $domain = null) { if (!is_int($count) || $count < 0) { throw new \InvalidArgumentException("Count must be a nonnegative integer. {$count} given."); } if ($domain === null) { $translation = ngettext($msgid1, $msgid2, $count); } else { $translation = dngettext($domain, $msgid1, $msgid2, $count); } if (is_array($placeholders)) { foreach ($placeholders as $key => $value) { $translation = str_replace('%' . $key . '%', $value, $translation); } } return $translation; }
/** * Override the current domain in a context ngettext call. * * @param string $domain * @param string $context * @param string $msgid1 * @param string $msgid2 * @param int $n * @return string */ public function dNPGetText($domain, $context, $msgid1, $msgid2, $n) { if ($this->driver->hasLocaleAndFunction('dngettext')) { $context_id = "{$context}{$msgid1}"; $translation = dngettext($domain, $context_id, $msgid2, $n); if ($translation == $context_id || $translation == $msgid2) { return $n == 1 ? $msgid1 : $msgid2; } return $translation; } return $this->driver->dNPGetText($domain, $context, $msgid1, $msgid2, $n); }
public function userSignup() { if (!$this->signup->sheet->id) { PHPWS_Core::errorPage('404'); } $sheet = $this->signup->sheet; $peep = $this->signup->peep; if (Current_User::isLogged() && empty($peep->email)) { $peep->email = Current_User::getEmail(); } if ($sheet->end_time < time()) { $this->signup->title = dgettext('signup', 'Sorry'); $this->signup->content = dgettext('signup', 'We are no longer accepting applications.'); return; } $slots = $sheet->getAllSlots(); $slots_filled = $sheet->totalSlotsFilled(); if (empty($slots)) { $this->signup->title = dgettext('signup', 'Sorry'); $this->signup->content = dgettext('signup', 'There is a problem with this signup sheet. Please check back later.'); return; } $this->signup->title =& $sheet->title; foreach ($slots as $slot) { // if the slots are filled, don't offer it if ($slots_filled && isset($slots_filled[$slot->id])) { $filled =& $slots_filled[$slot->id]; if ($filled >= $slot->openings) { continue; } else { $openings_left = $slot->openings - $filled; } } else { $openings_left =& $slot->openings; } $options[$slot->id] = sprintf(dngettext('signup', '%s (%s opening)', '%s (%s openings)', $openings_left), $slot->title, $openings_left); } if (!isset($options)) { $this->signup->content = dgettext('signup', 'Sorry, but all available slots are full. Please check back later for possible cancellations.'); return; } else { $form = new PHPWS_Form('slots'); $form->useFieldset(); $form->setLegend(dgettext('signup', 'Signup form')); $form->addHidden('module', 'signup'); $form->addHidden('uop', 'slot_signup'); $form->addHidden('sheet_id', $this->signup->sheet->id); $form->addSelect('slot_id', $options); $form->setLabel('slot_id', dgettext('signup', 'Available slots')); $form->setMatch('slot_id', $peep->slot_id); $form->addText('first_name', $peep->first_name); $form->setLabel('first_name', dgettext('signup', 'First name')); $form->addText('last_name', $peep->last_name); $form->setLabel('last_name', dgettext('signup', 'Last name')); $form->addText('email', $peep->email); $form->setSize('email', 30); $form->setLabel('email', dgettext('signup', 'Email address')); $form->addText('phone', $peep->getPhone()); $form->setSize('phone', 15); $form->setLabel('phone', dgettext('signup', 'Phone number')); if (!empty($this->signup->sheet->extra1)) { $form->addText('extra1', $peep->extra1); $form->setLabel('extra1', $this->signup->sheet->extra1); } if (!empty($this->signup->sheet->extra2)) { $form->addText('extra2', $peep->extra2); $form->setLabel('extra2', $this->signup->sheet->extra2); } if (!empty($this->signup->sheet->extra3)) { $form->addText('extra3', $peep->extra3); $form->setLabel('extra3', $this->signup->sheet->extra3); } $form->addSubmit(dgettext('signup', 'Submit')); $tpl = $form->getTemplate(); } $tpl['DESCRIPTION'] = $sheet->getDescription(); $this->signup->content = PHPWS_Template::process($tpl, 'signup', 'signup_form.tpl'); $this->signup->sheet->flag(); }
/** * @see TranslatorInterface * * {@inheritdoc} */ public function dnpgettext($domain, $context, $original, $plural, $value) { $message = $context . "" . $original; $translation = dngettext($domain, $message, $plural, $value); return $translation === $message ? $original : $translation; }
public static function ngettext($singular_message, $plural_message, $number) { return dngettext(Blorg::GETTEXT_DOMAIN, $singular_message, $plural_message, $number); }
function validatePost($post) { global $fmdb, $__FM_CONFIG; if (empty($post['time_name'])) { return __('No name defined.'); } /** Check name field length */ $field_length = getColumnLength('fm_' . $__FM_CONFIG[$_SESSION['module']]['prefix'] . 'time', 'time_name'); if ($field_length !== false && strlen($post['time_name']) > $field_length) { return sprintf(dngettext($_SESSION['module'], 'Name is too long (maximum %d character).', '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'] . 'time', $post['time_name'], 'time_', 'time_name', "AND time_id!={$post['time_id']}"); if ($fmdb->num_rows) { return __('This name already exists.'); } /** Process time */ $post['time_start_time'] = $post['time_start_time_hour'] . ':' . $post['time_start_time_min']; $post['time_end_time'] = $post['time_end_time_hour'] . ':' . $post['time_end_time_min']; /** Process weekdays */ if (@is_array($post['time_weekdays'])) { $decimals = 0; foreach ($post['time_weekdays'] as $dec => $checked) { $decimals += $dec; } $post['time_weekdays'] = $decimals; } else { $post['time_weekdays'] = 0; } /** Process dates */ if (empty($post['time_start_date'])) { unset($post['time_start_date']); } if (empty($post['time_end_date'])) { unset($post['time_end_date']); } return $post; }
/** * 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 validatePost($post) { global $fmdb, $__FM_CONFIG; if (empty($post['object_name'])) { return __('No object name defined.'); } if (empty($post['object_address'])) { return __('No object address defined.'); } if ($post['object_type'] == 'network') { if (empty($post['object_mask'])) { return __('No object netmask defined.'); } } /** Check name field length */ $field_length = getColumnLength('fm_' . $__FM_CONFIG[$_SESSION['module']]['prefix'] . 'objects', 'object_name'); if ($field_length !== false && strlen($post['object_name']) > $field_length) { return sprintf(dngettext($_SESSION['module'], 'Object name is too long (maximum %d character).', 'Object 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'] . 'objects', $post['object_name'], 'object_', 'object_name', "AND object_type='{$post['object_type']}' AND object_id!={$post['object_id']}"); if ($fmdb->num_rows) { return __('This object name already exists.'); } /** Check address and mask */ if (!verifyIPAddress($post['object_address'])) { return __('Address is invalid.'); } if ($post['object_type'] == 'network') { if (!verifyIPAddress($post['object_mask'])) { return __('Netmask is invalid.'); } } return $post; }