Commit aff95777 authored by alexpott's avatar alexpott
Browse files

Issue #2309737 by rpayanm, hussainweb, max-kuzomko, herom, millerbennett,...

Issue #2309737 by rpayanm, hussainweb, max-kuzomko, herom, millerbennett, ianthomas_uk, quietone, Sutharsan, sumitmadan, toddmbloom: Remove deprecated format_plural usage
parent f14ec035
......@@ -393,12 +393,12 @@ function format_xml_elements($array) {
*
* For example:
* @code
* $output = format_plural($node->comment_count, '1 comment', '@count comments');
* $output = \Drupal::translation()->formatPlural($node->comment_count, '1 comment', '@count comments');
* @endcode
*
* Example with additional replacements:
* @code
* $output = format_plural($update_count,
* $output = \Drupal::translation()->formatPlural($update_count,
* 'Changed the content type of 1 post from %old-type to %new-type.',
* 'Changed the content type of @count posts from %old-type to %new-type.',
* array('%old-type' => $info->old_type, '%new-type' => $info->new_type));
......@@ -451,7 +451,7 @@ function format_plural($count, $singular, $plural, array $args = array(), array
*/
function format_size($size, $langcode = NULL) {
if ($size < Bytes::KILOBYTE) {
return format_plural($size, '1 byte', '@count bytes', array(), array('langcode' => $langcode));
return \Drupal::translation()->formatPlural($size, '1 byte', '@count bytes', array(), array('langcode' => $langcode));
}
else {
$size = $size / Bytes::KILOBYTE; // Convert bytes to kilobytes.
......
......@@ -617,7 +617,7 @@ function template_preprocess_form_element_label(&$variables) {
* // The 'success' parameter means no fatal PHP errors were detected. All
* // other error management should be handled using 'results'.
* if ($success) {
* $message = format_plural(count($results), 'One post processed.', '@count posts processed.');
* $message = \Drupal::translation()->formatPlural(count($results), 'One post processed.', '@count posts processed.');
* }
* else {
* $message = t('Finished with an error.');
......
......@@ -41,7 +41,7 @@ public function parse($filename) {
}
$missing_keys = array_diff($this->getRequiredKeys(), array_keys(static::$parsedInfos[$filename]));
if (!empty($missing_keys)) {
$message = format_plural(count($missing_keys), 'Missing required key (!missing_keys) in !file.', 'Missing required keys (!missing_keys) in !file.', array('!missing_keys' => implode(', ', $missing_keys), '!file' => $filename));
$message = String::format('Missing required keys (!missing_keys) in !file.', array('!missing_keys' => implode(', ', $missing_keys), '!file' => $filename));
throw new InfoParserException($message);
}
if (isset(static::$parsedInfos[$filename]['version']) && static::$parsedInfos[$filename]['version'] === 'VERSION') {
......
......@@ -77,8 +77,8 @@ public function viewElements(FieldItemListInterface $items) {
if ($this->getSetting('prefix_suffix')) {
$prefixes = isset($settings['prefix']) ? array_map(array($this, 'fieldFilterXss'), explode('|', $settings['prefix'])) : array('');
$suffixes = isset($settings['suffix']) ? array_map(array($this, 'fieldFilterXss'), explode('|', $settings['suffix'])) : array('');
$prefix = (count($prefixes) > 1) ? format_plural($item->value, $prefixes[0], $prefixes[1]) : $prefixes[0];
$suffix = (count($suffixes) > 1) ? format_plural($item->value, $suffixes[0], $suffixes[1]) : $suffixes[0];
$prefix = (count($prefixes) > 1) ? $this->formatPlural($item->value, $prefixes[0], $prefixes[1]) : $prefixes[0];
$suffix = (count($suffixes) > 1) ? $this->formatPlural($item->value, $suffixes[0], $suffixes[1]) : $suffixes[0];
$output = $prefix . $output . $suffix;
}
// Output the raw value in a content attribute if the text of the HTML
......
......@@ -12,8 +12,8 @@
*
* Using this trait will add t() and formatPlural() methods to the class. These
* must be used for every translatable string, similar to how procedural code
* must use the global functions t() and format_plural(). This allows string
* extractor tools to find translatable strings.
* must use the global functions t() and \Drupal::translation()->formatPlural().
* This allows string extractor tools to find translatable strings.
*
* If the class is capable of injecting services from the container, it should
* inject the 'string_translation' service and assign it to
......
......@@ -51,7 +51,7 @@ public function compile(\Twig_Compiler $compiler) {
}
// Start writing with the function to be called.
$compiler->write('echo ' . (empty($plural) ? 't' : 'format_plural') . '(');
$compiler->write('echo ' . (empty($plural) ? 't' : '\Drupal::translation()->formatPlural') . '(');
// Move the count to the beginning of the parameters list.
if (!empty($plural)) {
......
......@@ -41,7 +41,7 @@ public function transChoice($id, $number, array $parameters = array(), $domain =
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));
return \Drupal::translation()->formatPlural($number, $ids[0], $ids[1], $this->processParameters($parameters), $this->getOptions($domain, $locale));
}
/**
......
......@@ -336,8 +336,9 @@ if (window.jQuery) {
* Drupal.t() is called by this function, make sure not to pass
* already-localized strings to it.
*
* See the documentation of the server-side format_plural() function for
* further details.
* See the documentation of the server-side
* \Drupal\Core\StringTranslation\TranslationInterface::formatPlural()
* function for more details.
*
* @param {Number} count
* The item count to display.
......
......@@ -150,7 +150,7 @@ public function buildConfigurationForm(array $form, FormStateInterface $form_sta
$lengths = array(0, 200, 400, 600, 800, 1000, 1200, 1400, 1600, 1800, 2000);
$options = array_map(function($length) {
return ($length == 0) ? t('Unlimited') : format_plural($length, '1 character', '@count characters');
return ($length == 0) ? t('Unlimited') : $this->formatPlural($length, '1 character', '@count characters');
}, array_combine($lengths, $lengths));
$form['processors'][$info['id']]['aggregator_teaser_length'] = array(
......
......@@ -44,7 +44,7 @@ public function buildForm(array $form, FormStateInterface $form_state) {
$instances = $this->entity->getInstances();
$form['message'] = array(
'#markup' => format_plural(count($instances), 'This will also remove 1 placed block instance.', 'This will also remove @count placed block instances.'),
'#markup' => $this->formatPlural(count($instances), 'This will also remove 1 placed block instance.', 'This will also remove @count placed block instances.'),
'#access' => !empty($instances),
);
......
......@@ -71,7 +71,7 @@ public function getConfirmText() {
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>';
$caption = '<p>' . $this->formatPlural(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;
}
......
......@@ -184,7 +184,7 @@ public function testBlockDelete() {
// Delete the block.
$this->drupalGet('block/1/delete');
$this->assertText(format_plural(1, 'This will also remove 1 placed block instance.', 'This will also remove @count placed block instance.'));
$this->assertText(\Drupal::translation()->formatPlural(1, 'This will also remove 1 placed block instance.', 'This will also remove @count placed block instance.'));
$this->drupalPostForm(NULL, array(), 'Delete');
$this->assertRaw(t('Custom block %name has been deleted.', array('%name' => $edit['info[0][value]'])));
......
......@@ -530,7 +530,7 @@ function comment_node_search_result(EntityInterface $node) {
// Do not make a string if there are no comment fields, or no comments exist
// or all comment fields are hidden.
if ($comments > 0 || $open) {
return array('comment' => format_plural($comments, '1 comment', '@count comments'));
return array('comment' => \Drupal::translation()->formatPlural($comments, '1 comment', '@count comments'));
}
}
......
......@@ -122,7 +122,7 @@ public function submitForm(array &$form, FormStateInterface $form_state) {
$this->commentStorage->delete($this->comments);
$count = count($form_state->getValue('comments'));
$this->logger('content')->notice('Deleted @count comments.', array('@count' => $count));
drupal_set_message(format_plural($count, 'Deleted 1 comment.', 'Deleted @count comments.'));
drupal_set_message($this->formatPlural($count, 'Deleted 1 comment.', 'Deleted @count comments.'));
}
$form_state->setRedirectUrl($this->getCancelUrl());
}
......
......@@ -208,7 +208,7 @@ function performCommentOperation($comment, $operation, $approval = FALSE) {
if ($operation == 'delete') {
$this->drupalPostForm(NULL, array(), t('Delete comments'));
$this->assertRaw(format_plural(1, 'Deleted 1 comment.', 'Deleted @count comments.'), format_string('Operation "@operation" was performed on comment.', array('@operation' => $operation)));
$this->assertRaw(\Drupal::translation()->formatPlural(1, 'Deleted 1 comment.', 'Deleted @count comments.'), format_string('Operation "@operation" was performed on comment.', array('@operation' => $operation)));
}
else {
$this->assertText(t('The update has been performed.'), format_string('Operation "@operation" was performed on comment.', array('@operation' => $operation)));
......
......@@ -345,7 +345,7 @@ function performCommentOperation(CommentInterface $comment, $operation, $approva
if ($operation == 'delete') {
$this->drupalPostForm(NULL, array(), t('Delete comments'));
$this->assertRaw(format_plural(1, 'Deleted 1 comment.', 'Deleted @count comments.'), format_string('Operation "@operation" was performed on comment.', array('@operation' => $operation)));
$this->assertRaw(\Drupal::translation()->formatPlural(1, 'Deleted 1 comment.', 'Deleted @count comments.'), format_string('Operation "@operation" was performed on comment.', array('@operation' => $operation)));
}
else {
$this->assertText(t('The update has been performed.'), format_string('Operation "@operation" was performed on comment.', array('@operation' => $operation)));
......
......@@ -239,19 +239,19 @@ public function buildForm(array $form, FormStateInterface $form_state) {
);
switch ($config_change_type) {
case 'create':
$form[$collection][$config_change_type]['heading']['#value'] = format_plural(count($config_names), '@count new', '@count new');
$form[$collection][$config_change_type]['heading']['#value'] = $this->formatPlural(count($config_names), '@count new', '@count new');
break;
case 'update':
$form[$collection][$config_change_type]['heading']['#value'] = format_plural(count($config_names), '@count changed', '@count changed');
$form[$collection][$config_change_type]['heading']['#value'] = $this->formatPlural(count($config_names), '@count changed', '@count changed');
break;
case 'delete':
$form[$collection][$config_change_type]['heading']['#value'] = format_plural(count($config_names), '@count removed', '@count removed');
$form[$collection][$config_change_type]['heading']['#value'] = $this->formatPlural(count($config_names), '@count removed', '@count removed');
break;
case 'rename':
$form[$collection][$config_change_type]['heading']['#value'] = format_plural(count($config_names), '@count renamed', '@count renamed');
$form[$collection][$config_change_type]['heading']['#value'] = $this->formatPlural(count($config_names), '@count renamed', '@count renamed');
break;
}
$form[$collection][$config_change_type]['list'] = array(
......
......@@ -175,7 +175,7 @@ function template_preprocess_file_upload_help(&$variables) {
$descriptions[] = t('Unlimited number of files can be uploaded to this field.');
}
else {
$descriptions[] = format_plural($cardinality, 'One file only.', 'Maximum @count files.');
$descriptions[] = \Drupal::translation()->formatPlural($cardinality, 'One file only.', 'Maximum @count files.');
}
}
if (isset($upload_validators['file_validate_size'])) {
......
......@@ -80,7 +80,7 @@ function assertFileHookCalled($hook, $expected_count = 1, $message = NULL) {
$message = format_string('hook_file_@name was called correctly.', array('@name' => $hook));
}
elseif ($expected_count == 0) {
$message = format_plural($actual_count, 'hook_file_@name was not expected to be called but was actually called once.', 'hook_file_@name was not expected to be called but was actually called @count times.', array('@name' => $hook, '@count' => $actual_count));
$message = \Drupal::translation()->formatPlural($actual_count, 'hook_file_@name was not expected to be called but was actually called once.', 'hook_file_@name was not expected to be called but was actually called @count times.', array('@name' => $hook, '@count' => $actual_count));
}
else {
$message = format_string('hook_file_@name was expected to be called %expected times but was called %actual times.', array('@name' => $hook, '%expected' => $expected_count, '%actual' => $actual_count));
......
......@@ -92,7 +92,7 @@ function assertFileHookCalled($hook, $expected_count = 1, $message = NULL) {
$message = format_string('hook_file_@name was called correctly.', array('@name' => $hook));
}
elseif ($expected_count == 0) {
$message = format_plural($actual_count, 'hook_file_@name was not expected to be called but was actually called once.', 'hook_file_@name was not expected to be called but was actually called @count times.', array('@name' => $hook, '@count' => $actual_count));
$message = \Drupal::translation()->formatPlural($actual_count, 'hook_file_@name was not expected to be called but was actually called once.', 'hook_file_@name was not expected to be called but was actually called @count times.', array('@name' => $hook, '@count' => $actual_count));
}
else {
$message = format_string('hook_file_@name was expected to be called %expected times but was called %actual times.', array('@name' => $hook, '%expected' => $expected_count, '%actual' => $actual_count));
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment