Skip to content

Remove the ng-binding class from text before lookup#94

Merged
rubenv merged 8 commits intorubenv:masterfrom
circlingthesun:ng-binding-fix
Aug 22, 2014
Merged

Remove the ng-binding class from text before lookup#94
rubenv merged 8 commits intorubenv:masterfrom
circlingthesun:ng-binding-fix

Conversation

@circlingthesun
Copy link
Copy Markdown
Contributor

When using ng-href and related directives, the 'ng-binding' class gets added to elements before the translate directive can get to it. This patch strips the ng-binding class from elements inside the translate directive to that the msgid lookup succeeds.

@rubenv
Copy link
Copy Markdown
Owner

rubenv commented Aug 18, 2014

That sounds like a bug. Have a look at how the directive is written. It's marked as terminal so it shouldn't process the contents until we inject it again.

Which version are you testing this with?

On 18 Aug 2014, at 17:43, Rickert Mulder notifications@github.com wrote:

When using ng-href and related directives, the 'ng-binding' class gets added to elements before the translate directive can get to it. This patch strips the ng-binding class from elements inside the translate directive to that the msgid lookup succeeds.

You can merge this Pull Request by running

git pull https://github.com/circlingthesun/angular-gettext ng-binding-fix
Or view, comment on, or merge it at:

#94

Commit Summary

Remove the ng-binding class from text before lookup
Strip ng-binding in the presence of other classes
File Changes

M Gruntfile.js (2)
M dist/angular-gettext.js (5)
M dist/angular-gettext.min.js (2)
M src/directive.js (6)
M test/unit/directive.js (11)
Patch Links:

https://github.com/rubenv/angular-gettext/pull/94.patch
https://github.com/rubenv/angular-gettext/pull/94.diff

Reply to this email directly or view it on GitHub.

@circlingthesun
Copy link
Copy Markdown
Contributor Author

Version of Angular? Same one as in the unit test (~1.2.0), the same also happens with 1.3 beta. ng(Ref/Src/Srcset/...) has a priority of 100 which is higher than translate's 350 (see https://github.com/angular/angular.js/blob/833e60a203263a81a24d773c82c3563c3fb2c97c/src/ng/directive/attrs.js#L355).

@rubenv
Copy link
Copy Markdown
Owner

rubenv commented Aug 18, 2014

It's lower :-)

See https://github.com/angular/angular.js/blob/833e60a203263a81a24d773c82c3563c3fb2c97c/src/ng/compile.js#L121-L127

So from my understanding, ng-href shouldn't even run. Need to investigate.

Oh, also, I haven't gotten round to reviewing the other patches yet, sorry for that.

@circlingthesun
Copy link
Copy Markdown
Contributor Author

Post link functions are run in reverse priority order so functions with lower numbers are executed first. Don't stress about the patches, I have my local copies :)

@demetriusnunes
Copy link
Copy Markdown

+1

@rubenv
Copy link
Copy Markdown
Owner

rubenv commented Aug 20, 2014

Surely this must be fixable by tuning the priority / doing things in compile vs link?

I mean, it feels very wrong to be messing around with the HTML that comes out, that's just a recipe for future breakage.

I'd love to see this fixed, but I have a feeling that there's a better way to do this.

@circlingthesun
Copy link
Copy Markdown
Contributor Author

Well, to avoid the ng-binding class one would have to set the priority to less that 100 which seems to break other tests. I've not had a hard look at why other tests break though. There may be a better solution. That would be nice.

@circlingthesun
Copy link
Copy Markdown
Contributor Author

So the problem is that the ng-binding attribute gets added during the compile phase of the ngBind directive. The translate directive first runs at link time at when it is too late. The element content cannot be accessed at compile time when using a transclusion. So you either need to retrieve the element html a 3rd translate directive, or get rid of the transclusion. I did the later as well as getting rid of the 2nd directive. Mmm... it seems I borked things.

@circlingthesun
Copy link
Copy Markdown
Contributor Author

...and its fixed. Thats a bit more elegant right?

Comment thread test/unit/directive.js
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

That's Afrikaans, right?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yeah, also known as kitchen dutch ;p

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Corrected this in 8fa33ba. I'm cool with having Afrikaans in the test suite [1], but it needs to be in the right language code.

[1] I have very fond memories of South Africa.

@rubenv
Copy link
Copy Markdown
Owner

rubenv commented Aug 21, 2014

Looking very good, I'll need to do some thorough testing to make sure we don't hit any corner-cases.

@rubenv rubenv merged commit 1cc047a into rubenv:master Aug 22, 2014
@rubenv
Copy link
Copy Markdown
Owner

rubenv commented Aug 22, 2014

Haven't found any issues with this patch. Let's release it. I'll bump the minor version to avoid any breakage, but I have yet to encounter some.

rubenv added a commit that referenced this pull request Aug 22, 2014
@rubenv
Copy link
Copy Markdown
Owner

rubenv commented Aug 22, 2014

Released to NPM as 1.1.0. Once again, fantastic work. Happy to see this fixed cleanly. Thanks!

@rubenv rubenv removed the needs work label Aug 22, 2014
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