Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
2375 extract translations from genshi or jinja2 *.html templates
- Loading branch information
Showing
2 changed files
with
25 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters