-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Open
Labels
Description
Feature Request
Summary
Add comprehensive RTL (Right-to-Left) support for Arabic and other RTL languages (Hebrew, Persian, Urdu) to improve accessibility and usability for users in RTL-speaking regions.
Motivation
OpenCode already has Arabic translations (README.ar.md and Arabic locale in the app), but the UI doesn't properly handle RTL text direction. This makes the interface difficult to use for Arabic-speaking users as text alignment, layout, and reading flow are incorrect.
Proposed Solution
1. Add Arabic Font Support
- Include IBM Plex Sans Arabic font (Regular, Medium, SemiBold weights)
- Use
unicode-rangein@font-faceto only load Arabic glyphs when needed - Add
--font-family-arabicCSS variable
2. Create RTL Stylesheet (rtl.css)
- Text direction and alignment rules for
html[dir="rtl"] - Preserve LTR for code blocks, file paths, URLs
- Icon flipping utilities for directional icons (arrows, etc.)
- Scrollbar positioning adjustments
- Form input RTL alignment
- Logical CSS properties (margin-inline-start, padding-inline-end, etc.)
3. Extend i18n Context
- Add
isRTLaccessor to detect RTL locale - Add
directionaccessor returning"ltr"or"rtl" - Auto-set
document.documentElement.dirwhen locale changes
4. RTL Utility Classes
.font-arabic- Explicitly use Arabic font.rtl-flip- Flip icons horizontally.preserve-ltr- Keep content LTR (for code).text-start/.text-end- RTL-aware alignment.ms-auto/.me-auto- RTL-aware margins
RTL Languages to Support
| Locale | Language |
|---|---|
ar |
Arabic |
he |
Hebrew |
fa |
Persian (Farsi) |
ur |
Urdu |
Implementation Notes
I have a working implementation ready that includes:
- 3 IBM Plex Sans Arabic font files (~224KB total)
fonts-arabic.csswith optimized@font-facedeclarationsrtl.csswith comprehensive RTL styling- Modified
i18n.tsxwith RTL detection helpers - Modified
language.tsxto auto-applydirattribute - RTL utility classes in
utilities.css
Files Changed: 12 files, +357 lines
Screenshots
The implementation correctly renders Arabic text right-to-left while preserving LTR for code blocks:
┌─────────────────────────────────────────┐
│ مرحبا بالعالم │ <- Arabic text aligned right
│ │
│ console.log("Hello") │ <- Code stays LTR
│ │
│ هذا نص عربي للاختبار │ <- More Arabic text
└─────────────────────────────────────────┘
Additional Context
- IBM Plex Sans Arabic is the Arabic companion to IBM Plex (already used in OpenCode)
- Uses
unicode-rangeso fonts only load when Arabic characters are present - No breaking changes - LTR languages work exactly as before
- Tested with standalone HTML and Vite dev server
Contribution
I'm happy to submit a PR with this implementation. Let me know if you'd like any changes to the approach!
Reactions are currently unavailable