From b4c459c3efc0f105958ac2cb6970265acf2b0747 Mon Sep 17 00:00:00 2001 From: Toni Rudolf Date: Sat, 4 Feb 2017 18:14:11 +0100 Subject: [PATCH 1/7] only match chars until next getResponse()->getContent(); // Clean the content for malformed tags in attributes or encoded tags - $content = preg_replace("@=\\s*[\"']\\s*()\\s*[\"']@mi", "=\"🚫 Can't be translated here. 🚫\"", $content); + $content = preg_replace("@=\\s*[\"']\\s*()\\s*[\"']@mi", "=\"🚫 Can't be translated here. 🚫\"", $content); $content = preg_replace('@<x-trans.+data-key="([^&]+)".+<\\/x-trans>@mi', '🚫 $1 🚫', $content); $html = sprintf( From 2ab873ba105b256948af8c39eaeaf585700303cd Mon Sep 17 00:00:00 2001 From: Toni Rudolf Date: Sat, 4 Feb 2017 18:19:49 +0100 Subject: [PATCH 2/7] match when used in special links if a translation is used as a link (localization)`` the regex wouldn't match. --- EventListener/EditInPlaceResponseListener.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/EventListener/EditInPlaceResponseListener.php b/EventListener/EditInPlaceResponseListener.php index 4bda1409..4e3e8bbb 100644 --- a/EventListener/EditInPlaceResponseListener.php +++ b/EventListener/EditInPlaceResponseListener.php @@ -74,7 +74,7 @@ public function onKernelResponse(FilterResponseEvent $event) $content = $event->getResponse()->getContent(); // Clean the content for malformed tags in attributes or encoded tags - $content = preg_replace("@=\\s*[\"']\\s*()\\s*[\"']@mi", "=\"🚫 Can't be translated here. 🚫\"", $content); + $content = preg_replace("@=\\s*[\"']\\s*(.[a-zA-Z]+:|)()\\s*[\"']@mi", "=\"🚫 Can't be translated here. 🚫\"", $content); $content = preg_replace('@<x-trans.+data-key="([^&]+)".+<\\/x-trans>@mi', '🚫 $1 🚫', $content); $html = sprintf( From d7d2054185d686c504b74ac5bc5c06f9716f64cb Mon Sep 17 00:00:00 2001 From: Toni Rudolf Date: Wed, 8 Feb 2017 16:28:47 +0100 Subject: [PATCH 3/7] added EditInPlace tests --- Tests/Functional/EditInPlaceTest.php | 11 ++++++++++- .../app/Resources/views/translated.html.twig | 9 ++++++--- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/Tests/Functional/EditInPlaceTest.php b/Tests/Functional/EditInPlaceTest.php index 4055d60f..2e786258 100644 --- a/Tests/Functional/EditInPlaceTest.php +++ b/Tests/Functional/EditInPlaceTest.php @@ -46,8 +46,17 @@ public function testActivatedTest() @$dom->loadHTML($response->getContent()); $xpath = new \DomXpath($dom); + // Check number of x-trans tags $xtrans = $xpath->query('//x-trans'); + self::assertEquals(6, $xtrans->length); - self::assertEquals(5, $xtrans->length); + // Check attribute with prefix (href="mailto:...") + $emailTag = $dom->getElementById('email'); + self::assertEquals('🚫 Can\'t be translated here. 🚫', $emailTag->getAttribute('href')); + self::assertEquals('localized.email', $emailTag->textContent); + + // Check attribute + $attributeDiv = $dom->getElementById('attribute-div'); + self::assertEquals('🚫 Can\'t be translated here. 🚫', $attributeDiv->getAttribute('data-value')); } } diff --git a/Tests/Functional/app/Resources/views/translated.html.twig b/Tests/Functional/app/Resources/views/translated.html.twig index bbaa71ed..acb690f2 100644 --- a/Tests/Functional/app/Resources/views/translated.html.twig +++ b/Tests/Functional/app/Resources/views/translated.html.twig @@ -6,8 +6,11 @@

{{ 'translated.heading'|transchoice(12) }}

-

{{ 'translated.paragraph0'|trans }}

-

{% trans %}translated.paragraph1{% endtrans %}

-

{% transchoice 21 %}translated.paragraph2{% endtranschoice %}

+

{{ 'translated.paragraph0'|trans }}

{% trans %}translated.paragraph1{% endtrans %}

+

+ {% transchoice 21 %}translated.paragraph2{% endtranschoice %} + {{ 'localized.email'|trans }} +

+
From d510972d232a417b33a744d900a71f505f91152d Mon Sep 17 00:00:00 2001 From: Toni Rudolf Date: Wed, 8 Feb 2017 19:18:42 +0100 Subject: [PATCH 4/7] leave additional strings in attribute --- EventListener/EditInPlaceResponseListener.php | 2 +- Tests/Functional/EditInPlaceTest.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/EventListener/EditInPlaceResponseListener.php b/EventListener/EditInPlaceResponseListener.php index 4e3e8bbb..60e07f5b 100644 --- a/EventListener/EditInPlaceResponseListener.php +++ b/EventListener/EditInPlaceResponseListener.php @@ -74,7 +74,7 @@ public function onKernelResponse(FilterResponseEvent $event) $content = $event->getResponse()->getContent(); // Clean the content for malformed tags in attributes or encoded tags - $content = preg_replace("@=\\s*[\"']\\s*(.[a-zA-Z]+:|)()\\s*[\"']@mi", "=\"🚫 Can't be translated here. 🚫\"", $content); + $content = preg_replace("@=\\s*[\"']\\s*(.[a-zA-Z]+:|)()\\s*[\"']@mi", "=\"$1🚫 Can't be translated here. 🚫\"", $content); $content = preg_replace('@<x-trans.+data-key="([^&]+)".+<\\/x-trans>@mi', '🚫 $1 🚫', $content); $html = sprintf( diff --git a/Tests/Functional/EditInPlaceTest.php b/Tests/Functional/EditInPlaceTest.php index 2e786258..f6d8cad5 100644 --- a/Tests/Functional/EditInPlaceTest.php +++ b/Tests/Functional/EditInPlaceTest.php @@ -52,7 +52,7 @@ public function testActivatedTest() // Check attribute with prefix (href="mailto:...") $emailTag = $dom->getElementById('email'); - self::assertEquals('🚫 Can\'t be translated here. 🚫', $emailTag->getAttribute('href')); + self::assertEquals('mailto:🚫 Can\'t be translated here. 🚫', $emailTag->getAttribute('href')); self::assertEquals('localized.email', $emailTag->textContent); // Check attribute From e99b57b8ebf6d4f2640da36948271f98f7cbbef9 Mon Sep 17 00:00:00 2001 From: Toni Rudolf Date: Thu, 9 Feb 2017 10:41:51 +0100 Subject: [PATCH 5/7] try to add encoding to DomDocument --- Tests/Functional/EditInPlaceTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Tests/Functional/EditInPlaceTest.php b/Tests/Functional/EditInPlaceTest.php index f6d8cad5..17260cd6 100644 --- a/Tests/Functional/EditInPlaceTest.php +++ b/Tests/Functional/EditInPlaceTest.php @@ -42,7 +42,7 @@ public function testActivatedTest() self::assertSame(200, $response->getStatusCode()); self::assertContains('', $response->getContent()); - $dom = new \DOMDocument(); + $dom = new \DOMDocument('1.0', 'utf-8'); @$dom->loadHTML($response->getContent()); $xpath = new \DomXpath($dom); @@ -52,7 +52,7 @@ public function testActivatedTest() // Check attribute with prefix (href="mailto:...") $emailTag = $dom->getElementById('email'); - self::assertEquals('mailto:🚫 Can\'t be translated here. 🚫', $emailTag->getAttribute('href')); + self::assertEquals('mailto:' . '🚫 Can\'t be translated here. 🚫', $emailTag->getAttribute('href')); self::assertEquals('localized.email', $emailTag->textContent); // Check attribute From 60ce5b108b900a6d2dfe4a15918fe07a73d8c082 Mon Sep 17 00:00:00 2001 From: Toni Rudolf Date: Thu, 9 Feb 2017 10:43:49 +0100 Subject: [PATCH 6/7] cs --- Tests/Functional/EditInPlaceTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/Functional/EditInPlaceTest.php b/Tests/Functional/EditInPlaceTest.php index 17260cd6..2c46244b 100644 --- a/Tests/Functional/EditInPlaceTest.php +++ b/Tests/Functional/EditInPlaceTest.php @@ -52,7 +52,7 @@ public function testActivatedTest() // Check attribute with prefix (href="mailto:...") $emailTag = $dom->getElementById('email'); - self::assertEquals('mailto:' . '🚫 Can\'t be translated here. 🚫', $emailTag->getAttribute('href')); + self::assertEquals('mailto:'.'🚫 Can\'t be translated here. 🚫', $emailTag->getAttribute('href')); self::assertEquals('localized.email', $emailTag->textContent); // Check attribute From 4ee8db48d1b8fc543bff21e6b64257c016a2c5a0 Mon Sep 17 00:00:00 2001 From: Toni Rudolf Date: Thu, 9 Feb 2017 16:05:38 +0100 Subject: [PATCH 7/7] convert encoding --- Tests/Functional/EditInPlaceTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/Functional/EditInPlaceTest.php b/Tests/Functional/EditInPlaceTest.php index 2c46244b..8d857f72 100644 --- a/Tests/Functional/EditInPlaceTest.php +++ b/Tests/Functional/EditInPlaceTest.php @@ -43,7 +43,7 @@ public function testActivatedTest() self::assertContains('', $response->getContent()); $dom = new \DOMDocument('1.0', 'utf-8'); - @$dom->loadHTML($response->getContent()); + @$dom->loadHTML(mb_convert_encoding($response->getContent(), 'HTML-ENTITIES', 'UTF-8')); $xpath = new \DomXpath($dom); // Check number of x-trans tags