I also found a temporary fix to apply to my code by escaping format with a
second %:
{{ obj.creation_date|date(_('%%B %%d, %%Y')) }}
Which I translate:
msgid "%%B %%d, %%Y"
msgstr "%%d %%B, %%Y"
On Friday, November 2, 2012 2:04:47 PM UTC-7, deBrice wrote:
>
> Hi guys,
>
> I use jinja i18n extension and recently I faced problem with date format
> translation. I have differents date format per languages. So I decided to
> also translate date format in my catalog:
>
> {{ obj.creation_date|date(_('%B %d, %Y')) }}
>
> So to get the day in front of the month in my .po file I have:
>
> msgid "%B %d, %Y"
> msgstr "%d %B, %Y"
>
> The issue is that _new_gettext context function from i18n jinja ext tries
> to apply the kwarg variables to the string when this one is empty.
> The result is:
>
> >>> u'%d %B, %Y' % {}
> Traceback (most recent call last):
> File "<stdin>", line 1, in <module>
> TypeError: an integer is required
>
> Here is the first fix that came into my mind.
>
> def _make_new_gettext(func):
> @contextfunction
> def gettext(__context, __string, **variables):
> rv = __context.call(func, __string)
> if __context.eval_ctx.autoescape:
> rv = Markup(rv)
> return variables and rv % variables or rv
> return gettext
>
> All the best,
>
> Brice
>
--
You received this message because you are subscribed to the Google Groups
"pocoo-libs" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/pocoo-libs/-/HQC9siOSInsJ.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/pocoo-libs?hl=en.