Core: Translate html code

Created on 5 Apr 2016  路  5Comments  路  Source: ngx-translate/core

I have html code inside my json file

{ "contactEMailDescription": "Contact <a href='mailto:{{value}}@foo.bar'>{{value}}</a> for more information" }

My html template
<div class="panel-footer"><small>{{ 'contactEMailDescription' | translate:{value:'info'} }}</small></div>

The outcome is not treated as html syntax, just as plain text.

Contact <a href='mailto:[email protected]'>fibi</a> for more information

when I would like it to look like:
Contact fibi for more information

Is it not possible to add html code inside the translate json file?

questiosupport

Most helpful comment

It is, but you're outputing the translation as text. If you want html you should do that:

<div class="panel-footer"><small [innerHTML]="'contactEMailDescription' | translate:{value:'info'}"></small></div>

All 5 comments

It is, but you're outputing the translation as text. If you want html you should do that:

<div class="panel-footer"><small [innerHTML]="'contactEMailDescription' | translate:{value:'info'}"></small></div>

I love the angular2 magic. Thanks :+1:

Hi @ocombe,
I propose to add information from this thread to documentation page.
IMHO it's quite common use case and more people (including also me) may have such problem.
Anyway, great thanks for help! :)

Hi,
[innerHTML]="'HOME.CHANNELS_TEXT' | translate "

HOME.CHANNELS_TEXT = <div class = 'div1' > **some text** </div>

I can't attach css style from current.component.css to .div1, (.div1 { color : lime;} ) , but if i give it from main style.css its working. why?

Hi,
[innerHTML]="'HOME.CHANNELS_TEXT' | translate "

HOME.CHANNELS_TEXT = <div class = 'div1' > **some text** </div>

I can't attach css style from current.component.css to .div1, (.div1 { color : lime;} ) , but if i give it from main style.css its working. why?

try using
encapsulation: ViewEncapsulation.None,
on the component
it worked for me

Was this page helpful?
0 / 5 - 0 ratings

Related issues

briancullinan picture briancullinan  路  3Comments

guysan picture guysan  路  4Comments

alkemist picture alkemist  路  3Comments

chris31389 picture chris31389  路  3Comments

dankerk picture dankerk  路  3Comments