This pull requests adds a lingua plugin to Mako. In addition it adds a couple of high-level tests for the existing Babel plugin, and refactors that plugin a bit to allow reuse of the basic parsing code.
Please note that this is still a work in progress, so please don't merge it as-is. There are a couple of things I still want to do:
Run this on some real world mako templates. Since I've never used Mako myself any pointers to examples would be very welcome :)
Lingua itself needs a better API to access its Python parser. I want to have that in place before getting this out - the current use of _extract_python is a bit dirty.
I've just pushed out lingua 3.2 which cleans up the API to call into extractors and updated the Mako plugin to match. I also extended the tests a bit to run gettext.mako through the lingua plugin as well, which revealed an interesting bug.
As far as I can see this is now ready for merging.
I've removed babel and lingua as test dependencies and added these back into the "skip" system (beaker is already not defaulted there either). babel in particular is causing problems on py3k and for a clean "python setup.py test" I'd prefer it not get into edgier cases, as that's what distros typically rely upon for vanilla package builds.
the refactoring has broken the babelplugin on python 3:
test/ext/test_babelplugin.py::ExtractMakoTestCase::test_extract[(1,'_','Page arg 1',),(1,'_','Page arg 2',),(10,'gettext','Begin',),(14,'_','Hi there!',['TRANSLATOR: Hi there!']),(19,'_','Hello',),(22,'_','Welcome',),(25,'_','Yo',),(36,'_','The',['TRANSLATOR: Ensure so and','so, thanks']),(36,'ungettext',('bunny','bunnies',None),),(41,'_','Goodbye',),(44,'_','Babel',),(45,'ungettext',('hella','hellas',None),),(62,'_','The',['TRANSLATOR: Ensure so and','so, thanks']),(62,'ungettext',('bunny','bunnies',None),),(68,'_','Goodbye, really!',['TRANSLATOR: HTML comment']),(71,'_','P.S. byebye',),(77,'_','Top',),(83,'_','foo',),(83,'_','hoho',),(85,'_','bar',),(92,'_','Inside a p tag',),(95,'_','Later in a p tag',),(99,'_','No action at a distance.',)]FAILED
I'm trying to see what the origin of this is but so far there seems to be a lot changed here.
You are using an private (underscore-prefixed) method from Mako, so it isn't entirely surprising something broke for your. Is there a particular type of API you are looking for that Mako might be able to provide?
Is there a particular type of API you are looking for that Mako might be able to provide?
Yes, I am looking for a way to derive from the default messages extractor so the derived version can preprocess custom syntax and feed the resulting mako syntax into it in order to retrieve translation strings. Previously, I could do that by just wrapping around Mako's extract() method. How is it supposed to be done now? Thanks!
Ok, I've got the idea. Actually, everything works fine, it's just that previously I had been able to call extract() with None as comment_tags in my tests, and apparently, this argument was used slightly differently within a function and such a case was never an issue. Now it is.