feature #17662 [Translation][transChoice] allows escaping the pipe character. (aitboudad)
This PR was merged into the 3.2-dev branch.
Discussion
----------
[Translation][transChoice] allows escaping the pipe character.
| Q | A
| ------------- | ---
| Bug fix? | no
| New feature? | yes
| BC breaks? | no
| Deprecations? | no
| Fixed tickets | #15195
| Tests pass? | yes
| License | MIT
Commits
-------
a35a93b
[Translation][transChoice] allows escaping the pipe character.
This commit is contained in:
commit
f400f01ecc
@ -1,6 +1,11 @@
|
|||||||
CHANGELOG
|
CHANGELOG
|
||||||
=========
|
=========
|
||||||
|
|
||||||
|
3.2.0
|
||||||
|
-----
|
||||||
|
|
||||||
|
* Added support for escaping `|` in plural translations with double pipe.
|
||||||
|
|
||||||
3.1.0
|
3.1.0
|
||||||
-----
|
-----
|
||||||
|
|
||||||
|
@ -47,11 +47,11 @@ class MessageSelector
|
|||||||
*/
|
*/
|
||||||
public function choose($message, $number, $locale)
|
public function choose($message, $number, $locale)
|
||||||
{
|
{
|
||||||
$parts = explode('|', $message);
|
preg_match_all('/(?:\|\||[^\|])++/', $message, $parts);
|
||||||
$explicitRules = array();
|
$explicitRules = array();
|
||||||
$standardRules = array();
|
$standardRules = array();
|
||||||
foreach ($parts as $part) {
|
foreach ($parts[0] as $part) {
|
||||||
$part = trim($part);
|
$part = trim(str_replace('||', '|', $part));
|
||||||
|
|
||||||
if (preg_match('/^(?P<interval>'.Interval::getIntervalRegexp().')\s*(?P<message>.*?)$/xs', $part, $matches)) {
|
if (preg_match('/^(?P<interval>'.Interval::getIntervalRegexp().')\s*(?P<message>.*?)$/xs', $part, $matches)) {
|
||||||
$explicitRules[$matches['interval']] = $matches['message'];
|
$explicitRules[$matches['interval']] = $matches['message'];
|
||||||
@ -74,7 +74,7 @@ class MessageSelector
|
|||||||
if (!isset($standardRules[$position])) {
|
if (!isset($standardRules[$position])) {
|
||||||
// when there's exactly one rule given, and that rule is a standard
|
// when there's exactly one rule given, and that rule is a standard
|
||||||
// rule, use this rule
|
// rule, use this rule
|
||||||
if (1 === count($parts) && isset($standardRules[0])) {
|
if (1 === count($parts[0]) && isset($standardRules[0])) {
|
||||||
return $standardRules[0];
|
return $standardRules[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -125,6 +125,8 @@ class MessageSelectorTest extends \PHPUnit_Framework_TestCase
|
|||||||
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),
|
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
|
// 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),
|
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),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user