From e717942491f2b475eb61043f5b62f081d9fa5d5b Mon Sep 17 00:00:00 2001 From: azine Date: Sat, 6 Jun 2015 18:39:32 +0200 Subject: [PATCH 1/8] Added test for message-selector with new-lines --- .../Translation/Tests/MessageSelectorTest.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/Symfony/Component/Translation/Tests/MessageSelectorTest.php b/src/Symfony/Component/Translation/Tests/MessageSelectorTest.php index d5a4f3e3d536a..848303b87f6ba 100644 --- a/src/Symfony/Component/Translation/Tests/MessageSelectorTest.php +++ b/src/Symfony/Component/Translation/Tests/MessageSelectorTest.php @@ -93,6 +93,23 @@ public function getChooseTests() 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), 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), 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), + + // Test texts with new-lines + array('This is text with a + new-line in it. Selector = 0.', '{0}This is a text with a + new-line in it. Selector = 0.|{1}This is a text with a + new-line in it. Selector = 1.|[1,Inf]This is a text with a + new-line in it. Selector > 1.', 0), + array('This is text with a + new-line in it. Selector = 1.', '{0}This is a text with a + new-line in it. Selector = 0.|{1}This is a text with a + new-line in it. Selector = 1.|[1,Inf]This is a text with a + new-line in it. Selector > 1.', 1), + array('This is text with a + new-line in it. Selector > 1.', '{0}This is a text with a + new-line in it. Selector = 0.|{1}This is a text with a + new-line in it. Selector = 1.|[1,Inf]This is a text with a + new-line in it. Selector > 1.', 5), ); } } From 7ac273247f90e71dedac46f1d2fcae4ca5904d38 Mon Sep 17 00:00:00 2001 From: azine Date: Sat, 6 Jun 2015 18:47:24 +0200 Subject: [PATCH 2/8] allow new-lines in messages with pluralization --- src/Symfony/Component/Translation/MessageSelector.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Component/Translation/MessageSelector.php b/src/Symfony/Component/Translation/MessageSelector.php index 9f5430cfe29ae..f7fde31ad9090 100644 --- a/src/Symfony/Component/Translation/MessageSelector.php +++ b/src/Symfony/Component/Translation/MessageSelector.php @@ -57,7 +57,7 @@ public function choose($message, $number, $locale) foreach ($parts as $part) { $part = trim($part); - if (preg_match('/^(?P'.Interval::getIntervalRegexp().')\s*(?P.*?)$/x', $part, $matches)) { + if (preg_match('/^(?P'.Interval::getIntervalRegexp().')\s*(?P.*?)$/xs', $part, $matches)) { $explicitRules[$matches['interval']] = $matches['message']; } elseif (preg_match('/^\w+\:\s*(.*?)$/', $part, $matches)) { $standardRules[] = $matches[1]; From ddf37c933669c9097a21990a319b831e7f696e2c Mon Sep 17 00:00:00 2001 From: azine Date: Sat, 6 Jun 2015 18:51:38 +0200 Subject: [PATCH 3/8] removed spaces --- src/Symfony/Component/Translation/Tests/MessageSelectorTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Component/Translation/Tests/MessageSelectorTest.php b/src/Symfony/Component/Translation/Tests/MessageSelectorTest.php index 848303b87f6ba..7f8fdc20c0d73 100644 --- a/src/Symfony/Component/Translation/Tests/MessageSelectorTest.php +++ b/src/Symfony/Component/Translation/Tests/MessageSelectorTest.php @@ -93,7 +93,7 @@ public function getChooseTests() 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), 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), 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), - + // Test texts with new-lines array('This is text with a new-line in it. Selector = 0.', '{0}This is a text with a From b9a01563fc8e1794c1cbcf59d48b633d2fb9687e Mon Sep 17 00:00:00 2001 From: azine Date: Mon, 8 Jun 2015 13:15:45 +0200 Subject: [PATCH 4/8] fixed test --- .../Component/Translation/Tests/MessageSelectorTest.php | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/Symfony/Component/Translation/Tests/MessageSelectorTest.php b/src/Symfony/Component/Translation/Tests/MessageSelectorTest.php index 7f8fdc20c0d73..54625a5e3019d 100644 --- a/src/Symfony/Component/Translation/Tests/MessageSelectorTest.php +++ b/src/Symfony/Component/Translation/Tests/MessageSelectorTest.php @@ -95,18 +95,15 @@ public function getChooseTests() 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), // Test texts with new-lines - array('This is text with a - new-line in it. Selector = 0.', '{0}This is a text with a + array('This is text with a\n new-line in it. Selector = 0.', '{0}This is a text with a new-line in it. Selector = 0.|{1}This is a text with a new-line in it. Selector = 1.|[1,Inf]This is a text with a new-line in it. Selector > 1.', 0), - array('This is text with a - new-line in it. Selector = 1.', '{0}This is a text with a + array('This is text with a\n new-line in it. Selector = 1.', '{0}This is a text with a new-line in it. Selector = 0.|{1}This is a text with a new-line in it. Selector = 1.|[1,Inf]This is a text with a new-line in it. Selector > 1.', 1), - array('This is text with a - new-line in it. Selector > 1.', '{0}This is a text with a + array('This is text with a\n new-line in it. Selector > 1.', '{0}This is a text with a new-line in it. Selector = 0.|{1}This is a text with a new-line in it. Selector = 1.|[1,Inf]This is a text with a new-line in it. Selector > 1.', 5), From dde45d0faf327a60455a115e4f9c22a38279ef9c Mon Sep 17 00:00:00 2001 From: azine Date: Tue, 9 Jun 2015 21:19:17 +0200 Subject: [PATCH 5/8] replaced \n with actual line-breaks --- .../Component/Translation/Tests/MessageSelectorTest.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/Symfony/Component/Translation/Tests/MessageSelectorTest.php b/src/Symfony/Component/Translation/Tests/MessageSelectorTest.php index 54625a5e3019d..7f8fdc20c0d73 100644 --- a/src/Symfony/Component/Translation/Tests/MessageSelectorTest.php +++ b/src/Symfony/Component/Translation/Tests/MessageSelectorTest.php @@ -95,15 +95,18 @@ public function getChooseTests() 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), // Test texts with new-lines - array('This is text with a\n new-line in it. Selector = 0.', '{0}This is a text with a + array('This is text with a + new-line in it. Selector = 0.', '{0}This is a text with a new-line in it. Selector = 0.|{1}This is a text with a new-line in it. Selector = 1.|[1,Inf]This is a text with a new-line in it. Selector > 1.', 0), - array('This is text with a\n new-line in it. Selector = 1.', '{0}This is a text with a + array('This is text with a + new-line in it. Selector = 1.', '{0}This is a text with a new-line in it. Selector = 0.|{1}This is a text with a new-line in it. Selector = 1.|[1,Inf]This is a text with a new-line in it. Selector > 1.', 1), - array('This is text with a\n new-line in it. Selector > 1.', '{0}This is a text with a + array('This is text with a + new-line in it. Selector > 1.', '{0}This is a text with a new-line in it. Selector = 0.|{1}This is a text with a new-line in it. Selector = 1.|[1,Inf]This is a text with a new-line in it. Selector > 1.', 5), From ccf6eac0f606582b2bb64c4ff84ecf2af7e88a02 Mon Sep 17 00:00:00 2001 From: azine Date: Tue, 9 Jun 2015 21:35:04 +0200 Subject: [PATCH 6/8] next try to fix tests with newlines --- .../Component/Translation/Tests/MessageSelectorTest.php | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/Symfony/Component/Translation/Tests/MessageSelectorTest.php b/src/Symfony/Component/Translation/Tests/MessageSelectorTest.php index 7f8fdc20c0d73..4ea8d0ec28a1b 100644 --- a/src/Symfony/Component/Translation/Tests/MessageSelectorTest.php +++ b/src/Symfony/Component/Translation/Tests/MessageSelectorTest.php @@ -95,18 +95,15 @@ public function getChooseTests() 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), // Test texts with new-lines - array('This is text with a - new-line in it. Selector = 0.', '{0}This is a text with a + array("This is text with a\n new-line in it. Selector = 0.", '{0}This is a text with a new-line in it. Selector = 0.|{1}This is a text with a new-line in it. Selector = 1.|[1,Inf]This is a text with a new-line in it. Selector > 1.', 0), - array('This is text with a - new-line in it. Selector = 1.', '{0}This is a text with a + array("This is text with a\n new-line in it. Selector = 1.", '{0}This is a text with a new-line in it. Selector = 0.|{1}This is a text with a new-line in it. Selector = 1.|[1,Inf]This is a text with a new-line in it. Selector > 1.', 1), - array('This is text with a - new-line in it. Selector > 1.', '{0}This is a text with a + array("This is text with a\n new-line in it. Selector > 1.", '{0}This is a text with a new-line in it. Selector = 0.|{1}This is a text with a new-line in it. Selector = 1.|[1,Inf]This is a text with a new-line in it. Selector > 1.', 5), From d0cd7777cacd123a38c49f6d7064df432475a7e1 Mon Sep 17 00:00:00 2001 From: azine Date: Tue, 9 Jun 2015 22:47:07 +0200 Subject: [PATCH 7/8] fixed double-/single-quote issue in tests As long as the interpreted string is the same, the new-lines work fine. But the following combination does not work: key: "some text \n with a new line" text: 'some text \n with a new line" But I would say this is expected behavior. --- .../Translation/Tests/MessageSelectorTest.php | 28 +++++++++++++++---- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/src/Symfony/Component/Translation/Tests/MessageSelectorTest.php b/src/Symfony/Component/Translation/Tests/MessageSelectorTest.php index 4ea8d0ec28a1b..dd73a5bd73ef1 100644 --- a/src/Symfony/Component/Translation/Tests/MessageSelectorTest.php +++ b/src/Symfony/Component/Translation/Tests/MessageSelectorTest.php @@ -93,20 +93,38 @@ public function getChooseTests() 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), 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), 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), - + // Test texts with new-lines - array("This is text with a\n new-line in it. Selector = 0.", '{0}This is a text with a + // with double-quotes and \n in id and double-quotes and actual newlines in text + array("This is a text with a\n new-line in it. Selector = 0.", "{0}This is a text with a + new-line in it. Selector = 0.|{1}This is a text with a + new-line in it. Selector = 1.|[1,Inf]This is a text with a + new-line in it. Selector > 1.", 0), + // with double-quotes and \n in id and single-quotes and actual newlines in text + array("This is a text with a\n new-line in it. Selector = 1.", '{0}This is a text with a new-line in it. Selector = 0.|{1}This is a text with a new-line in it. Selector = 1.|[1,Inf]This is a text with a - new-line in it. Selector > 1.', 0), - array("This is text with a\n new-line in it. Selector = 1.", '{0}This is a text with a + new-line in it. Selector > 1.', 1), + array("This is a text with a\n new-line in it. Selector > 1.", '{0}This is a text with a + new-line in it. Selector = 0.|{1}This is a text with a + new-line in it. Selector = 1.|[1,Inf]This is a text with a + new-line in it. Selector > 1.', 5), + // with double-quotes and id split accros lines + array("This is a text with a + new-line in it. Selector = 1.", '{0}This is a text with a new-line in it. Selector = 0.|{1}This is a text with a new-line in it. Selector = 1.|[1,Inf]This is a text with a new-line in it. Selector > 1.', 1), - array("This is text with a\n new-line in it. Selector > 1.", '{0}This is a text with a + // with single-quotes and id split accros lines + array('This is a text with a + new-line in it. Selector > 1.', '{0}This is a text with a new-line in it. Selector = 0.|{1}This is a text with a new-line in it. Selector = 1.|[1,Inf]This is a text with a new-line in it. Selector > 1.', 5), + // with single-quotes and \n in text + 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), ); } } From 5ded97ed27cb0157ae024f4812ab9f1fa16767ad Mon Sep 17 00:00:00 2001 From: azine Date: Tue, 9 Jun 2015 22:54:36 +0200 Subject: [PATCH 8/8] fix coding-style-issues with newlines --- src/Symfony/Component/Translation/Tests/MessageSelectorTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Component/Translation/Tests/MessageSelectorTest.php b/src/Symfony/Component/Translation/Tests/MessageSelectorTest.php index dd73a5bd73ef1..48c30b3a14574 100644 --- a/src/Symfony/Component/Translation/Tests/MessageSelectorTest.php +++ b/src/Symfony/Component/Translation/Tests/MessageSelectorTest.php @@ -95,7 +95,7 @@ public function getChooseTests() 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), // Test texts with new-lines - // with double-quotes and \n in id and double-quotes and actual newlines in text + // with double-quotes and \n in id & double-quotes and actual newlines in text array("This is a text with a\n new-line in it. Selector = 0.", "{0}This is a text with a new-line in it. Selector = 0.|{1}This is a text with a new-line in it. Selector = 1.|[1,Inf]This is a text with a