Skip to content

Conversation

@toooni
Copy link
Contributor

@toooni toooni commented Feb 4, 2017

  • fixes issue where everything was removed between two translations of html attribute contents on the same line
  • fixed issue when translation used in special link with additional content in href attribute: <a href="email:*localizedEmail*">

if a translation is used as a link (localization)`<a href="email:*localizedEmail*">` the regex wouldn't match.
@toooni toooni changed the title Attr fix fixed attribution replacement Feb 4, 2017
@Nyholm
Copy link
Member

Nyholm commented Feb 8, 2017

Thank you. Could you add a unit test to prove this regex?

@toooni
Copy link
Contributor Author

toooni commented Feb 8, 2017

Sure thing!

@toooni
Copy link
Contributor Author

toooni commented Feb 8, 2017

@Nyholm ok like this?

Copy link
Member

@Nyholm Nyholm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it looks good. Im not 100% sure about these classes though. So I would like a second review from an expert ;)

@toooni
Copy link
Contributor Author

toooni commented Feb 8, 2017

@Nyholm classes?

Copy link
Contributor

@damienalexandre damienalexandre left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with only one of the changes.

The one which remove attribute prefix looks strange to me, can you expose what is the issue with a <a href="mailto:🚫 Can't be translated here. 🚫"> link?

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'));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That means the prefix is lost? Is that always a good idea?

From my opinion the prefix should not be removed (mailto:) - we only put the <x-trans> tag where is a translation and that should not interfere with the content around it.

Copy link
Contributor Author

@toooni toooni Feb 8, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right. That's a bad idea. Already pushed the changes.

@damienalexandre
Copy link
Contributor

Ok now I'm ok with the change but the test is failing, looks like $emailTag->getAttribute('href') return a broken string mailto:� Can't be translated here. �.
Could you try to add <?xml encoding="UTF-8"> at the beginning of Tests/Functional/app/Resources/views/translated.html.twig to force UTF8 Dom parsing?

@toooni
Copy link
Contributor Author

toooni commented Feb 9, 2017

@damienalexandre That's strange. Locally the tests are green. I'l try to fix it.. but I have to commit/push each time.

@toooni
Copy link
Contributor Author

toooni commented Feb 9, 2017

@damienalexandre Can you please look at the last two commits (TravisCI). This is strange.

@damienalexandre
Copy link
Contributor

Yes it looks like there is a bug in PHP DomDocument / Travis I can't reproduce locally neither.

I will investigate 👍

@damienalexandre
Copy link
Contributor

Ok I think it works with this:

@$dom->loadHTML(mb_convert_encoding($response->getContent(), 'HTML-ENTITIES', 'UTF-8'));

As you can see here: https://travis-ci.org/php-translation/symfony-bundle/builds/199987659 / 90b3c2c

Could you update your branch accordingly?

Thanks!

@damienalexandre damienalexandre merged commit c38bf3e into php-translation:master Feb 9, 2017
@damienalexandre
Copy link
Contributor

Perfect, thanks a lot for your time and help! 👍

@toooni toooni deleted the attr_fix branch February 9, 2017 15:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants