From 1e31998f50a380ae139b368fc7af9bcc5af86d0f Mon Sep 17 00:00:00 2001 From: Kumi Date: Tue, 20 Aug 2024 07:25:07 +0200 Subject: [PATCH] feat: improve language and project handling - Default values for `lang` and `project` added in `render_template` to ensure consistent rendering parameters. - Included `lang` and `project` parameters in error and article templates for better context in error messages. - Enhanced search form in base template to persist selected `lang` and `project` improving user experience. These changes provide a more consistent and localized user experience by maintaining language and project context across different parts of the application. Fixes #17. --- src/wikimore/app.py | 10 +++++++++- src/wikimore/templates/base.html | 4 ++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/wikimore/app.py b/src/wikimore/app.py index cc47899..af985f1 100644 --- a/src/wikimore/app.py +++ b/src/wikimore/app.py @@ -92,6 +92,9 @@ def render_template(*args, **kwargs) -> Text: Returns: Text: The rendered template. """ + kwargs.setdefault("lang", "en") + kwargs.setdefault("project", "wiki") + return flask_render_template( *args, **kwargs, @@ -237,6 +240,8 @@ def wiki_article( "article.html", title="Article not found", content=f"Sorry, the article {title} was not found in the {project} project in the {lang} language.", + lang=lang, + project=project, ), 404, ) @@ -247,6 +252,8 @@ def wiki_article( "article.html", title="Error", content=f"An error occurred while fetching the article {title} from the {project} project in the {lang} language.", + lang=lang, + project=project, ), 500, ) @@ -274,7 +281,6 @@ def wiki_article( a["href"] = f"/{project}/{lang}{href}" elif href.startswith("//") or href.startswith("https://"): - print(f"Checking {href}") parts = urlparse(href) target_domain = f"https://{parts.netloc}" @@ -337,6 +343,8 @@ def wiki_article( "article.html", title=title.replace("_", " "), content=processed_html, + lang=lang, + project=project, rtl=rtl, ) diff --git a/src/wikimore/templates/base.html b/src/wikimore/templates/base.html index 0614922..7c4db70 100644 --- a/src/wikimore/templates/base.html +++ b/src/wikimore/templates/base.html @@ -12,12 +12,12 @@