Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
i18n ext , gettext and date format
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  3 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
deBrice  
View profile  
 More options Nov 2 2012, 5:04 pm
From: deBrice <bbrriic...@gmail.com>
Date: Fri, 2 Nov 2012 14:04:47 -0700 (PDT)
Local: Fri, Nov 2 2012 5:04 pm
Subject: i18n ext , gettext and date format

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 must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
deBrice  
View profile  
 More options Nov 2 2012, 5:34 pm
From: deBrice <bbrriic...@gmail.com>
Date: Fri, 2 Nov 2012 14:34:50 -0700 (PDT)
Local: Fri, Nov 2 2012 5:34 pm
Subject: Re: i18n ext , gettext and date format

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"


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
deBrice  
View profile  
 More options Nov 7 2012, 11:16 am
From: deBrice <bbrriic...@gmail.com>
Date: Wed, 7 Nov 2012 08:16:31 -0800 (PST)
Local: Wed, Nov 7 2012 11:16 am
Subject: Re: i18n ext , gettext and date format

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"


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »