Index: cms/converters.py |
=================================================================== |
--- a/cms/converters.py |
+++ b/cms/converters.py |
@@ -376,16 +376,17 @@ |
filters = { |
'translate': self.translate, |
'linkify': self.linkify, |
'toclist': self.toclist, |
} |
globals = { |
'get_string': self.get_string, |
+ 'has_string': self.has_string, |
'get_page_content': self.get_page_content, |
} |
for dirname, dictionary in [('filters', filters), |
('globals', globals)]: |
for filename in self._params['source'].list_files(dirname): |
root, ext = os.path.splitext(filename) |
if ext.lower() != '.py': |
@@ -402,16 +403,19 @@ |
' in {}'.format(name, path)) |
self._env = jinja2.Environment( |
loader=SourceTemplateLoader(self._params['source']), |
autoescape=True) |
self._env.filters.update(filters) |
self._env.globals.update(globals) |
+ def _get_locale_data(self, page): |
+ return self._params['source'].read_locale(self._params['locale'], page) |
+ |
def get_html(self, source, filename): |
env = self._env |
code = env.compile(source, None, filename) |
template = jinja2.Template.from_code(env, code, env.globals) |
try: |
module = template.make_module(self._params) |
except Exception: |
@@ -430,23 +434,29 @@ |
self._params['page'], name, default, comment, |
self._params['localedata'], html_escapes |
)) |
def get_string(self, name, page=None): |
if page is None: |
page = self._params['page'] |
- localedata = self._params['source'].read_locale(self._params['locale'], |
- page) |
+ localedata = self._get_locale_data(page) |
default = localedata[name] |
return jinja2.Markup(self.localize_string( |
page, name, default, '', localedata, html_escapes |
)) |
+ def has_string(self, name, page=None): |
+ if page is None: |
+ page = self._params['page'] |
+ |
+ localedata = self._get_locale_data(page) |
+ return name in localedata |
+ |
def get_page_content(self, page, locale=None): |
from cms.utils import get_page_params |
if locale is None: |
locale = self._params['locale'] |
return get_page_params(self._params['source'], locale, page) |
def linkify(self, page, locale=None, **attrs): |