angular / angular.js

AngularJS - HTML enhanced for web apps!
https://angularjs.org
MIT License
58.82k stars 27.51k forks source link

ngPluralize: support for HTML tags in translations? #4790

Open ysbaddaden opened 10 years ago

ysbaddaden commented 10 years ago

I found myself in a situation where some of the translation, and not all, must be within a strong tag. Since the ngPluralize directive uses element.text() (source) then the string is HTML escaped, and it doesn't work.

<ng:pluralize count="users.length" when="{other:'<strong>{}</strong> users'}" />

Since it may lead to XSS issues, I was wondering how to allow ngPluralize to use element.html() in some cases. If $interpolate already escapes the interpolated values, then maybe the directive could use element.html()? Or may be add an attribute like as="html" to give the user control over the HTML safeness of the translation? All it would need then is:

function ngPluralizeWatchAction(newVal) {
  if (attr.as === 'html') {
    element.html(newVal);
  } else {
    element.text(newVal);
  }
}
samward1985 commented 10 years ago

+1

Casperd88 commented 10 years ago

+1

guillaumesmo commented 10 years ago

+1

wagnerdevel commented 10 years ago

+1

hamsterready commented 10 years ago

+1

josh256 commented 10 years ago

+1

xaralis commented 10 years ago

+1

PatrickWolleb commented 10 years ago

+1

jbielick commented 10 years ago

+1

amitport commented 10 years ago

:+1:

squarecapadmin commented 9 years ago

+1

blair55 commented 9 years ago

+1

scanferla commented 9 years ago

+1

shanecp commented 9 years ago

+1

imjoshholloway commented 9 years ago

+1. In the mean time I've created a gist that I'm using in place of ngPluralize where I need HTML

krazi3 commented 9 years ago

+1

AshCoolman commented 9 years ago

:+1:

thicolares commented 9 years ago

+1

jhalley commented 9 years ago

+1

lgalfaso commented 9 years ago

Using html with pluralize should be strait-forward with a small ad-hoc directive as it is the case here http://plnkr.co/edit/mkKt5rqYorGu4a1t93J8?p=preview

manikanta896 commented 8 years ago

+1

nicolasmoise commented 8 years ago

+1

danpe commented 7 years ago

+1

christianesperar commented 6 years ago

Hi, this seems a little bit late, but in case anyone still has some problem with this one, I created directives that can solve this problem. It can be found here https://github.com/christianesperar/ng-pluralize-html

You can see it in action here https://rawgit.com/christianesperar/ng-pluralize-html/master/example/github.html