Vue-i18n: How to put HTML elements in translations?

Created on 5 Jan 2016  路  15Comments  路  Source: kazupon/vue-i18n

This will print out <br /> instead of a linebreak:

module.exports = {
  en: {
    index: {
       headline: 'Testing html <br /> with i18n'
    }
  }
}

Most helpful comment

What would also be great would be able to render functions like v-link and @click. For example say I have the below json:

{
    "message": "This is a message <a v-link="{name: 'linkName'}">with a link</a>"
}

It doesn't render the v-link right now. Is this something you could implement?

As always, thanks

All 15 comments

+1

Any update with this? Thanks

If you wrap the translation in 3 brackets like:

{{{ $t("message.hello") }}}

it does actually render the HTML correctly. But is it good practise to do that?

thanks @aaronjpitts.

I think @aaronjpitts solved this. I'm closing this as it's working for me aswell. Thank you!

@sagaio could you re-open the issue ? and consider the issue solved when the documentation has clarified the solution ? I can make a pull request for this one if you want.

Sure. Nice PR!
For the record It's also stated on VueJS offical page: http://vuejs.org/guide/syntax.html#Raw_HTML

@guillaumevincent thanks!
ping @kazupon

@guillaumevincent
Welcome Pull request :smiley_cat:

@kazupon the PR is already done :

https://github.com/guillaumevincent/vue-i18n/pull/1

What would also be great would be able to render functions like v-link and @click. For example say I have the below json:

{
    "message": "This is a message <a v-link="{name: 'linkName'}">with a link</a>"
}

It doesn't render the v-link right now. Is this something you could implement?

As always, thanks

ping @kazupon

@guillaumevincent
Can you send to kazupon/vue-i18n PR please ?

@aaronjpitts
Hmm, :disappointed:
It cannot render the directive as v-link, because it need to compile the directive.

Sorry @kazupon don't understand what I've done :(
here the good pull request : https://github.com/kazupon/vue-i18n/pull/20

Was this page helpful?
0 / 5 - 0 ratings