Skip to content
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
2 changes: 1 addition & 1 deletion EventListener/EditInPlaceResponseListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -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*(<x-trans.+<\\/x-trans>)\\s*[\"']@mi", "=\"🚫 Can't be translated here. 🚫\"", $content);
$content = preg_replace("@=\\s*[\"']\\s*(.[a-zA-Z]+:|)(<x-trans.+?(?=<\\/x-trans)<\\/x-trans>)\\s*[\"']@mi", "=\"$1🚫 Can't be translated here. 🚫\"", $content);
$content = preg_replace('@&lt;x-trans.+data-key=&quot;([^&]+)&quot;.+&lt;\\/x-trans&gt;@mi', '🚫 $1 🚫', $content);

$html = sprintf(
Expand Down
15 changes: 12 additions & 3 deletions Tests/Functional/EditInPlaceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,21 @@ public function testActivatedTest()
self::assertSame(200, $response->getStatusCode());
self::assertContains('<!-- TranslationBundle -->', $response->getContent());

$dom = new \DOMDocument();
@$dom->loadHTML($response->getContent());
$dom = new \DOMDocument('1.0', 'utf-8');
@$dom->loadHTML(mb_convert_encoding($response->getContent(), 'HTML-ENTITIES', 'UTF-8'));
$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('mailto:'.'🚫 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'));
}
}
9 changes: 6 additions & 3 deletions Tests/Functional/app/Resources/views/translated.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@
</head>
<body>
<h1>{{ 'translated.heading'|transchoice(12) }}</h1>
<p>{{ 'translated.paragraph0'|trans }}</p>
<p>{% trans %}translated.paragraph1{% endtrans %}</p>
<p>{% transchoice 21 %}translated.paragraph2{% endtranschoice %}</p>
<p>{{ 'translated.paragraph0'|trans }}</p><p>{% trans %}translated.paragraph1{% endtrans %}</p><!-- two translation in same html line -->
<p>
{% transchoice 21 %}translated.paragraph2{% endtranschoice %}
<a id="email" href="mailto:{{ 'localized.email'|trans }}">{{ 'localized.email'|trans }}</a><!-- translation inside attribute with additional content -->
</p>
<div id="attribute-div" data-value="{{ 'translated.attribute'|trans }}"></div> <!-- translation inside html attribute -->
</body>
</html>