Looking for a replacement for i18ndude or an improved version

I am looking for an improved version of i18ndude (by checking v3.2.2) or some kind of successor. i18ndude extracts translatable strings from Python code (using pygettext) and Zope page templates, but this is somewhat impossible:

  • It hides the pygettext command line options and thus does this, for example. it is impossible to specify keywords without breaking the code
  • It’s hard to understand and hard to expand (for example, you can somehow add parsing of Javascript files)
  • The command line syntax is cumbersome (for example, "i18ndude merge --pot ... --merge ... --merge2 ...")
  • Some files are not parsed or processed incorrectly, as a result some lines are not found (for example, each file with the name "* pt" is considered HTML, even "* .xml.pt").
  • Development seems to have ended in 2010.

It would be nice to have something

  • with a better command line interface, for example. like Subversion, supporting the command and help command
  • easily extensible
  • easy to configure (for example, which files are analyzed using that parser or how to report the type of files, for example, taking into account the properties of svn: mime-type)

Since the command line interface is most likely incompatible with one of the i18ndude, I think it's better to go for a replacement.

Has anyone already written such a tool and wants to share it, or is it still to be done?

+4
source share
1 answer

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.

+4
source

Source: https://habr.com/ru/post/1413132/


All Articles