Skip to content

fix: rtl display issue in author merge interface#11412

Open
akramcodez wants to merge 1 commit intointernetarchive:masterfrom
akramcodez:fix/rtl-display-author-merge-interface
Open

fix: rtl display issue in author merge interface#11412
akramcodez wants to merge 1 commit intointernetarchive:masterfrom
akramcodez:fix/rtl-display-author-merge-interface

Conversation

@akramcodez
Copy link
Contributor

Closes #10115

Problem

When merging authors, RTL work titles (Arabic, Hebrew) cause edition counts and years to display incorrectly mixed with the title text.

Before: مدرسة العذاب 1 edition, 2009 (numbers appear inside RTL text)
After: Title and numbers are visually separated with proper text direction

Solution

  • Added is_rtl() utility function using Unicode bidirectional properties
  • Modified merge template to apply dir="rtl" only to RTL titles
  • Keep edition count and year in separate dir="ltr" span
  • Single template handles both RTL and LTR cases (no code duplication)

Technical Changes

  • openlibrary/plugins/upstream/utils.py: Added @public is_rtl() function
  • openlibrary/templates/merge/authors.html: Per-title RTL detection with proper text separation

Stakeholders: @Freso @cdrini @mekarpeles

Copilot AI review requested due to automatic review settings November 4, 2025 04:41
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds right-to-left (RTL) text support for book titles in the author merge interface to ensure proper display of titles in RTL languages like Arabic and Hebrew.

  • Introduces a new is_rtl() utility function to detect RTL characters using Unicode bidirectional properties
  • Updates the author merge template to conditionally apply dir="rtl" attribute to book title links when they contain RTL characters
  • Wraps edition count and publication year information in dir="ltr" to maintain left-to-right display for numeric data

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
openlibrary/plugins/upstream/utils.py Adds is_rtl() function to detect RTL text using Unicode bidirectional character properties
openlibrary/templates/merge/authors.html Refactors book title display to apply RTL directionality and improves formatting of edition metadata

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@akramcodez akramcodez force-pushed the fix/rtl-display-author-merge-interface branch from 9912d55 to a1939eb Compare November 4, 2025 04:46
Copy link
Contributor

@Freso Freso left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for tackling this! A few comments. :)

title="$_('Open in a new window')"
$:cond(is_rtl(doc['title']), 'dir="rtl"', '')
>$doc['title']</a>
<span class="smaller" dir="ltr">
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don’t hardcode ltr here. It may not be ltr, depending on what the user’s locale is set to.

Suggested change
<span class="smaller" dir="ltr">
<span class="smaller">

The <span> won’t inherit the dir property from <a> since it’s not a child of <a>, so there should be no reason to set it directly here at all. (If anything, there should be a dir property on <html> or <body> depending on the set locale, but that’s outside of the scope of this PR.)

<a href="$doc['key']"
target="new"
title="$_('Open in a new window')"
$:cond(is_rtl(doc['title']), 'dir="rtl"', '')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
$:cond(is_rtl(doc['title']), 'dir="rtl"', '')
dir="$:cond(is_rtl(doc['title']), 'rtl', 'ltr')"

There might be situations where someone is browsing the site in, say, Arabic, and it turns out there’s an issue with Latin-script/LTR titles. If we believe that it’s not rtl, it’s probably ltr, so let’s declare that.

If we really want to optimise the code to not include the property when not needed, we’ll need to compare with the set locale’s direction and only output if they differ… but that’s probably overengineering for now.

@Freso
Copy link
Contributor

Freso commented Nov 4, 2025

Also, why did you remove the is_rtl docstring? :(

@akramcodez akramcodez force-pushed the fix/rtl-display-author-merge-interface branch from f1a7f63 to a404941 Compare November 4, 2025 16:17
@akramcodez
Copy link
Contributor Author

Also, why did you remove the is_rtl docstring? :(

Sorry for the mistakes, I actually planned to fix them tomorrow. But thanks a lot for the detailed explanation! The test is still failing though, could you please suggest what I should do now?

@Freso
Copy link
Contributor

Freso commented Nov 4, 2025

The test is still failing though, could you please suggest what I should do now?

Are you sure the syntax is $:cond(…)? Looks like line 70 of authors.html uses $cond(…), without the :. I’m not extremely familiar with the templating language, so my comments were generally more directed towards abstract/conceptional issues (e.g., making sure this still makes sense for people using OL in a non-LTR locale) rather than very specific, concrete code issues. :)

@github-actions github-actions bot added the Needs: Response Issues which require feedback from lead label Nov 5, 2025
@akramcodez
Copy link
Contributor Author

@cdrini I’ve done my best, but I’m kind of stuck now. Please review the changes and let me know if there are any issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Needs: Response Issues which require feedback from lead

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Edition number is shown in wrong location in author merge interface when Work title is a right‐to‐left language

3 participants