Converter-extractor for alternative message file formats

43 views
Skip to first unread message

Pedro Romano

unread,
Feb 28, 2012, 6:55:44 PM2/28/12
to Python Babel
Hello,

I have a use case where I want to merge the messages in a 'Qt
Linguist' '.ts' XML file with the messages otherwise extracted from
other source files by 'babel.messages.extract' module functionality.
It is almost as simple as defining a custom extractor for the 'Qt
Linguist' '.ts' and plugging it in by registering it on my Babel
configuration file.

However the 'babel.messages.extract' module 'extract_from_dir',
'extract_from_file' and 'extract' methods are coded to expect that a
processed file will only contain messages for itself and when the
location for the messages is generated it will obviously refer to the
'.ts' file for all messages instead of the original source files for
which I actually have the location information but have no way to pass
up from my extractor.

Would this functionality be interesting to be included in Babel? If so
I would like to eventually contribute patches for it. Any suggestions
on the best way to integrated it with the current code?

Thanks in advance for any comments regarding this matter.

Regards,
--Pedro.

Felix Schwarz

unread,
Feb 28, 2012, 7:00:45 PM2/28/12
to python...@googlegroups.com
Hi,

Am 29.02.2012 00:55, schrieb Pedro Romano:
> However the 'babel.messages.extract' module 'extract_from_dir',
> 'extract_from_file' and 'extract' methods are coded to expect that a
> processed file will only contain messages for itself and when the
> location for the messages is generated it will obviously refer to the
> '.ts' file for all messages instead of the original source files for
> which I actually have the location information but have no way to pass
> up from my extractor.
>
> Would this functionality be interesting to be included in Babel? If so
> I would like to eventually contribute patches for it. Any suggestions
> on the best way to integrated it with the current code?

Sounds like a sensible use case - though I didn't have time to check the code.
Can you outline your changes? If these are ok, you can work on a full-blown
patch :-)

fs

Pedro Algarvio

unread,
Feb 28, 2012, 7:12:56 PM2/28/12
to python...@googlegroups.com, Pedro Romano
Hello there Pedro.

If you own your .ts, or better if you're the one producing this .ts
file, can I point you to an all gettext approach?

http://blog.ufsoft.org/2012/01/23/using-gettext-in-compiled-qt-ui-files-with-pyside

That's what I'm using on my own Qt project(PyQt or PySide).

If you don't own, or do not create that .ts file yourself, yet, you
need to use it, take a look at the Glade extractor in babel's svn contrib:

http://svn.edgewall.org/repos/babel/contrib/glade/babelglade/extract.py

You could create a similar extractor, parsing the filename, line
number and string to translate, and feed that to babel instead of
letting babel parse that .ts file itself, leading to all translatable
strings pointing to the same file.

Just some ideas.

Regards,

Pedro Algarvio.

0x9C558009.asc

David Fraser

unread,
Feb 29, 2012, 2:40:48 AM2/29/12
to python...@googlegroups.com
Presumably you also know about the Translate Toolkit and its support for Qt .ts files - though not sure how useful that would be to you...
http://translate.sourceforge.net/wiki/toolkit/ts2po

Hello there Pedro.

http://blog.ufsoft.org/2012/01/23/using-gettext-in-compiled-qt-ui-files-with-pyside

http://svn.edgewall.org/repos/babel/contrib/glade/babelglade/extract.py

Just some ideas.

Regards,

Pedro Algarvio.

--
You received this message because you are subscribed to the Google Groups "Python Babel" group.
To post to this group, send email to python...@googlegroups.com.
To unsubscribe from this group, send email to python-babel...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/python-babel?hl=en.

Pedro Romano

unread,
Feb 29, 2012, 3:55:41 AM2/29/12
to Python Babel
David,

Yes I started with the Translate Toolkit 'ts2po' approach, but the
file locations were lost that way because 'ts2po' doesn't convert
these on to the .po file it just uses the context names. Since writing
the babel extractor seemed quite trivial I opted for that as the
simplest/cleanest approach.

Pedro,

I think I had already came across the 'exclusively gettext approach
bypassing Qt Linguistic' approach for Qt translations, but for some
reason I had forgotten about it. I shall revisit it and the check the
Glade extractor also.

Thanks everyone for the excellent feedback! I shall get back in touch
with any interesting information or any patches if I go that route.

--Pedro.

On Feb 29, 7:40 am, David Fraser <dav...@sjsoft.com> wrote:
> Presumably you also know about the Translate Toolkit and its support for Qt .ts files - though not sure how useful that would be to you...http://translate.sourceforge.net/wiki/toolkit/ts2po
>
>
>
>
>
>
>
> ----- Original Message -----
> From: "Pedro Algarvio" <pe...@algarvio.me>
> To: python...@googlegroups.com
>
> Cc: "Pedro Romano" <pmcn...@gmail.com>
> Sent: Wednesday, February 29, 2012 2:12:56 AM
> Subject: Re: Converter-extractor for alternative message file formats
>
> Hello there Pedro.
>
> If you own your .ts, or better if you're the one producing this .ts
> file, can I point you to an all gettext approach?
>
> http://blog.ufsoft.org/2012/01/23/using-gettext-in-compiled-qt-ui-fil...

Pedro Romano

unread,
Feb 29, 2012, 12:56:32 PM2/29/12
to Python Babel
As a wrap-up to this: I decided to go with monkey patching the PyQt UI
compiler and using gettext everywhere else. It was the simplest and
cleanest solution.

Thanks again for all feedback!

--Pedro.
Reply all
Reply to author
Forward
0 new messages