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
This commit is contained in:
Kumi 2024-08-19 13:37:49 +02:00
parent 056c19225a
commit a182e71661
Signed by: kumi
GPG key ID: ECBCC9082395383F
3 changed files with 30 additions and 10 deletions

View file

@ -127,13 +127,16 @@ def wiki_article(project, lang, title):
try: try:
article_html = next(iter(pages.values()))["revisions"][0]["*"] article_html = next(iter(pages.values()))["revisions"][0]["*"]
except KeyError: except KeyError:
return render_template( return (
render_template(
"article.html", "article.html",
title=title.replace("_", " "), title=title.replace("_", " "),
content="Article not found", content="Article not found",
wikimedia_projects=app.wikimedia_projects, wikimedia_projects=app.wikimedia_projects,
languages=app.languages, languages=app.languages,
), 404 ),
404,
)
soup = BeautifulSoup(article_html, "html.parser") soup = BeautifulSoup(article_html, "html.parser")
@ -166,7 +169,9 @@ def wiki_article(project, lang, title):
found = False found = False
for language, language_projects in app.languages.items(): 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: if project_url == target_domain:
a["href"] = url_for( a["href"] = url_for(
"wiki_article", "wiki_article",
@ -205,6 +210,7 @@ def wiki_article(project, lang, title):
content=processed_html, content=processed_html,
wikimedia_projects=app.wikimedia_projects, wikimedia_projects=app.wikimedia_projects,
languages=app.languages, languages=app.languages,
rtl=bool(soup.find("div", class_="mw-parser-output", dir="rtl")),
) )

View file

@ -53,6 +53,10 @@ a.new::after {
color: #333; color: #333;
} }
.title-rtl {
direction: rtl;
}
/* Search styling */ /* Search styling */
#search-form { #search-form {
margin: 0; margin: 0;
@ -95,6 +99,11 @@ h1 {
} }
/* General sidebar styling */ /* General sidebar styling */
.mw-content-rtl .sidebar {
float: left;
clear: left;
}
.sidebar { .sidebar {
background-color: #f9f9f9; background-color: #f9f9f9;
border: 1px solid #ddd; border: 1px solid #ddd;
@ -325,6 +334,11 @@ h1 {
} }
/* Sidebar styling */ /* Sidebar styling */
.mw-content-rtl .infobox {
float: left;
clear: left;
}
.infobox { .infobox {
float: right; float: right;
margin: 1em; margin: 1em;

View file

@ -1,6 +1,6 @@
{% extends "base.html" %} {% extends "base.html" %}
{% block content %} {% block content %}
<h1>{{ title }}</h1> <h1 class="title{% if rtl %} title-rtl{% endif %}">{{ title }}</h1>
<p>{{ content|safe }}</p> {{ content|safe }}
{% endblock %} {% endblock %}