我们从Python开源项目中,提取了以下23个代码示例,用于说明如何使用django.utils.translation.templatize()。
def preprocess(self): """ Preprocess (if necessary) a translatable file before passing it to xgettext GNU gettext utility. """ from django.utils.translation import templatize if not self.is_templatized: return with io.open(self.path, 'r', encoding=settings.FILE_CHARSET) as fp: src_data = fp.read() if self.domain == 'djangojs': content = prepare_js_for_gettext(src_data) elif self.domain == 'django': content = templatize(src_data, self.path[2:]) with io.open(self.work_path, 'w', encoding='utf-8') as fp: fp.write(content)
def preprocess(self): """ Preprocess (if necessary) a translatable file before passing it to xgettext GNU gettext utility. """ if not self.is_templatized: return encoding = settings.FILE_CHARSET if self.command.settings_available else 'utf-8' with io.open(self.path, 'r', encoding=encoding) as fp: src_data = fp.read() if self.domain == 'djangojs': content = prepare_js_for_gettext(src_data) elif self.domain == 'django': content = templatize(src_data, origin=self.path[2:], charset=encoding) with io.open(self.work_path, 'w', encoding='utf-8') as fp: fp.write(content)
def decorate_templatize(func): def templatize(src, origin=None): src = to_text(src, settings.FILE_CHARSET) if origin.endswith(".pug"): html = process(src,compiler=Compiler) else: html = src return func(html, origin) return templatize