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

manikanta896 avatar May 23 '16 13:05 manikanta896

+1

nicolasmoise avatar Aug 31 '16 19:08 nicolasmoise

+1

danpe avatar Nov 29 '16 16:11 danpe

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

christianesperar avatar Jan 28 '18 15:01 christianesperar