本文整理汇总了PHP中Zend_Translate::plural方法的典型用法代码示例。如果您正苦于以下问题:PHP Zend_Translate::plural方法的具体用法?PHP Zend_Translate::plural怎么用?PHP Zend_Translate::plural使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend_Translate
的用法示例。
在下文中一共展示了Zend_Translate::plural方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: numCount
/**
* Test the password for minimum number of numeric characters.
*
* @param mixed $parameter
* @param string $password
*/
protected function numCount($parameter, $password)
{
$len = intval($parameter);
if ($len) {
$results = array();
// Not used but required
$count = preg_match_all('/[0-9]/', $password, $results);
if ($len > 0 && $count < $len) {
$this->_addError(sprintf($this->translate->plural('should contain at least one number', 'should contain at least %d numbers', $len), $len));
} elseif ($len < 0 && ($count > 0 || null === $password)) {
$this->_addError($this->translate->_('may not contain numbers'));
}
}
}
示例2: testGettingPluralsUsingOwnRule
/**
* Tests getting plurals from lowered locale
*/
public function testGettingPluralsUsingOwnRule()
{
$lang = new Zend_Translate(Zend_Translate::AN_ARRAY, array('singular' => array('plural_0 (en)', 'plural_1 (en)', 'plural_2 (en)', 'plural_3 (en)'), 'plural' => ''), 'en');
$lang->addTranslation(array('msg1' => 'Message 1 (ru)'), 'en_US');
$lang->setLocale('en_US');
Zend_Translate_Plural::setPlural(array($this, 'customPlural'), 'en_US');
$this->assertEquals('plural_1 (en)', $lang->translate(array('singular', 'plural', 1)));
$this->assertEquals('plural_1 (en)', $lang->plural('singular', 'plural', 1));
$this->assertEquals('plural_1 (en)', $lang->translate(array('singular', 'plural', 0)));
$this->assertEquals('plural_1 (en)', $lang->plural('singular', 'plural', 0));
}
示例3: tokenMailFields
/**
* Returns an array of {field_names} => values for this token for
* use in an e-mail tamplate.
*
* @param array $tokenData
* @return array
*/
public function tokenMailFields()
{
if ($this->token) {
$locale = $this->respondent->getLanguage();
$survey = $this->token->getSurvey();
// Count todo
$tSelect = $this->loader->getTracker()->getTokenSelect(array('all' => 'COUNT(*)', 'track' => $this->db->quoteInto('SUM(CASE WHEN gto_id_respondent_track = ? THEN 1 ELSE 0 END)', $this->token->getRespondentTrackId())));
$tSelect->andSurveys(array())->forRespondent($this->token->getRespondentId(), $this->organizationId)->forGroupId($survey->getGroupId())->onlyValid();
$todo = $tSelect->fetchRow();
// Set the basic fields
$result['round'] = $this->token->getRoundDescription();
$organizationLoginUrl = $this->organization->getLoginUrl();
$result['site_ask_url'] = $organizationLoginUrl . '/ask/';
// Url's
$url = $organizationLoginUrl . '/ask/forward/' . \MUtil_Model::REQUEST_ID . '/';
$url .= $this->token->getTokenId();
$urlInput = $result['site_ask_url'] . 'index/' . \MUtil_Model::REQUEST_ID . '/' . $this->token->getTokenId();
$result['survey'] = $survey->getName();
$result['todo_all'] = sprintf($this->translate->plural('%d survey', '%d surveys', $todo['all'], $locale), $todo['all']);
$result['todo_all_count'] = $todo['all'];
$result['todo_track'] = sprintf($this->translate->plural('%d survey', '%d surveys', $todo['track'], $locale), $todo['track']);
$result['todo_track_count'] = $todo['track'];
$result['token'] = strtoupper($this->token->getTokenId());
$result['token_from'] = \MUtil_Date::format($this->token->getValidFrom(), \Zend_Date::DATE_LONG, 'yyyy-MM-dd', $locale);
$result['token_link'] = '[url=' . $url . ']' . $survey->getName() . '[/url]';
$result['token_until'] = \MUtil_Date::format($this->token->getValidUntil(), \Zend_Date::DATE_LONG, 'yyyy-MM-dd', $locale);
$result['token_url'] = $url;
$result['token_url_input'] = $urlInput;
$result['track'] = $this->token->getTrackName();
// Add the code fields
$codes = $this->token->getRespondentTrack()->getCodeFields();
foreach ($codes as $code => $data) {
$key = 'track.' . $code;
if (is_array($data)) {
$data = implode(' ', $data);
}
$result[$key] = $data;
}
if ($this->token->hasRelation()) {
$allFields = $this->getMailFields(false);
// Set about to patient name
$results['relation_about'] = $allFields['name'];
$results['relation_about_first_name'] = $allFields['first_name'];
$results['relation_about_full_name'] = $allFields['full_name'];
$results['relation_about_greeting'] = $allFields['greeting'];
$results['relation_about_last_name'] = $allFields['last_name'];
$results['relation_field_name'] = $this->token->getRelationFieldName();
if ($relation = $this->token->getRelation()) {
// Now update all respondent fields to be of the relation
$results['name'] = $relation->getName();
$results['first_name'] = $relation->getFirstName();
$results['last_name'] = $relation->getLastName();
$results['full_name'] = $relation->getHello($locale);
$results['greeting'] = $relation->getGreeting($locale);
$results['to'] = $relation->getEmail();
$this->addTo($results['to'], $results['name']);
} else {
$results['name'] = $this->translate->getAdapter()->_('Undefined relation');
$results['first_name'] = '';
$results['last_name'] = '';
$results['full_name'] = '';
$results['greeting'] = '';
$results['to'] = '';
}
} else {
$results['relation_about'] = $this->translate->getAdapter()->_('yourself', $this->token->getRespondentLanguage());
$results['relation_about_first_name'] = '';
$results['relation_about_full_name'] = '';
$results['relation_about_greeting'] = '';
$results['relation_about_last_name'] = '';
$results['relation_field_name'] = '';
}
} else {
$result['round'] = '';
$result['site_ask_url'] = '';
$result['survey'] = '';
$result['todo_all'] = '';
$result['todo_all_count'] = '';
$result['todo_track'] = '';
$result['todo_track_count'] = '';
$result['token'] = '';
$result['token_from'] = '';
$result['token_link'] = '';
$result['token_until'] = '';
$result['token_url'] = '';
$result['token_url_input'] = '';
$result['track'] = '';
$result['relation_about'] = $this->translate->getAdapter()->_('yourself');
$result['relation_about_first_name'] = '';
$result['relation_about_full_name'] = '';
$result['relation_about_greeting'] = '';
$result['relation_about_last_name'] = '';
$result['relation_field_name'] = '';
//.........这里部分代码省略.........
示例4: testTranslationHundSingular
public function testTranslationHundSingular()
{
$path = dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . 'TestFiles' . DIRECTORY_SEPARATOR;
$translate = new Zend_Translate('gettextPo', $path, 'en');
$this->assertEquals("Dog", $translate->plural("Hund", "hunde", 1, "en"), 'Wrong translation!');
}
示例5: testTranslationPluralWithPlural
public function testTranslationPluralWithPlural()
{
$path = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'TestFiles' . DIRECTORY_SEPARATOR;
$translate = new Zend_Translate('gettextPo', $path, 'en');
$this->assertEquals("Dog", $translate->plural("Hund", "hunde", 1, "en"), 'Translating singular of a plural with pluralfunction');
}
示例6: diffReadable
/**
* Returns the difference between this date and the given $date
*
* It will always round to the biggest period, so 8 days ago will result in 1 week ago
* while 13 days ago will result in 2 weeks ago.
*
* @param \Zend_Date $date
* @param \Zend_Translate $translate
* @return string
*/
public function diffReadable(\Zend_Date $date, \Zend_Translate $translate)
{
$difference = $date->getUnixTimeStamp() - $this->getUnixTimestamp();
//second, minute, hour, day, week, month, year, decade
$lengths = array("60", "60", "24", "7", "4.34", "12", "10");
if ($difference > 0) {
// this was in the past
$ending = $translate->_("%s ago");
} else {
// this was in the future
$difference = -$difference;
$ending = $translate->_("%s to go");
}
for ($j = 0; $j < 7 && $difference >= $lengths[$j]; $j++) {
$difference /= $lengths[$j];
}
$difference = round($difference);
switch ($j) {
case 0:
$period = $translate->plural('second', 'seconds', $difference);
break;
case 1:
$period = $translate->plural('minute', 'minutes', $difference);
break;
case 2:
$period = $translate->plural('hour', 'hours', $difference);
break;
case 3:
$period = $translate->plural('day', 'days', $difference);
break;
case 4:
$period = $translate->plural('week', 'weeks', $difference);
break;
case 5:
$period = $translate->plural('month', 'months', $difference);
break;
case 6:
$period = $translate->plural('year', 'years', $difference);
break;
case 7:
$period = $translate->plural('decade', 'decades', $difference);
break;
default:
break;
}
$time = "{$difference} {$period}";
$text = sprintf($ending, $time);
return $text;
}