grunt-angular-translate
grunt-angular-translate copied to clipboard
Ternary operator parsing produces some false results
With the patch from PR #69 the code snippet below will generate both the false translation keys active and non-active in addition to the correct one STATE_LABEL.
<a ng-class=" state==3 ? 'active': 'non-active'">
<span>3</span> {{'STATE_LABEL' | translate}}
</a>
If I disable the HtmlFilterTernary regex (by commenting it out in tasks/angular-translate.js the extraction works as expected (only extracting STATE_LABEL).
I believe that this pattern for HtmlFilterTernary would work better:
\s*(?:::)?([^?|}]*\?[^:]*:[^|}]*)\s*\|\s*translate(:.*?)?\s*
The change is in the first character class which was [^?]* (match any characters not ?) to [^?|}]* (match any characters not ?, |, or }). This prevents the match from crossing too many other interpolation sequences.
In the meantime, adding a comment like this will help to prevent this regex from matching incorrectly. I inserted it after a ternary before the next translate.
<!-- Prevent grunt-angular-translate from incorrectly matching: ?|: -->
Edited: with a more effective comment.