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
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
I know I posted a temporary fix that might seems to be more like a good permanent solution than a temporary one but I want to insist on the fact that it creates 2 different formats within the po file:
# format translation for date formatting on backend # obj.creation_date.strftime(_("%B %d, %Y")) msgid "%B %d, %Y" msgstr "%d %B, %Y"
# format translation for date formatting on jinja2 # {{ obj.creation_date|date(_("%%B %%d, %%Y")) }} 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