public function DrupalTranslator::transChoice in Drupal 8
Same name and namespace in other branches
- 9 core/lib/Drupal/Core/Validation/DrupalTranslator.php \Drupal\Core\Validation\DrupalTranslator::transChoice()
File
- core/lib/Drupal/Core/Validation/DrupalTranslator.php, line 37
Class
- DrupalTranslator
- Translates strings using Drupal's translation system.
Namespace
Drupal\Core\Validation
Code
public function transChoice($id, $number, array $parameters = [], $domain = NULL, $locale = NULL) {
$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 \Drupal::translation()
->formatPlural($number, $ids[0], $ids[1], $this
->processParameters($parameters), $this
->getOptions($domain, $locale));
}