support i18n
This commit is contained in:
@ -18,6 +18,26 @@ 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
|
||||
|
Reference in New Issue
Block a user