Custom keywords per extractor

105 views
Skip to first unread message

Martin Myrseth

unread,
Nov 5, 2012, 12:02:06 PM11/5/12
to python...@googlegroups.com
I would like to to run `pybabel extract` on a project tree, extracting strings from python, mako and javascript.

Python and mako should use the default keywords (or something like it), which also works quite nicely.
However, using '_' as a translation function in JS isn't really all that nice due to libraries like underscore.js,
and other libraries mounting under '_'. E.g., _("Please, don't translate me").isString().

So ... I don't seem to be able to accomplish this with the mappings file.

I was looking at the following section in the Babel docs:

Particularly:

# Extraction from JavaScript files
[javascript: **.js]
extract_messages = $._, jQuery._

That does not seem to work, though. Or, that example does, but only because the translation function
is in fact '_' with a prefix. Looking at the source for babel.messages.extract.extract_javascript,
it doesn't seem like the function really uses anything from the passed in options besides the encoding.

This invalidates the example from the Babel docs.

In other words, there's seems to be no way to locally override the keywords for a specific extractor
(in this case the built-in ones)? For custom extractors you could somewhat control which keywords you
would like to use based on an option key. However, *that* breaks once 'extract' re-receives control from
the extractors, as it tries to map the function names from the results into the keyword dict in order to get
the argument spec.

Running pybabel twice using different mappings doesn't work either, as the strings extracted from the
first run are removed by the second.
Reply all
Reply to author
Forward
0 new messages