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 a35a93b

Browse filesBrowse files
committed
[Translation][transChoice] allows escaping the pipe character.
1 parent 5c91f6e commit a35a93b
Copy full SHA for a35a93b

File tree

Expand file treeCollapse file tree

3 files changed

+11
-4
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+11
-4
lines changed

‎src/Symfony/Component/Translation/CHANGELOG.md

Copy file name to clipboardExpand all lines: src/Symfony/Component/Translation/CHANGELOG.md
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
CHANGELOG
22
=========
33

4+
3.2.0
5+
-----
6+
7+
* Added support for escaping `|` in plural translations with double pipe.
8+
49
3.1.0
510
-----
611

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Translation/MessageSelector.php
+4-4Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,11 @@ class MessageSelector
4747
*/
4848
public function choose($message, $number, $locale)
4949
{
50-
$parts = explode('|', $message);
50+
preg_match_all('/(?:\|\||[^\|])++/', $message, $parts);
5151
$explicitRules = array();
5252
$standardRules = array();
53-
foreach ($parts as $part) {
54-
$part = trim($part);
53+
foreach ($parts[0] as $part) {
54+
$part = trim(str_replace('||', '|', $part));
5555

5656
if (preg_match('/^(?P<interval>'.Interval::getIntervalRegexp().')\s*(?P<message>.*?)$/xs', $part, $matches)) {
5757
$explicitRules[$matches['interval']] = $matches['message'];
@@ -74,7 +74,7 @@ public function choose($message, $number, $locale)
7474
if (!isset($standardRules[$position])) {
7575
// when there's exactly one rule given, and that rule is a standard
7676
// rule, use this rule
77-
if (1 === count($parts) && isset($standardRules[0])) {
77+
if (1 === count($parts[0]) && isset($standardRules[0])) {
7878
return $standardRules[0];
7979
}
8080

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Translation/Tests/MessageSelectorTest.php
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,8 @@ public function getChooseTests()
125125
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),
126126
// with double-quotes and id split accros lines
127127
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),
128+
// esacape pipe
129+
array('This is a text with | in it. Selector = 0.', '{0}This is a text with || in it. Selector = 0.|{1}This is a text with || in it. Selector = 1.', 0),
128130
);
129131
}
130132
}

0 commit comments

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