Skip to content

Commit a404941

Browse files
committed
fix: RTL display issue in author merge interface
1 parent 6d2c117 commit a404941

File tree

2 files changed

+35
-4
lines changed

2 files changed

+35
-4
lines changed

openlibrary/plugins/upstream/utils.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -633,6 +633,31 @@ def add_metatag(tag: str = "meta", **attrs) -> None:
633633
context.metatags.append(Metatag(tag, **attrs))
634634

635635

636+
@public
637+
def is_rtl(text: str) -> bool:
638+
"""
639+
Check if the given text is right-to-left (RTL) using Unicode bidirectional properties.
640+
641+
Args:
642+
text: The text to check for RTL characters
643+
644+
Returns:
645+
bool: True if the text contains RTL characters, False otherwise
646+
647+
Examples:
648+
>>> is_rtl("Hello World")
649+
False
650+
>>> is_rtl("مدرسة العذاب")
651+
True
652+
>>> is_rtl("Hello مرحبا World")
653+
True
654+
"""
655+
if not text:
656+
return False
657+
# 'R' = Right-to-Left, 'AL' = Arabic Letter
658+
return any(unicodedata.bidirectional(char) in ('R', 'AL') for char in text)
659+
660+
636661
@public
637662
def url_quote(text: str | bytes) -> str:
638663
if isinstance(text, str):

openlibrary/templates/merge/authors.html

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,16 @@ <h1>$_("Merge Authors")</h1>
9292
<p>No description.</p>
9393
<ul>
9494
$for doc in top.docs:
95-
<li><a href="$doc['key']" target="new" title="$_('Open in a new window')">$doc['title']</a> <span class="smaller">$ungettext('%(count)s edition', '%(count)s editions', doc['edition_count'], count=doc['edition_count']),
96-
$if doc.get('first_publish_year'):
97-
<span title="$_('First published in')">$doc['first_publish_year']</span>
98-
</span></li>
95+
<li>
96+
<a href="$doc['key']"
97+
target="new"
98+
title="$_('Open in a new window')"
99+
dir="$:cond(is_rtl(doc['title']), 'rtl', 'ltr')"
100+
>$doc['title']</a>
101+
<span class="smaller">
102+
$ungettext('%(count)s edition', '%(count)s editions', doc['edition_count'], count=doc['edition_count'])$if doc.get('first_publish_year'):, <span title="$_('First published in')">$doc['first_publish_year']</span>
103+
</span>
104+
</li>
99105
</ul>
100106
</div>
101107
<div class="data count">

0 commit comments

Comments
 (0)