Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Illuminate/Translation/MessageSelector.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ private function extract($segments, $number)
*/
private function extractFromString($part, $number)
{
preg_match('/^[\{\[]([^\[\]\{\}]*)[\}\]](.*)/s', $part, $matches);
preg_match('/^[\{\[]([\d,\.*]*)[\}\]](.*)/s', $part, $matches);

if (count($matches) !== 3) {
return null;
Expand Down Expand Up @@ -92,7 +92,7 @@ private function extractFromString($part, $number)
private function stripConditions($segments)
{
return (new Collection($segments))
->map(fn ($part) => preg_replace('/^[\{\[]([^\[\]\{\}]*)[\}\]]/', '', $part))
->map(fn ($part) => preg_replace('/^[\{\[][\d,\.*]*[\}\]]/', '', $part))
->all();
}

Expand Down
12 changes: 12 additions & 0 deletions tests/Translation/TranslationMessageSelectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public static function chooseTestData()
['first', '{9}first|{10}second', 1],
['', '{0}|{1}second', 0],
['', '{0}first|{1}', 1],
['second', '{1.3}first|{2.3}second', .3],
['first', '{1.3}first|{2.3}second', 1.3],
['second', '{1.3}first|{2.3}second', 2.3],
['first
Expand Down Expand Up @@ -63,6 +64,17 @@ public static function chooseTestData()

['first', '{0} first | { 1 } second', 0],
['first', '[4,*]first | [1,3]second', 100],

['[first](//example.com)', '[first](//example.com)|[second](//test.com)', 1],
['[second](//test.com)', '[first](//example.com)|[second](//test.com)', 2],
['[first](//example.com)', '{0}[first](//example.com)|{1}[second](//test.com)', 0],
['[second](//test.com)', '{0}[first](//example.com)|{1}[second](//test.com)', 1],
['[first](//example.com)', '{0}[first](//example.com)|[2,*][second](//test.com)', 0],
['[first](//example.com)', '{0}[first](//example.com)|[2,*][second](//test.com)', 1],
['[second](//test.com)', '{0}[first](//example.com)|[2,*][second](//test.com)', 10],
['[first](//example.com)', '{0}[first](//example.com)|{2.3}[second](//test.com)', 0],
['[first](//example.com)', '{0}[first](//example.com)|{2.3}[second](//test.com)', 1],
['[second](//test.com)', '{0}[first](//example.com)|{2.3}[second](//test.com)', 2.3],
];
}
}
Loading