I came with this extraction method for babel:

from web.template import Template
import StringIO
from babel.messages.extract import extract_python

def extract_webpy(fileobj, keywords, comment_tags, options):
    code = Template.generate_code(fileobj.read(), fileobj.name)
    return extract_python(StringIO.StringIO(code), keywords,
comment_tags, options)

haven't tested it yet, but i think it should work :)


On Dec 2, 12:32 am, andrei <[EMAIL PROTECTED]> wrote:
> Well, it doesn't work for me.
> I've got a new idea. Since webpy translates templates to python code
> before compiling them - then it would be possible to somehow extract
> messages from the python code of template.
> I will try to dig this way.
>
> On Dec 1, 4:41 am, Zhang Huangbin <[EMAIL PROTECTED]> wrote:
>
> > andrei wrote:
> > > On Nov 30, 5:41 pm, Zhang Huangbin <[EMAIL PROTECTED]> wrote:
> > > > I use pygettext.py to extract messages from webpy template files, and
> > > > it works. I don't know why you got this error msg. :(
>
> > > Can you please try to extract message from this 
> > > file:http://old.etoleto.com/base.html
> > > and tell me if it works ?
>
> > Hi, Andrei.
>
> > file: templates/default/base.html
> > ----<----
> > $def with (page=None, title=None) $if title: $else:       $:js
> > (session.section) $:css(session.section)
> > FleXoft
>
> > $if session.user: ${session.user.login}: $for url in urls
> > (session.user.type): $if not loop.first: / $url.name / $_('Logout')
> > $:page
> > ----<----
>
> > Shell command:
> > ----<----
> > $ python pygettext.py -a -v -d messages -o messages.po ../*.py ../
> > templates/default/*.html
> > ----<----
>
> > In messages.po ('Logout' is only used in base.html, so it's extracted
> > from it):
> > ----<----
> > #: ../templates/default/base.html:4
> > msgid "Logout"
> > msgstr ""
> > ----<----
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"web.py" group.
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/webpy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to