Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 786b8a6

Browse filesBrowse files
azinefabpot
authored andcommitted
Allow new lines in Messages translated with transchoice() (replacement for #14867)
1 parent c95d86c commit 786b8a6
Copy full SHA for 786b8a6

File tree

Expand file treeCollapse file tree

2 files changed

+33
-1
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+33
-1
lines changed

‎src/Symfony/Component/Translation/MessageSelector.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Translation/MessageSelector.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public function choose($message, $number, $locale)
5757
foreach ($parts as $part) {
5858
$part = trim($part);
5959

60-
if (preg_match('/^(?P<interval>'.Interval::getIntervalRegexp().')\s*(?P<message>.*?)$/x', $part, $matches)) {
60+
if (preg_match('/^(?P<interval>'.Interval::getIntervalRegexp().')\s*(?P<message>.*?)$/xs', $part, $matches)) {
6161
$explicitRules[$matches['interval']] = $matches['message'];
6262
} elseif (preg_match('/^\w+\:\s*(.*?)$/', $part, $matches)) {
6363
$standardRules[] = $matches[1];

‎src/Symfony/Component/Translation/Tests/MessageSelectorTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Translation/Tests/MessageSelectorTest.php
+32Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,38 @@ public function getChooseTests()
9393
array('There are no apples', '{0} There are no apples|]0,1[There are %count% apples|{1} There is one apple|[1,Inf] There is more than one apple', 0),
9494
array('There are no apples', '{0} There are no apples|]0,1[There are %count% apples|{1} There is one apple|[1,Inf] There is more than one apple', 0.0),
9595
array('There are no apples', '{0.0} There are no apples|]0,1[There are %count% apples|{1} There is one apple|[1,Inf] There is more than one apple', 0),
96+
97+
// Test texts with new-lines
98+
// with double-quotes and \n in id & double-quotes and actual newlines in text
99+
array("This is a text with a\n new-line in it. Selector = 0.", "{0}This is a text with a
100+
new-line in it. Selector = 0.|{1}This is a text with a
101+
new-line in it. Selector = 1.|[1,Inf]This is a text with a
102+
new-line in it. Selector > 1.", 0),
103+
// with double-quotes and \n in id and single-quotes and actual newlines in text
104+
array("This is a text with a\n new-line in it. Selector = 1.", '{0}This is a text with a
105+
new-line in it. Selector = 0.|{1}This is a text with a
106+
new-line in it. Selector = 1.|[1,Inf]This is a text with a
107+
new-line in it. Selector > 1.', 1),
108+
array("This is a text with a\n new-line in it. Selector > 1.", '{0}This is a text with a
109+
new-line in it. Selector = 0.|{1}This is a text with a
110+
new-line in it. Selector = 1.|[1,Inf]This is a text with a
111+
new-line in it. Selector > 1.', 5),
112+
// with double-quotes and id split accros lines
113+
array("This is a text with a
114+
new-line in it. Selector = 1.", '{0}This is a text with a
115+
new-line in it. Selector = 0.|{1}This is a text with a
116+
new-line in it. Selector = 1.|[1,Inf]This is a text with a
117+
new-line in it. Selector > 1.', 1),
118+
// with single-quotes and id split accros lines
119+
array('This is a text with a
120+
new-line in it. Selector > 1.', '{0}This is a text with a
121+
new-line in it. Selector = 0.|{1}This is a text with a
122+
new-line in it. Selector = 1.|[1,Inf]This is a text with a
123+
new-line in it. Selector > 1.', 5),
124+
// with single-quotes and \n in text
125+
array('This is a text with a\nnew-line in it. Selector = 0.', '{0}This is a text with a\nnew-line in it. Selector = 0.|{1}This is a text with a\nnew-line in it. Selector = 1.|[1,Inf]This is a text with a\nnew-line in it. Selector > 1.', 0),
126+
// with double-quotes and id split accros lines
127+
array("This is a text with a\nnew-line in it. Selector = 1.", "{0}This is a text with a\nnew-line in it. Selector = 0.|{1}This is a text with a\nnew-line in it. Selector = 1.|[1,Inf]This is a text with a\nnew-line in it. Selector > 1.", 1),
96128
);
97129
}
98130
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.