3
0
This commit is contained in:
2022-04-07 13:53:45 +02:00
parent 71e7fe7b09
commit 7420b4107e
4 changed files with 24 additions and 29 deletions

View File

@ -18,26 +18,6 @@ class DispatchingJinjaLoader(quart.templating.DispatchingJinjaLoader):
def __init__(self, app: MyQuartApp) -> None:
super().__init__(app)
def get_source(
self, environment: jinja2.Environment, template: str
) -> typing.Tuple[str, typing.Optional[str], typing.Optional[typing.Callable[[], bool]]]:
"""Returns the template source from the environment.
This considers the loaders on the :attr:`app` and blueprints.
"""
langs: typing.List[str] = quart.g.langs
for loader in self._loaders():
for lang in langs:
try:
return loader.get_source(environment, os.path.join('i18n', lang, template))
except jinja2.TemplateNotFound:
continue
try:
return loader.get_source(environment, template)
except jinja2.TemplateNotFound:
continue
raise jinja2.TemplateNotFound(template)
def _loaders(self) -> typing.Generator[jinja2.BaseLoader, None, None]:
if self.app.custom_loader:
yield self.app.custom_loader