Skip to content

Commit

Permalink
2375 extract translations from genshi or jinja2 *.html templates
Browse files Browse the repository at this point in the history
  • Loading branch information
tobes committed May 28, 2012
1 parent 8c636a1 commit 4afa82a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
21 changes: 21 additions & 0 deletions ckan/lib/extract.py
@@ -0,0 +1,21 @@
import re
from genshi.filters.i18n import extract as extract_genshi
from jinja2.ext import babel_extract as extract_jinja2

def extract_ckan(fileobj, *args, **kw):
''' Determine the type of file (Genshi or Jinja2) and then call the
correct extractor function.
Basically we just look for a jinja2 {{ or {% tag. '''

source = fileobj.read()
if re.search('\{\{|\{\%', source):
# jinja2
extractor_function = extract_jinja2
else:
# genshi
extractor_function = extract_genshi
# we've eaten the file so we need to get back to the start
fileobj.seek(0)
return extractor_function(fileobj, *args, **kw)

6 changes: 4 additions & 2 deletions setup.py
Expand Up @@ -36,7 +36,7 @@
'ckan': [
('**.py', 'python', None),
('templates/importer/**', 'ignore', None),
('templates/**.html', 'genshi', None),
('templates/**.html', 'ckan', None),
('ckan/templates/home/language.js', 'genshi', {
'template_class': 'genshi.template:TextTemplate'
}),
Expand All @@ -46,7 +46,7 @@
('public/**', 'ignore', None),
],
'ckanext/stats/templates': [
('**.html', 'genshi', None),
('**.html', 'ckan', None),
]},
entry_points="""
[nose.plugins.0.10]
Expand Down Expand Up @@ -110,6 +110,8 @@
css = html_resources:css
javascript = html_resources:javascript
[babel.extractors]
ckan = ckan.lib.extract:extract_ckan
""",
# setup.py test command needs a TestSuite so does not work with py.test
# test_suite = 'nose.collector',
Expand Down

0 comments on commit 4afa82a

Please sign in to comment.