当前位置: 首页>>代码示例>>PHP>>正文


PHP format_plural函数代码示例

本文整理汇总了PHP中format_plural函数的典型用法代码示例。如果您正苦于以下问题:PHP format_plural函数的具体用法?PHP format_plural怎么用?PHP format_plural使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了format_plural函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: generateElements

 /**
  * {@inheritdoc}
  */
 protected function generateElements(array $values)
 {
     $num = $values['num'];
     $kill = $values['kill'];
     $pass = $values['pass'];
     $age = $values['time_range'];
     $roles = $values['roles'];
     $url = parse_url($GLOBALS['base_url']);
     if ($kill) {
         $uids = db_select('users', 'u')->fields('u', array('uid'))->condition('uid', 1, '>')->execute()->fetchAllAssoc('uid');
         user_delete_multiple(array_keys($uids));
         $this->setMessage(\Drupal::translation()->formatPlural(count($uids), '1 user deleted', '@count users deleted.'));
     }
     if ($num > 0) {
         $names = array();
         while (count($names) < $num) {
             //@todo add suport for devel_generate_word(mt_rand(6, 12)) in a class method
             $name = $this->generateWord(mt_rand(6, 12));
             $names[$name] = '';
         }
         if (empty($roles)) {
             $roles = array(DRUPAL_AUTHENTICATED_RID);
         }
         foreach ($names as $name => $value) {
             $edit = array('uid' => NULL, 'name' => $name, 'pass' => $pass, 'mail' => $name . '@example.com', 'status' => 1, 'created' => REQUEST_TIME - mt_rand(0, $age), 'roles' => array_combine($roles, $roles), 'devel_generate' => TRUE);
             $account = entity_create('user', $edit);
             // Populate all fields with sample values.
             $this->populateFields($account);
             $account->save();
         }
     }
     $this->setMessage(t('!num_users created.', array('!num_users' => format_plural($num, '1 user', '@count users'))));
 }
开发者ID:anatalsceo,项目名称:en-classe,代码行数:36,代码来源:UserDevelGenerate.php

示例2: update_script_selection_form

function update_script_selection_form($form, &$form_state)
{
    $count = 0;
    $form['start'] = array('#tree' => TRUE, '#type' => 'fieldset', '#collapsed' => TRUE, '#collapsible' => TRUE);
    // Ensure system.module's updates appear first
    $form['start']['system'] = array();
    $updates = update_get_update_list();
    foreach ($updates as $module => $update) {
        if (!isset($update['start'])) {
            $form['start'][$module] = array('#title' => $module, '#item' => $update['warning'], '#prefix' => '<div class="warning">', '#suffix' => '</div>');
            continue;
        }
        if (!empty($update['pending'])) {
            $form['start'][$module] = array('#type' => 'hidden', '#value' => $update['start']);
            $form['start'][$module . '_updates'] = array('#markup' => theme('item_list', array('items' => $update['pending'], 'title' => $module . ' module')));
        }
        if (isset($update['pending'])) {
            $count = $count + count($update['pending']);
        }
    }
    if (empty($count)) {
        drupal_set_message(t('No pending updates.'));
        unset($form);
        $form['links'] = array('#markup' => theme('item_list', array('items' => update_helpful_links())));
    } else {
        $form['help'] = array('#markup' => '<p>The version of Drupal you are updating from has been automatically detected.</p>', '#weight' => -5);
        $form['start']['#title'] = format_plural($count, '1 pending update', '@count pending updates');
        $form['has_js'] = array('#type' => 'hidden', '#default_value' => FALSE);
        $form['submit'] = array('#type' => 'submit', '#value' => 'Apply pending updates');
    }
    return $form;
}
开发者ID:berkes,项目名称:sympal,代码行数:32,代码来源:update.php

示例3: format_interval

/**
 * Format a time interval with the requested granularity.
 *
 * @param $timestamp
 *   The length of the interval in seconds.
 * @param $granularity
 *   How many different units to display in the string.
 * @param $langcode
 *   Optional language code to translate to a language other than
 *   what is used to display the page.
 * @return
 *   A translated string representation of the interval.
 */
function format_interval($timestamp, $granularity = 2, $langcode = NULL) {
  $units = array(
    '1 year|@count years' => 31536000,
    '1 month|@count months' => 2592000,
    '1 week|@count weeks' => 604800,
    '1 day|@count days' => 86400,
    '1 hour|@count hours' => 3600,
    '1 min|@count min' => 60,
    '1 sec|@count sec' => 1
  );
  $output = '';
  foreach ($units as $key => $value) {
    $key = explode('|', $key);
    if ($timestamp >= $value) {
      $output .= ($output ? ' ' : '') . format_plural(floor($timestamp / $value), $key[0], $key[1], array(), array('langcode' => $langcode));
      $timestamp %= $value;
      $granularity--;
    }

    if ($granularity == 0) {
      break;
    }
  }
  return $output ? $output : t('0 sec', array(), array('langcode' => $langcode));
}
开发者ID:ryandao,项目名称:Facebook-Status-Time-Capsule,代码行数:38,代码来源:common.php

示例4: summaryTitle

 /**
  * Overrides \Drupal\views\Plugin\views\pager\PagerPluginBase::summaryTitle().
  */
 public function summaryTitle()
 {
     if (!empty($this->options['offset'])) {
         return format_plural($this->options['items_per_page'], '@count item, skip @skip', 'Paged, @count items, skip @skip', array('@count' => $this->options['items_per_page'], '@skip' => $this->options['offset']));
     }
     return format_plural($this->options['items_per_page'], '@count item', 'Paged, @count items', array('@count' => $this->options['items_per_page']));
 }
开发者ID:davidsoloman,项目名称:drupalconsole.com,代码行数:10,代码来源:Full.php

示例5: md_hosoren_facetapi_count

function md_hosoren_facetapi_count($variables)
{
    $count = (int) $variables['count'];
    $one_item = t('pc.');
    $more_items = t('pcs.');
    //pcs.
    $output = format_plural($count, '1 ' . $one_item, '@count ' . $more_items);
    return '<span class="facet-count">(' . $output . ')</span>';
}
开发者ID:aposidelov,项目名称:copfun1,代码行数:9,代码来源:template.php

示例6: buildForm

 /**
  * {@inheritdoc}
  */
 public function buildForm(array $form, FormStateInterface $form_state)
 {
     $filter_values = $this->translateFilterValues();
     $langcode = $filter_values['langcode'];
     $this->languageManager->reset();
     $languages = language_list();
     $langname = isset($langcode) ? $languages[$langcode]->name : "- None -";
     $form['#attached']['library'][] = 'locale/drupal.locale.admin';
     $form['langcode'] = array('#type' => 'value', '#value' => $filter_values['langcode']);
     $form['strings'] = array('#type' => 'item', '#tree' => TRUE, '#language' => $langname, '#theme' => 'locale_translate_edit_form_strings');
     if (isset($langcode)) {
         $strings = $this->translateFilterLoadStrings();
         $plural_formulas = $this->state->get('locale.translation.plurals') ?: array();
         foreach ($strings as $string) {
             // Cast into source string, will do for our purposes.
             $source = new SourceString($string);
             // Split source to work with plural values.
             $source_array = $source->getPlurals();
             $translation_array = $string->getPlurals();
             if (count($source_array) == 1) {
                 // Add original string value and mark as non-plural.
                 $form['strings'][$string->lid]['plural'] = array('#type' => 'value', '#value' => 0);
                 $form['strings'][$string->lid]['original'] = array('#type' => 'item', '#title' => $this->t('Source string (@language)', array('@language' => $this->t('Built-in English'))), '#title_display' => 'invisible', '#markup' => '<span lang="en">' . String::checkPlain($source_array[0]) . '</span>');
             } else {
                 // Add original string value and mark as plural.
                 $form['strings'][$string->lid]['plural'] = array('#type' => 'value', '#value' => 1);
                 $form['strings'][$string->lid]['original_singular'] = array('#type' => 'item', '#title' => $this->t('Singular form'), '#markup' => '<span lang="en">' . String::checkPlain($source_array[0]) . '</span>', '#prefix' => '<span class="visually-hidden">' . $this->t('Source string (@language)', array('@language' => $this->t('Built-in English'))) . '</span>');
                 $form['strings'][$string->lid]['original_plural'] = array('#type' => 'item', '#title' => $this->t('Plural form'), '#markup' => '<span lang="en">' . String::checkPlain($source_array[1]) . '</span>');
             }
             if (!empty($string->context)) {
                 $form['strings'][$string->lid]['context'] = array('#type' => 'value', '#value' => '<span lang="en">' . String::checkPlain($string->context) . '</span>');
             }
             // Approximate the number of rows to use in the default textarea.
             $rows = min(ceil(str_word_count($source_array[0]) / 12), 10);
             if (empty($form['strings'][$string->lid]['plural']['#value'])) {
                 $form['strings'][$string->lid]['translations'][0] = array('#type' => 'textarea', '#title' => $this->t('Translated string (@language)', array('@language' => $langname)), '#title_display' => 'invisible', '#rows' => $rows, '#default_value' => $translation_array[0], '#attributes' => array('lang' => $langcode));
             } else {
                 // Dealing with plural strings.
                 if (isset($plural_formulas[$langcode]['plurals']) && $plural_formulas[$langcode]['plurals'] > 2) {
                     // Add a textarea for each plural variant.
                     for ($i = 0; $i < $plural_formulas[$langcode]['plurals']; $i++) {
                         $form['strings'][$string->lid]['translations'][$i] = array('#type' => 'textarea', '#title' => $i == 0 ? $this->t('Singular form') : format_plural($i, 'First plural form', '@count. plural form'), '#rows' => $rows, '#default_value' => isset($translation_array[$i]) ? $translation_array[$i] : '', '#attributes' => array('lang' => $langcode), '#prefix' => $i == 0 ? '<span class="visually-hidden">' . $this->t('Translated string (@language)', array('@language' => $langname)) . '</span>' : '');
                     }
                 } else {
                     // Fallback for unknown number of plurals.
                     $form['strings'][$string->lid]['translations'][0] = array('#type' => 'textarea', '#title' => $this->t('Singular form'), '#rows' => $rows, '#default_value' => $translation_array[0], '#attributes' => array('lang' => $langcode), '#prefix' => '<span class="visually-hidden">' . $this->t('Translated string (@language)', array('@language' => $langname)) . '</span>');
                     $form['strings'][$string->lid]['translations'][1] = array('#type' => 'textarea', '#title' => $this->t('Plural form'), '#rows' => $rows, '#default_value' => isset($translation_array[1]) ? $translation_array[1] : '', '#attributes' => array('lang' => $langcode));
                 }
             }
         }
         if (count(Element::children($form['strings']))) {
             $form['actions'] = array('#type' => 'actions');
             $form['actions']['submit'] = array('#type' => 'submit', '#value' => $this->t('Save translations'));
         }
     }
     return $form;
 }
开发者ID:davidsoloman,项目名称:drupalconsole.com,代码行数:60,代码来源:TranslateEditForm.php

示例7: transChoice

 /**
  * Implements \Symfony\Component\Translation\TranslatorInterface::transChoice().
  */
 public function transChoice($id, $number, array $parameters = array(), $domain = NULL, $locale = NULL)
 {
     // Violation messages can separated singular and plural versions by "|".
     $ids = explode('|', $id);
     if (!isset($ids[1])) {
         throw new \InvalidArgumentException(sprintf('The message "%s" cannot be pluralized, because it is missing a plural (e.g. "There is one apple|There are @count apples").', $id));
     }
     return format_plural($number, $ids[0], $ids[1], $this->processParameters($parameters), $this->getOptions($domain, $locale));
 }
开发者ID:davidsoloman,项目名称:drupalconsole.com,代码行数:12,代码来源:DrupalTranslator.php

示例8: at_tf_admin_date_display_remaining

function at_tf_admin_date_display_remaining($variables)
{
    $remaining_days = $variables['remaining_days'];
    $output = '';
    $show_remaining_text = t(' (Less than 1 day remaining!)');
    if ($remaining_days) {
        $show_remaining_text = format_plural($remaining_days, ' (There is 1 day remaining!)', ' (There are @count days remaining.)');
    }
    return '<span class="date-display-remaining">' . $show_remaining_text . '</span>';
}
开发者ID:samknelson,项目名称:grievance,代码行数:10,代码来源:template.php

示例9: getDescription

 /**
  * {@inheritdoc}
  */
 public function getDescription()
 {
     $caption = '';
     $num_links = $this->menuLinkManager->countMenuLinks($this->entity->id());
     if ($num_links) {
         $caption .= '<p>' . format_plural($num_links, '<strong>Warning:</strong> There is currently 1 menu link in %title. It will be deleted (system-defined items will be reset).', '<strong>Warning:</strong> There are currently @count menu links in %title. They will be deleted (system-defined links will be reset).', array('%title' => $this->entity->label())) . '</p>';
     }
     $caption .= '<p>' . t('This action cannot be undone.') . '</p>';
     return $caption;
 }
开发者ID:anatalsceo,项目名称:en-classe,代码行数:13,代码来源:MenuDeleteForm.php

示例10: buildForm

 /**
  * {@inheritdoc}
  */
 public function buildForm(array $form, FormStateInterface $form_state)
 {
     $num_nodes = $this->queryFactory->get('node')->condition('type', $this->entity->id())->count()->execute();
     if ($num_nodes) {
         $caption = '<p>' . format_plural($num_nodes, '%type is used by 1 piece of content on your site. You can not remove this content type until you have removed all of the %type content.', '%type is used by @count pieces of content on your site. You may not remove %type until you have removed all of the %type content.', array('%type' => $this->entity->label())) . '</p>';
         $form['#title'] = $this->getQuestion();
         $form['description'] = array('#markup' => $caption);
         return $form;
     }
     return parent::buildForm($form, $form_state);
 }
开发者ID:davidsoloman,项目名称:drupalconsole.com,代码行数:14,代码来源:NodeTypeDeleteConfirm.php

示例11: buildForm

 /**
  * {@inheritdoc}
  */
 public function buildForm(array $form, FormStateInterface $form_state)
 {
     $blocks = $this->queryFactory->get('block_content')->condition('type', $this->entity->id())->execute();
     if (!empty($blocks)) {
         $caption = '<p>' . format_plural(count($blocks), '%label is used by 1 custom block on your site. You can not remove this block type until you have removed all of the %label blocks.', '%label is used by @count custom blocks on your site. You may not remove %label until you have removed all of the %label custom blocks.', array('%label' => $this->entity->label())) . '</p>';
         $form['description'] = array('#markup' => $caption);
         return $form;
     } else {
         return parent::buildForm($form, $form_state);
     }
 }
开发者ID:anatalsceo,项目名称:en-classe,代码行数:14,代码来源:BlockContentTypeDeleteForm.php

示例12: buildForm

 /**
  * {@inheritdoc}
  */
 public function buildForm(array $form, FormStateInterface $form_state)
 {
     $num_nodes = $this->database->query("SELECT COUNT(*) FROM {node} WHERE type = :type", array(':type' => $this->entity->id()))->fetchField();
     if ($num_nodes) {
         $caption = '<p>' . format_plural($num_nodes, '%type is used by 1 piece of content on your site. You can not remove this content type until you have removed all of the %type content.', '%type is used by @count pieces of content on your site. You may not remove %type until you have removed all of the %type content.', array('%type' => $this->entity->label())) . '</p>';
         $form['#title'] = $this->getQuestion();
         $form['description'] = array('#markup' => $caption);
         return $form;
     }
     return parent::buildForm($form, $form_state);
 }
开发者ID:anatalsceo,项目名称:en-classe,代码行数:14,代码来源:NodeTypeDeleteConfirm.php

示例13: mybasictheme_preprocess_node

function mybasictheme_preprocess_node(&$variables)
{
    // Check whether we have some comments present
    if (isset($variables['comment_count'])) {
        if ($variables['comment_count'] > 0) {
            // Add a new custom $commentlink variable
            $variables['commentlink'] = l(format_plural($variables['comment_count'], '1 comment', '@count comments'), drupal_lookup_path('alias', 'node/' . $variables['nid']), array('fragment' => 'comments'));
        }
    }
    // Re-write the $submitted variable the way we want it
    $variables['submitted'] = t('@datetime | by !username', array('!username' => $variables['name'], '@datetime' => date("j F Y", $variables['created'])));
}
开发者ID:adamstacey5,项目名称:drupal-7-training,代码行数:12,代码来源:template.php

示例14: busy_preprocess_node

/**
 * Override or insert variables into the node template.
 */
function busy_preprocess_node(&$vars)
{
    if ($vars['page'] && isset($vars['content']['links']['comment'])) {
        if (isset($vars['content']['links']['comment']['#links']['comment_add'])) {
            $vars['content']['links']['comment']['#links']['comments_count'] = $vars['content']['links']['comment']['#links']['comment_add'];
        }
        $vars['content']['links']['comment']['#links']['comments_count']['title'] = t('@num_comments', array('@num_comments' => format_plural($vars['comment_count'], '1 comment', '@count comments')));
        $vars['content']['links']['comment']['#links']['comments_count']['attributes'] = array();
    }
    if (theme_get_setting('toggle_node_user_picture', 'busy') && $vars['picture']) {
        $vars['classes_array'][] = 'node-with-author-picture';
    }
}
开发者ID:EclipseGc,项目名称:busy,代码行数:16,代码来源:template.php

示例15: mothership_preprocess_forum_list

function mothership_preprocess_forum_list(&$variables)
{
    global $user;
    $row = 0;
    $count = 0;
    $count2 = 0;
    // Sanitize each forum so that the template can safely print the data.
    foreach ($variables['forums'] as $id => $forum) {
        $variables['forums'][$id]->description = !empty($forum->description) ? filter_xss_admin($forum->description) : '';
        $variables['forums'][$id]->link = url("forum/{$forum->tid}");
        $variables['forums'][$id]->name = check_plain($forum->name);
        $variables['forums'][$id]->is_container = !empty($forum->container);
        $variables['forums'][$id]->zebra = $row % 2 == 0 ? 'odd' : 'even';
        $row++;
        //     $variables['forums'][$id]->depth == 1
        // make a count of the non container forums
        if ($variables['forums'][$id]->depth) {
            if (!$variables['forums'][$id]->is_container) {
                $variables['forums'][$id]->count = $count;
                $count++;
            }
        } else {
            if (!$variables['forums'][$id]->is_container) {
                $variables['forums'][$id]->count = $count2;
                $count2++;
            }
        }
        $variables['forums'][$id]->new_text = '';
        $variables['forums'][$id]->new_url = '';
        $variables['forums'][$id]->new_topics = 0;
        $variables['forums'][$id]->old_topics = $forum->num_topics;
        $variables['forums'][$id]->icon_class = 'default';
        $variables['forums'][$id]->icon_title = t('No new posts');
        if ($user->uid) {
            $variables['forums'][$id]->new_topics = _forum_topics_unread($forum->tid, $user->uid);
            if ($variables['forums'][$id]->new_topics) {
                $variables['forums'][$id]->new_text = format_plural($variables['forums'][$id]->new_topics, '1 new', '@count new');
                $variables['forums'][$id]->new_url = url("forum/{$forum->tid}", array('fragment' => 'new'));
                $variables['forums'][$id]->icon_class = 'new';
                $variables['forums'][$id]->icon_title = t('New posts');
            }
            $variables['forums'][$id]->old_topics = $forum->num_topics - $variables['forums'][$id]->new_topics;
        }
        $variables['forums'][$id]->last_reply = theme('forum_submitted', array('topic' => $forum->last_post));
    }
    // $tid = term id.
    if (isset($variables['tid'])) {
        $variables['forum_id'] = $variables['tid'];
        unset($variables['tid']);
    }
}
开发者ID:kieranbutler,项目名称:ikieran,代码行数:51,代码来源:forum.php


注:本文中的format_plural函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。