diff --git a/jweb/context.py b/jweb/context.py index a98c36e..26e5fbe 100644 --- a/jweb/context.py +++ b/jweb/context.py @@ -31,6 +31,9 @@ class Context: def current_language(self) -> str | None: return self.__current_language + def language(self) -> str | None: + return self.current_language + def add_filters(self, **filters: Any) -> None: self.__environment.filters.update(**filters) @@ -45,6 +48,7 @@ class Context: def load_translations(self, domain: str, locale_dir: str | Path, *languages: str) -> None: locale_dir = str(locale_dir) self.__environment.add_extension("jinja2.ext.i18n") + self.__environment.policies["ext.i18n.trimmed"] = True self.__translations[_DEFAULT_LANGUAGE] = NullTranslations() for language in languages: self.__translations[language] = gettext.translation( @@ -114,7 +118,7 @@ class Context: def __render(self, source: str, output_path: Path, **context: Any) -> None: output_path.parent.mkdir(exist_ok=True, parents=True) template = self.__environment.get_template(source) - content = template.render(**context) + content = template.render(context=self, **context) with open(output_path, "w") as output_file: output_file.write(content)