.*?)$/xs
+EOF;
+
+ $standardRules = array();
+ foreach ($parts as $part) {
+ $part = trim(str_replace('||', '|', $part));
+
+ // try to match an explicit rule, then fallback to the standard ones
+ if (preg_match($intervalRegexp, $part, $matches)) {
+ if ($matches[2]) {
+ foreach (explode(',', $matches[3]) as $n) {
+ $standardRules['='.$n] = $matches['message'];
+ }
+ } else {
+ $leftNumber = '-Inf' === $matches['left'] ? -INF : (float) $matches['left'];
+ $rightNumber = \is_numeric($matches['right']) ? (float) $matches['right'] : INF;
+
+ $leftNumber = ('[' === $matches['left_delimiter'] ? $leftNumber : 1 + $leftNumber);
+ $rightNumber = (']' === $matches['right_delimiter'] ? 1 + $rightNumber : $rightNumber);
+
+ if ($leftNumber !== -INF && INF !== $rightNumber) {
+ for ($i = $leftNumber; $i < $rightNumber; ++$i) {
+ $standardRules['='.$i] = $matches['message'];
+ }
+ } else {
+ // $rightNumber is INF or $leftNumber is -INF
+ if (isset($standardRules['other'])) {
+ throw new \LogicException(sprintf('%s does not support converting messages with both "-Inf" and "Inf". Message: "%s"', __CLASS__, $message));
+ }
+ $standardRules['other'] = $matches['message'];
+ }
+ }
+ } elseif (preg_match('/^\w+\:\s*(.*?)$/', $part, $matches)) {
+ $standardRules[] = $matches[1];
+ } else {
+ $standardRules[] = $part;
+ }
+ }
+
+ return $standardRules;
+ }
+
+ private static function buildIcuString(array $data, string $variableDelimiter): string
+ {
+ $icu = "{ COUNT, plural,\n";
+ foreach ($data as $key => $message) {
+ $message = strtr($message, array('%count%' => '#'));
+ $message = self::replaceVariables($message, $variableDelimiter);
+ $icu .= sprintf(" %s {%s}\n", $key, $message);
+ }
+ $icu .= '}';
+
+ return $icu;
+ }
+
+ private static function replaceVariables(string $message, string $variableDelimiter): string
+ {
+ $regex = sprintf('|%s(.*?)%s|s', $variableDelimiter, $variableDelimiter);
+
+ return preg_replace($regex, '{$1}', $message);
+ }
+}
pFad - Phonifier reborn
Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies:
Alternative Proxy
pFad Proxy
pFad v3 Proxy
pFad v4 Proxy