Have you tried Babel ? It supports a plugin system for extracting messages from different sources.
lingua provides plugins for ZPT and zope.i18nmessageid, giving you all the features of i18ndude, but with a fairly active open source community.
To use babel in your project, you need to configure the setup.py file to use the babel commands , then run these functions as a setting for the .py command; e.g. python yourpackage/setup.py extract_messages
.
If a lingua
egg is available as a dependency, you can connect it to the message_extractors
structure in 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), ], }, ... )
Please note: you cannot include Babel as a setup_requires dependency, since setup.py script only works if it can actually import Babel! You can try and work around this by creating pads for cmdclass entries, but I haven't tried it 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, this option expects an INI file format with the [method fileglob]
:
[lingua_python **.py] [lingua_xml **/templates/**.pt]
Each section may contain options that should be passed to the extractor function (each line of option = value
becomes a key-value pair in the dict options passed to it), but I do not think that the lingua_ * methods accept any parameters.
Extractor configurations are then used for each input directory specified on the command line, or for each package specified in the setup.py packages
parameter.