From 3e72038ed268bbba5616dfe5c47e34b9a22c13f8 Mon Sep 17 00:00:00 2001 From: Leo Vasanko Date: Thu, 3 Sep 2026 03:06:34 +0000 Subject: [PATCH] dir=rtl on for RTL page languages --- pagerite/i18n.py | 4 ++++ pagerite/views.py | 6 ++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/pagerite/i18n.py b/pagerite/i18n.py index 627c4a2..b854b72 100644 --- a/pagerite/i18n.py +++ b/pagerite/i18n.py @@ -21,6 +21,10 @@ from pagerite.data import Data, Node, Patch, resolve #: ancestor (up to the front page) sets one (Node.language, "" = inherit). ORIGINAL_LANGUAGE = "en" +#: Languages written right-to-left; pages served in one get dir="rtl" on +#: (views._layout). +RTL_LANGUAGES = frozenset({"ar", "fa", "he", "ur"}) + def primary_lang(menu: dict[str, Node], path: str) -> str: """The primary language of the article at ``path``: its own diff --git a/pagerite/views.py b/pagerite/views.py index f30d61c..3ef8cca 100644 --- a/pagerite/views.py +++ b/pagerite/views.py @@ -339,12 +339,14 @@ def _layout( ``social`` maps meta keys to contents: ``og:*``/``article:*`` go out as property attributes, everything else (description, twitter:*) as name. - ``lang`` is the served language for . ``canonical`` and + ``lang`` is the served language for ; an RTL language (ar, + fa, ...) also puts dir="rtl" on (the editor panel carries its own + lang="en" dir="ltr", so it is unaffected). ``canonical`` and ``alternates`` ((hreflang, href) pairs) are the page's language URLs (see docs/localization.md), emitted right after the viewport and before the social tags: canonical first, then the hreflang alternates. """ - doc = Document(E.Title, lang=lang) + doc = Document(E.Title, lang=lang, dir="rtl" if lang in i18n.RTL_LANGUAGES else "ltr") # Responsive layout (see the 48rem breakpoint in pagerite.css) needs # the real device width, not the default 980px layout viewport. doc.meta(name="viewport", content="width=device-width, initial-scale=1")