Change record status: 
Project: 
Introduced in branch: 
8.x
Description: 

format_plural() and format_interval() have been deprecated. Use \Drupal::translation()->formatPlural() and \Drupal::service('date')->formatInterval() instead.

Summary

  • Deprecated format_plural() and format_interval()
  • Created \Drupal::translation()->formatPlural()
  • Created \Drupal::service('date')->formatInterval()
  • Added test cases for above functions

Example: Formatting total comment count plural text

Before

<?php
$output = format_plural($node->comment_count, '1 comment', '@count comments');
?>

After

<?php
$output = \Drupal::translation()->formatPlural($node->comment_count, '1 comment', '@count comments');
?>

---
Example: Formatting how long ago a node was created

Before

<?php
$ago = t('@time ago',  array('@time' => format_interval((time() - $node->created) , 2));
?>

After

<?php
$ago = t('@time ago',  array('@time' =>  \Drupal::service('date.formatter')->formatInterval((time() - $node->created) , 2));
?>
Impacts: 
Module developers
Themers