本文整理汇总了PHP中__n函数的典型用法代码示例。如果您正苦于以下问题:PHP __n函数的具体用法?PHP __n怎么用?PHP __n使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了__n函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: subscribe
/**
* Subscribe to a Premium offer.
*
* @return \Cake\Network\Response
*/
public function subscribe()
{
$this->loadComponent('Transaction');
$this->loadModel('PremiumOffers');
$this->loadModel('PremiumDiscounts');
$offer = $this->PremiumOffers->find('offerByPeriod', ['period' => $this->request->data['period']]);
if (!$offer) {
$this->Flash->error(__("This offer does not exist."));
return $this->redirect(['action' => 'index']);
}
//Check the discount code.
$discountPercentage = null;
if (!empty($this->request->data['discount'])) {
$discount = $this->PremiumDiscounts->find('discountByCodeAndOffer', ['code' => $this->request->data['discount'], 'offer_id' => $offer->id]);
if (is_null($discount) || !$this->PremiumDiscounts->isDiscountValid($discount)) {
$this->Flash->error(__("Your discount code isn't valid or has already been used."));
return $this->redirect(['action' => 'index']);
} else {
$discountPercentage = $discount->discount;
}
}
$price = Number::format($offer->price, ['locale' => 'en_US']);
$tax = Number::format($offer->tax, ['locale' => 'en_US']);
$custom = ['user_id' => $this->request->session()->read('Auth.User.id'), 'offer_id' => $offer->id, 'period' => $offer->period, 'discount_id' => isset($discount) ? $discount->id : null];
$paypalUrl = $this->Transaction->getPaypalUrl($price, $tax, __n('Premium {0} month', 'Premium {0} months', $offer->period, $offer->period), http_build_query($custom), $discountPercentage);
if (!$paypalUrl) {
$this->Flash->error(__("Unable to get the Paypal URL, please contact an administrator or try again later."));
return $this->redirect(['action' => 'index']);
}
$this->redirect($paypalUrl);
}
示例2: beforeRender
public function beforeRender()
{
parent::beforeRender();
$breadcrumbs = array(array('link' => Router::url(array('controller' => 'pages', 'action' => 'index')), 'text' => __('Home'), 'active' => ''), array('link' => Router::url(array('controller' => 'condos', 'action' => 'index')), 'text' => __n('Condo', 'Condos', 2), 'active' => ''), array('link' => Router::url(array('controller' => 'condos', 'action' => 'view', $this->getPhkRequestVar('condo_id'))), 'text' => $this->getPhkRequestVar('condo_text'), 'active' => ''), array('link' => '', 'text' => __('Drafts'), 'active' => 'active'));
$headerTitle = __('Drafts');
$this->set(compact('breadcrumbs', 'headerTitle'));
}
示例3: getDiff
/**
* Returns a fuzzy time difference as 'nearly x units' or 'over x units'
*
* @param string $dateFrom From datetime in 'YYYY-MM-DD HH:MM:SS' format
* @param string $dateTo To datetime in 'YYYY-MM-DD HH:MM:SS' format
* @return string
* @access public
* @static
* @note first parameter show be smaller than second parameter.
* dates should be in this format 'yyyy-mm-dd 00:00:00' (time optional)
*/
public static function getDiff($dateFrom, $dateTo = null)
{
$dateTo = ($dateTo === null) ? date('Y-m-d H:i:s') : $dateTo;
$from = self::_isValidDate($dateFrom);
$to = self::_isValidDate($dateTo);
if ($from && $to)
{
$dateDiff = self::_getDiff($from, $to);
$dd['years'] = $dateDiff / YEAR;
$dd['months'] = $dateDiff / MONTH;
$dd['weeks'] = $dateDiff / WEEK;
$dd['days'] = $dateDiff / DAY;
$dd['hours'] = $dateDiff / HOUR;
$dd['minutes'] = $dateDiff / MINUTE;
$dd['seconds'] = $dateDiff;
foreach ($dd as $period => $amt)
{
$whole = floor($amt);
$fract = $amt - $whole;
if ($whole >= 1 || $fract >= 0.94)
{
if ($fract >= 0.94)
{
return (__('almost', true) . " " . ($whole + 1) . " "
. __n(rtrim($period, "s"), $period, $whole + 1, true));
}
return (__("over ", true) . $whole . " "
. __n(rtrim($period, "s"), $period, $whole, true));
}
}
}
return "";
}
示例4: _setMenu
/**
* set menu items
*
* @return void
* @access protected
* @throws
*/
protected function _setMenu()
{
$menuItems = array('Aros', 'AccessUsers');
$translationDomain = 'access';
$this->set(compact('menuItems', 'translationDomain'));
$this->set('title_for_layout', __d('access', 'Access Setup'));
$this->set('user_at_string', __n('User', 'Users', 1) . ' ' . $this->Session->read('Auth.User.name') . ' @ ' . __d('access', 'Access Setup'));
}
示例5: index
public function index()
{
$page = isset($this->params['page']) ? (int) $this->params['page'] : 1;
$perPage = 20;
$pagination = $this->User->paginate($page, $perPage);
$pagination['url'] = Router::getRoute('adminUserPaged');
$this->data->set('pagination', $pagination);
$this->data->set('Users', $this->User->findAll(array('offset' => ($page - 1) * $perPage, 'limit' => $perPage)));
$this->data->set('pageTitle', __n(':1 Benutzer', ':1 Benutzer', $pagination['total']));
}
示例6: minutes_to_hours
public function minutes_to_hours($minutes)
{
if ($minutes <= 60) {
return sprintf(__n("%d minute", "%d minutes", $minutes), $minutes);
} else {
$hours = floor($minutes / 60);
$mins = $minutes - $hours * 60;
$mins = str_pad($mins, 2, "0", STR_PAD_LEFT);
return sprintf(__n("%d h", "%d h", $hours), $hours) . ' ' . sprintf(__n("%s", "%s", $mins), $mins);
}
}
示例7: index
public function index()
{
$this->BlogPost->unbind('Tag');
$page = @$this->params['page'] or 1;
$BlogPosts = $this->BlogPost->findAll(array('offset' => ($page - 1) * $this->BlogPost->perPage, 'limit' => $this->BlogPost->perPage, 'depth' => 1));
$this->data->set('BlogPosts', $BlogPosts);
$pagination = $this->BlogPost->paginate($page, $this->BlogPost->perPage);
$pagination['url'] = Router::getRoute('adminBlogPostPaged');
$this->data->set('pagination', $pagination);
// page title
$this->data->set('pageTitle', __n(':1 Blogeintrag', ':1 Blogeinträge', $pagination['total']));
}
示例8: beforeRender
/**
* beforeRender callback
*
* @param
* @return
* @access public
* @throws
*/
public function beforeRender()
{
$this->set('title_for_layout', '');
$this->theme = Configure::read('Application.theme');
$this->set('unread_notifications', $this->Notify->countNotifications(AuthComponent::user('id')));
$this->set('user_at_string', __n('User', 'Users', 1) . ' ' . $this->Session->read('Auth.User.name') . ' @ ' . __('pHkapa'));
// if is set layout for error , clear menuItems
if ($this->_setErrorLayout()) {
$menuItems = array();
$this->set(compact('menuItems'));
}
}
示例9: set_crumb
function set_crumb($action = null, $controller = null)
{
if ($action == null) {
$action = $this->controller->action;
}
if ($controller == null) {
$controller = $this->controller->name;
}
// Only return a crumb if the language value is assigned something.
$language_format = __('% ' . $action, true);
if ($language_format != '% ' . $action) {
return sprintf($language_format, __n($controller, $controller, 1, true));
}
}
示例10: testSubstitutionPlural
/**
* testSubstitutionPlural
*
* @return void
*/
public function testSubstitutionPlural()
{
$return = __n('single', 'plural {number}', 1);
$this->assertSame('single', $return);
$return = __n('single', 'plural {number}', 0);
$this->assertSame('plural 0', $return);
$return = __n('single', 'plural {number}', 2);
$this->assertSame('plural 2', $return);
$return = __n('single {color}', 'plural {number} {color}', 1, array('color' => 'blue'));
$this->assertSame('single blue', $return);
$return = __n('single {color}', 'plural {number} {color}', 0, array('color' => 'blue'));
$this->assertSame('plural 0 blue', $return);
$return = __n('single {color}', 'plural {number} {color}', 2, array('color' => 'blue'));
$this->assertSame('plural 2 blue', $return);
}
示例11: toReadableSize
/**
* Returns a formatted-for-humans file size.
*
* @param integer $size Size in bytes
*
* @return string Human readable size
*
* @since 1.0.0
*/
public function toReadableSize($size)
{
switch (true) {
case $size < 1024:
return sprintf(__n('%d Byte', '%d Bytes', $size, true), $size);
case round($size / 1024) < 1024:
return sprintf(__('%d KB', true), $this->precision($size / 1024, 0));
case round($size / 1024 / 1024, 2) < 1024:
return sprintf(__('%.2f MB', true), $this->precision($size / 1024 / 1024, 2));
case round($size / 1024 / 1024 / 1024, 2) < 1024:
return sprintf(__('%.2f GB', true), $this->precision($size / 1024 / 1024 / 1024, 2));
default:
return sprintf(__('%.2f TB', true), $this->precision($size / 1024 / 1024 / 1024 / 1024, 2));
}
}
示例12: duration
static function duration($duration)
{
$ret = array();
$days = floor($duration / 1440);
if ($days) {
$duration -= $days * 1440;
$ret[] = $days . ' ' . __n('day', 'days', $days, true);
}
$hours = floor($duration / 60);
if ($hours) {
$duration -= $hours * 60;
$ret[] = $hours . ' ' . __n('hour', 'hours', $hours, true);
}
if ($duration || empty($ret)) {
$ret[] = $duration . ' ' . __n('minute', 'minutes', $duration, true);
}
return implode(', ', $ret);
}
示例13: display
public function display($likes, $userKey = 'username')
{
$n = count($likes);
if ($n > 0) {
if ($n == 1) {
$like = $likes[0];
$text = $this->Html->link($like['User'][$userKey], array('controller' => 'users', 'action' => 'view', $like['User']['id']));
} else {
if ($n > 1) {
$users = array();
foreach ($likes as $like) {
$users[] = $like['User'][$userKey];
}
$text = $this->Html->link(__n('%s people', '%s people', $n, $n), '#', array('title' => $this->Text->toList($users, __('and'))));
}
}
echo __dn('like', '%s liked this.', '%s liked this.', $n, $text);
}
}
示例14: add
public function add()
{
$this->viewBuilder()->layout('json');
// Ensure user doesn't exceed picture limit
$userId = $this->Auth->user('id');
$currentCount = $this->Pictures->getCountForUser($userId);
$maxPicturesPerUser = Configure::read('maxPicturesPerUser');
if ($currentCount >= $maxPicturesPerUser) {
$msg = 'Sorry, you\'ve reached your limit of ' . $maxPicturesPerUser . __n(' picture', ' pictures', $maxPicturesPerUser);
throw new ForbiddenException($msg);
}
$picture = $this->Pictures->newEntity();
if ($this->request->is('post')) {
$this->request->data['filename'] = $this->request->data('Filedata');
$this->request->data['is_primary'] = false;
$this->request->data['user_id'] = $userId;
$picture = $this->Pictures->patchEntity($picture, $this->request->data);
if ($picture->errors()) {
$exceptionMsg = 'There was an error uploading that picture. Please try again.';
$exceptionMsg .= '<ul>';
foreach ($picture->errors() as $field => $errors) {
foreach ($errors as $label => $message) {
$exceptionMsg .= '<li>' . $message . '</li>';
}
}
$exceptionMsg .= '</ul>';
throw new BadRequestException($exceptionMsg);
} else {
$picture = $this->Pictures->save($picture);
if ($picture) {
$message = 'Picture successfully uploaded';
$this->set(['message' => $message, 'picture' => $picture->filename, 'pictureId' => $picture->id]);
} else {
$msg = 'There was an error uploading that picture. Please try again.';
throw new InternalErrorException($msg);
}
}
} else {
throw new BadRequestException('No picture was uploaded');
}
$this->set('_serialize', ['message', 'picture', 'pictureId']);
}
示例15: smarty_modifier_agestring
/**
* agestring smarty modifier
*
* @param int $age age in seconds
* @return string human readable string
*/
function smarty_modifier_agestring($age)
{
if ($age > 60 * 60 * 24 * 365 * 2) {
$years = (int) ($age / 60 / 60 / 24 / 365);
return sprintf(__n('%1$d year ago', '%1$d years ago', $years), $years);
} else {
if ($age > 60 * 60 * 24 * (365 / 12) * 2) {
$months = (int) ($age / 60 / 60 / 24 / (365 / 12));
return sprintf(__n('%1$d month ago', '%1$d months ago', $months), $months);
} else {
if ($age > 60 * 60 * 24 * 7 * 2) {
$weeks = (int) ($age / 60 / 60 / 24 / 7);
return sprintf(__n('%1$d week ago', '%1$d weeks ago', $weeks), $weeks);
} else {
if ($age > 60 * 60 * 24 * 2) {
$days = (int) ($age / 60 / 60 / 24);
return sprintf(__n('%1$d day ago', '%1$d days ago', $days), $days);
} else {
if ($age > 60 * 60 * 2) {
$hours = (int) ($age / 60 / 60);
return sprintf(__n('%1$d hour ago', '%1$d hours ago', $hours), $hours);
} else {
if ($age > 60 * 2) {
$min = (int) ($age / 60);
return sprintf(__n('%1$d min ago', '%1$d min ago', $min), $min);
} else {
if ($age > 2) {
$sec = (int) $age;
return sprintf(__n('%1$d sec ago', '%1$d sec ago', $sec), $sec);
}
}
}
}
}
}
}
return __('right now');
}