8000 bug #14897 Allow new lines in Messages translated with transchoice()… · symfony/symfony@e54d716 · GitHub
[go: up one dir, main page]

Skip to content

Commit e54d716

Browse files
committed
bug #14897 Allow new lines in Messages translated with transchoice() (replacement for #14867) (azine)
This PR was submitted for the 2.8 branch but it was merged into the 2.3 branch instead (closes #14897). Discussion ---------- Allow new lines in Messages translated with transchoice() (replacement for #14867) | Q | A | ------------- | --- | Bug fix? | yes | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | | License | MIT | Doc PR | Hi, I found that the MessageSelector does not handle new lines in messages very well. I suggest adding the "s" modifier to the regexp used to identify the parts and ranges. What do you think? PS: would be nice to have this change also in Symfony 2.6 & 2.7 Commits ------- 786b8a6 Allow new lines in Messages translated with transchoice() (replacement for #14867)
2 parents c95d86c + 786b8a6 commit e54d716

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

src/Symfony/Component/Translation/MessageSelector.php

Lines 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

Lines 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