Hugo: i18n template escapes HTML

Created on 16 Sep 2016  路  3Comments  路  Source: gohugoio/hugo

This is a problem for strings like foo <a href="...">bar</a>. It is possible to separate the translation into two separate calls to i18n, but this breaks languages that have different orderings of verb / subject.

Is there a way to disable HTML escaping when using go-i18n to translate strings?

Most helpful comment

Just tested this and can confirm that {{ i18n "foo" | safeHTML }} does what you're asking for, @VoidingWarranties.

And that's how it should be in Go templates. If you want to be unsafe, be explicit. :)

All 3 comments

Maybe ... I haven't thought that through. but wouldn't a {{ i18n "foo" | html }} also do the trick?

/cc @moorereason @digitalcraftsman @mitchchn

Just tested this and can confirm that {{ i18n "foo" | safeHTML }} does what you're asking for, @VoidingWarranties.

And that's how it should be in Go templates. If you want to be unsafe, be explicit. :)

Thank you @bep and @mitchchn! Works exactly as you said.

Was this page helpful?
0 / 5 - 0 ratings