From a182e71661b65513e9890268df4f389be60defbd Mon Sep 17 00:00:00 2001 From: Kumi Date: Mon, 19 Aug 2024 13:37:49 +0200 Subject: [PATCH] feat(i18n): add RTL support for article pages Enhanced article rendering to support right-to-left (RTL) languages. Updated templates, styles, and HTML to conditionally apply RTL styling based on content direction. Improved readability and user experience for RTL language users. Relates: #16 --- src/wikimore/app.py | 22 ++++++++++++++-------- src/wikimore/static/css/style.css | 14 ++++++++++++++ src/wikimore/templates/article.html | 4 ++-- 3 files changed, 30 insertions(+), 10 deletions(-) diff --git a/src/wikimore/app.py b/src/wikimore/app.py index 5a4b571..4ea9abb 100644 --- a/src/wikimore/app.py +++ b/src/wikimore/app.py @@ -127,13 +127,16 @@ def wiki_article(project, lang, title): try: article_html = next(iter(pages.values()))["revisions"][0]["*"] except KeyError: - return render_template( - "article.html", - title=title.replace("_", " "), - content="Article not found", - wikimedia_projects=app.wikimedia_projects, - languages=app.languages, - ), 404 + return ( + render_template( + "article.html", + title=title.replace("_", " "), + content="Article not found", + wikimedia_projects=app.wikimedia_projects, + languages=app.languages, + ), + 404, + ) soup = BeautifulSoup(article_html, "html.parser") @@ -166,7 +169,9 @@ def wiki_article(project, lang, title): found = False for language, language_projects in app.languages.items(): - for project_name, project_url in language_projects["projects"].items(): + for project_name, project_url in language_projects[ + "projects" + ].items(): if project_url == target_domain: a["href"] = url_for( "wiki_article", @@ -205,6 +210,7 @@ def wiki_article(project, lang, title): content=processed_html, wikimedia_projects=app.wikimedia_projects, languages=app.languages, + rtl=bool(soup.find("div", class_="mw-parser-output", dir="rtl")), ) diff --git a/src/wikimore/static/css/style.css b/src/wikimore/static/css/style.css index 67eb43f..49ff30c 100644 --- a/src/wikimore/static/css/style.css +++ b/src/wikimore/static/css/style.css @@ -53,6 +53,10 @@ a.new::after { color: #333; } +.title-rtl { + direction: rtl; +} + /* Search styling */ #search-form { margin: 0; @@ -95,6 +99,11 @@ h1 { } /* General sidebar styling */ +.mw-content-rtl .sidebar { + float: left; + clear: left; +} + .sidebar { background-color: #f9f9f9; border: 1px solid #ddd; @@ -325,6 +334,11 @@ h1 { } /* Sidebar styling */ +.mw-content-rtl .infobox { + float: left; + clear: left; +} + .infobox { float: right; margin: 1em; diff --git a/src/wikimore/templates/article.html b/src/wikimore/templates/article.html index e485e1f..38c48f4 100644 --- a/src/wikimore/templates/article.html +++ b/src/wikimore/templates/article.html @@ -1,6 +1,6 @@ {% extends "base.html" %} {% block content %} -

{{ title }}

-

{{ content|safe }}

+

{{ title }}

+ {{ content|safe }} {% endblock %} \ No newline at end of file