X-Git-Url: https://yaffs.net/gitweb/?a=blobdiff_plain;f=vendor%2Fsymfony%2Ftranslation%2FMessageSelector.php;h=5de171c5f4a408c84d7b85453be7c271d69980ea;hb=5b8bb166bfa98770daef9de5c127fc2e6ef02340;hp=bdbb0f965fff0da82c75c9b5a385f28f135df07e;hpb=a2bd1bf0c2c1f1a17d188f4dc0726a45494cefae;p=yaffs-website diff --git a/vendor/symfony/translation/MessageSelector.php b/vendor/symfony/translation/MessageSelector.php index bdbb0f965..5de171c5f 100644 --- a/vendor/symfony/translation/MessageSelector.php +++ b/vendor/symfony/translation/MessageSelector.php @@ -11,6 +11,8 @@ namespace Symfony\Component\Translation; +use Symfony\Component\Translation\Exception\InvalidArgumentException; + /** * MessageSelector. * @@ -43,15 +45,21 @@ class MessageSelector * * @return string * - * @throws \InvalidArgumentException + * @throws InvalidArgumentException */ public function choose($message, $number, $locale) { - $parts = explode('|', $message); + $parts = array(); + if (preg_match('/^\|++$/', $message)) { + $parts = explode('|', $message); + } elseif (preg_match_all('/(?:\|\||[^\|])++/', $message, $matches)) { + $parts = $matches[0]; + } + $explicitRules = array(); $standardRules = array(); foreach ($parts as $part) { - $part = trim($part); + $part = trim(str_replace('||', '|', $part)); if (preg_match('/^(?P'.Interval::getIntervalRegexp().')\s*(?P.*?)$/xs', $part, $matches)) { $explicitRules[$matches['interval']] = $matches['message']; @@ -74,11 +82,11 @@ class MessageSelector if (!isset($standardRules[$position])) { // when there's exactly one rule given, and that rule is a standard // rule, use this rule - if (1 === count($parts) && isset($standardRules[0])) { + if (1 === \count($parts) && isset($standardRules[0])) { return $standardRules[0]; } - throw new \InvalidArgumentException(sprintf('Unable to choose a translation for "%s" with locale "%s" for value "%d". Double check that this translation has the correct plural options (e.g. "There is one apple|There are %%count%% apples").', $message, $locale, $number)); + throw new InvalidArgumentException(sprintf('Unable to choose a translation for "%s" with locale "%s" for value "%d". Double check that this translation has the correct plural options (e.g. "There is one apple|There are %%count%% apples").', $message, $locale, $number)); } return $standardRules[$position];