angular.js icon indicating copy to clipboard operation
angular.js copied to clipboard

ngPluralize: support for HTML tags in translations?

Open ysbaddaden opened this issue 13 years ago • 24 comments

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);
  }
}

ysbaddaden avatar Nov 05 '13 13:11 ysbaddaden

+1

samward1985 avatar Jan 09 '14 04:01 samward1985

+1

Casperd88 avatar Mar 14 '14 14:03 Casperd88

+1

guillaumesmo avatar Apr 18 '14 02:04 guillaumesmo

+1

wagnerdevel avatar Apr 30 '14 14:04 wagnerdevel

+1

hamsterready avatar May 23 '14 12:05 hamsterready

+1

josh256 avatar May 28 '14 19:05 josh256

+1

xaralis avatar Jul 24 '14 07:07 xaralis

+1

PatrickWolleb avatar Aug 01 '14 13:08 PatrickWolleb

+1

jbielick avatar Aug 15 '14 20:08 jbielick

:+1:

amitport avatar Oct 20 '14 21:10 amitport

+1

squarecapadmin avatar Nov 03 '14 04:11 squarecapadmin

+1

blair55 avatar Nov 10 '14 23:11 blair55

+1

scanferla avatar Dec 23 '14 18:12 scanferla

+1

shanecp avatar Jan 02 '15 10:01 shanecp

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

imjoshholloway avatar Jan 15 '15 17:01 imjoshholloway

+1

krazi3 avatar Apr 01 '15 20:04 krazi3

:+1:

AshCoolman avatar Apr 27 '15 17:04 AshCoolman

+1

thicolares avatar Jul 08 '15 12:07 thicolares

+1

jhalley avatar Jul 22 '15 04:07 jhalley

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

lgalfaso avatar Jul 26 '15 13:07 lgalfaso