Looking for a replacement for i18ndude, or an improved version
gettext, internationalization, plone, python, zope
Solution
Have you tried Babel? It supports a plugin system for extracting messages from various sources.
lingua provides plugins for ZPT and zope.i18nmessageid, giving you all the functionality of i18ndude, but with a reasonably active Open Source community.
To use babel in your project, you'll need to configure your setup.py to use babel commands, then run those functions as setup.py commands; e.g. `python yourpackage/setup.py extract_messages`.
Provided the `lingua` egg is available as a dependency, you can then it's plugins in the `message_extractors` structure in your setup.py to tell Babel how to extract i18n messages from your source files:
...
from babel.messages import frontend as babel
...
setup(...
setup_requires=['lingua'],
cmdclass = dict(
compile_catalog=babel.compile_catalog,
extract_messages=babel.extract_messages,
init_catalog=babel.init_catalog,
update_catalog=babel.update_catalog,
),
message_extractors = {
'path/in/package': [
('**.py', 'lingua_python', None),
('**/templates/**.pt', 'lingua_xml', None),
],
},
...
)
Note that you cannot include Babel as a setup_requires dependency, as the setup.py script only works if it can actually import babel! You could try and work around this by creating shims for the cmdclass entries, but I haven't tried this myself yet. For now, just install the Babel egg in your virtualenv or globally.
If you want to use the `--mapping-file` CLI option instead of the `message_extractors` entry, that option expects an INI-style file format with `[method fileglob]` headers:
[lingua_python **.py]
[lingua_xml **/templates/**.pt]
Each section can contain options to be passed to the extractor function (each `option = value` line becomes a key-value pair in the options dict passed to it), but I don't think the lingua_* methods take any options.
The extractor configurations are then used for every input dir you mention on the command line, or each package mentioned in the setup.py `packages` option.
Problem
I'm looking for an improved version of i18ndude (having checked out v3.2.2), or some kind of successor. i18ndude extracts translatable strings from Python code (using pygettext) and Zope page templates, but it is somewhat unfulfilling: - It hides the commandline options of pygettext and thus makes it e.g. impossible to specify keywords without hacking the code - It is hard to understand and hard to extend (e.g., one might want to add parsing of Javascript files somehow) - The commandline syntax is cumbersome (e.g. "i18ndude merge --pot ... --merge ... --merge2 ...") - Some files are not parsed or parsed in a wrong way, resulting in some strings not being found (e.g. every file named something like "*pt" is considered HTML, even "*.xml.pt"). - Development seems to have ended in 2010. It would be nice to have something - with a better commandline interface, e.g. like the one of Subversion, supporting "command" and "help command" - easily extendable - easily configurable (e.g. what kind of files to parse using which parser, or how to tell the type of files, e.g. taking svn:mime-type properties into account) Since the commandline interface would likely be incompatible to the one of i18ndude, I consider it best to go for a replacement. Has anybody written such a tool by now and is willing to share it, or is this a task still to be done?