Percent character should not be interpreted by the i18n engine
Currently if a translatable string contains the percent character (%
), such value is interpreted in the server side as a placeholder for printf style formatting.
Sometimes, though, we want to pass such characters to be used as formats for the browser (and rendered with the sprintf.js library, for instance). Currently this is done by duplicating the % character, so that the follow
{{ translate `<b>%%i%%%%</b> bounce rate between %%s and %%s` }}
will yield the english string <b>%i%%</b> bounce rate between %s and %s
to the browser, which is interpreted by sprintf:
// yields "<b>10%</b> bounce rate between aa and bb"
sprintf("<b>%i%%</b> bounce rate between %s and %s", 10, "aa", "bb")
In my opinion, the server side rendering should ignore % characters, forwarding them literally to the browser, so that the translation team don't need to remember that %
needs to be duplicated in the .po files, which is very unusual on translating software.
technical background
This issue is related to the fact that we are using gettext
files to store the translations, but the translation engine we are using is https://godoc.org/golang.org/x/text
(go-text).
Go-text
uses a different syntax for interpreting the %
differently, so what we have to do it to somehow transform a gettext
compatible string to the go-text
equivalent.