angularangular-translate

Translate pipe with parameters


I'm using translate pipe. I have a string, that include website of my company and I shouldn't translate it. So I use parameters. But website should be a link(tag ). How can I do it?

<p class="al-privacy-policy-text">{{"PRIVACY_POLICY_PAGE.INTRODUCTION_TEXT" | translate: ({website: 'https://www.title.com/'})}}</p>

Now https://www.title.com is a simply text.

"PRIVACY_POLICY_PAGE.INTRODUCTION_TEXT": " ...when using our website {{website}}..."


Solution

  • Change the content of PRIVACY_POLICY_PAGE.INTRODUCTION_TEXT to use an anchor tag for the website placeholder. Then use innerHtml to allow html content so it will not be sanitized.

    <p class="al-privacy-policy-text" [innerHTML]="'PRIVACY_POLICY_PAGE.INTRODUCTION_TEXT' | translate: ({website: 'https://www.title.com/'})"></p>
    

    See also Sanitization and security contexts and How to include html tags in your translation strings