From db342cbdb3c9c16952ff91d7deca14792a968909 Mon Sep 17 00:00:00 2001 From: Alex Pott <alex.a.pott@googlemail.com> Date: Wed, 9 Sep 2015 15:55:53 +0100 Subject: [PATCH] =?UTF-8?q?Issue=20#2552867=20by=20jhodgdon,=20G=C3=A1bor?= =?UTF-8?q?=20Hojtsy,=20pjonckiere:=20Document=20DrupalTranslator::transCh?= =?UTF-8?q?oice()'s=20non-standard=20formatPlural()=20usage?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/lib/Drupal/Core/Validation/DrupalTranslator.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/core/lib/Drupal/Core/Validation/DrupalTranslator.php b/core/lib/Drupal/Core/Validation/DrupalTranslator.php index b14c7d24ab58..ff74ce8a145b 100644 --- a/core/lib/Drupal/Core/Validation/DrupalTranslator.php +++ b/core/lib/Drupal/Core/Validation/DrupalTranslator.php @@ -41,6 +41,17 @@ 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)); } + + // Normally, calls to formatPlural() need to use literal strings, like + // formatPlural($count, '1 item', '@count items') + // so that the Drupal project POTX string extractor will correctly + // extract the strings for translation and save them in a format that + // formatPlural() can work with. However, this is a special case, because + // Drupal is supporting a constraint message format from Symfony. So + // although $id looks like a variable here, it is actually coming from a + // static string in a constraint class that the POTX extractor knows about + // and has processed to work with formatPlural(), so this specific call to + // formatPlural() will work correctly. return \Drupal::translation()->formatPlural($number, $ids[0], $ids[1], $this->processParameters($parameters), $this->getOptions($domain, $locale)); } -- GitLab