8000 [Translation][transChoice] allows escaping the pipe character. by aitboudad · Pull Request #17662 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Translation][transChoice] allows escaping the pipe character. #17662

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 14, 2016
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
5 changes: 5 additions & 0 deletions src/Symfony/Component/Translation/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
CHANGELOG
=========

3.2.0
-----

* Added support for escaping `|` in plural translations with double pipe.

3.1.0
-----

Expand Down
8 changes: 4 additions & 4 deletions src/Symfony/Component/Translation/MessageSelector.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ class MessageSelector
*/
public function choose($message, $number, $locale)
{
$parts = explode('|', $message);
preg_match_all('/(?:\|\||[^\|])++/', $message, $parts);
$explicitRules = array();
$standardRules = array();
foreach ($parts as $part) {
$part = trim($part);
foreach ($parts[0] as $part) {
$part = trim(str_replace('||', '|', $part));

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ public function getChooseTests()
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),
// with double-quotes and id split accros lines
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),
// esacape pipe
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),
);
}
}
0