rubenv / angular-gettext-tools

Tools for extracting/compiling angular-gettext strings.
http://angular-gettext.rocketeer.be/
MIT License
39 stars 130 forks source link

Extractor issue: Double quotes in html attribute #78

Open HarryBurns opened 9 years ago

HarryBurns commented 9 years ago

Hi!

If we'll try to process such html with angular-gettext-tools:

<input id="title" placeholder="'{{'BlahBlahBlah'|translate}}'"/>
<!-- Yes, we really need such "' quotes -->

It will produce duplicate keys:

As you see, in html attribute we have single quotes inside double quotes, and I think that's the problem.

I think, you need to make Regex for html attributes more 'hungry' in exports.js. For example, by changing this line to start = '^.*';. It works for me, but I don't know about side-effects.

rubenv commented 9 years ago

Have you tried this:

<input id="title" placeholder="'BlahBlahBlah'|translate"/>

?

rubenv commented 9 years ago

I think, you need to make Regex for html attributes more 'hungry' in exports.js. For example, by changing this line to start = '^.*';. It works for me, but I don't know about side-effects.

That will cause a lot of problems with multiple matches. Go ahead and try it though.

Do try the code above, that's probably the right fix for your case.

(apologies for the open/close, that was an accident).

HarryBurns commented 9 years ago

Thanks for speedy answer!

Do try the code above, that's probably the right fix for your case.

In current case - yes, it will help. But it was only an example. Angular with Kendo sometimes force me to use tricky expressions inside attributes(with multiple filters, casting and some black kendo magic), that can't be parsed by your engine properly.

I think, there is the way to modify regex to find only "Text"|translate template from any mess in attribute expression.

Now I'm using a lot of custom directives to avoid such situations... If your RegEx magic is too complex to touch it - it's ok, there is a lot of workarounds for this cases, just a little more tricky.

rubenv commented 9 years ago

Well, we have a pretty decent test suite, so you're definitely allowed to modify the Regex.

I'm not going to spend my time debugging Kendo madness, but I'll happily accept any fixes for it.