Skip to content Skip to sidebar Skip to footer

How To Escape '%' Character In Jinja 2.10 {% Trans %} Using Pybabel?

I am using jinja 2.10 and pybabel. When my template contains following code (with '%' char inside trans block) pybabel-compile does not translate the string. The extracted string (

Solution 1:

Another way: {% trans percent='%' %}100{{ percent }} anonymity{% endtrans %}

Solution 2:

I had stuck about this too, but I found in Babel documentation the solution:

##flask.ext.babel.gettext(string, **variables)####Translates a string with the current locale and passes in the given keyword arguments as mapping to a string formatting string.

gettext(u'Hello World!')
gettext(u'Hello %(name)s!', name='World')

And I translate to simple code like this:

_('Hello %(name)s!', name='World%')

I hope I help you :D

Post a Comment for "How To Escape '%' Character In Jinja 2.10 {% Trans %} Using Pybabel?"