Support for non-Python projects

9 views
Skip to first unread message

Adrián Chaves Fernández

unread,
Oct 11, 2013, 1:52:32 AM10/11/13
to python...@googlegroups.com
Hi there,

I need to extract messages for a JavaScript/C++ game (0 A.D.). It requires pretty different string extractions, such as line-by-line extraction of plain text files ignoring empty lines, extraction of JSON, extraction of XML, extraction of JSON within XML, and extraction from JavaScript and C++ files as well. I have all this in place already using Bash (with some tools such as itstool for XML or the Translate Toolkit for JSON, plus GNU Gettext for source code and some dirty hack for the rest), and now I’m looking into translating this into Python. And the only Python library for message extraction that I found was yours (Translate Toolkit seems to be more focused on conversion between formats than on extraction, as it does not seem to be able to extract messages from source files, but I might be wrong).

My main concern is whether my purpose fits the goals of this project; that is, whether or not patches to fix issues I run into to get what I need would be rejected because I’m not using Babel "for internationalizing Python applications". I would perfectly understand that you want to focus on Python applications and Python applications only, I just want to know.

For example, I’ve already manage to extract the C++ strings using a custom extractor which is actually just the built-in JavaScript extractor, with kind of works already. However, I did notice that Babel automatically inserts a “python-format” tag to messages, regardless of what I do (this is done in the Message class initialization). So, instead of having this:

    catalogObject.add(message, locations=[(filepath, lineNumber)], auto_comments=comments)

I have this:

    messageObject = Message(message, locations=[(filepath, lineNumber)], auto_comments=comments)
    messageObject.flags = ("c-format",)
    catalogObject[message] = messageObject

I also noticed that messages added to a catalog just overwrite the existing message, and there is not way to merge a message instead, so instead of “catalogObject[message] = messageObject”, I actually do the following:

    if message not in template:
        template[message] = messageObject
    else:
        template[message].locations.add((filepath, lineNumber))
        template[message].auto_comments.update(comments)

Finally, I’ve not seen anything about using context for translation messages, so I can only guess that this is not supported.
Reply all
Reply to author
Forward
0 new messages