Skip to content

feat(i18n): RTL layout for Arabic (direction switch + logical-property migration)#131

Merged
os-zhuang merged 1 commit into
mainfrom
feat/rtl-arabic
Jun 11, 2026
Merged

feat(i18n): RTL layout for Arabic (direction switch + logical-property migration)#131
os-zhuang merged 1 commit into
mainfrom
feat/rtl-arabic

Conversation

@os-zhuang

Copy link
Copy Markdown
Contributor

RTL — the last i18n gap

Arabic now lays out right-to-left, not just translated LTR.

Mechanism (lib/rtl.ts)

  • syncRTL(lang)web sets document.dir; native sets I18nManager.forceRTL (persisted). Applied on launch from _layout for the active language.
  • setLanguage persists the choice (so it survives the reload), flips direction, and on web reloads when the direction actually changes (en↔ar).
  • i18n init now prefers the persisted language over device detection — without this the RTL reload reset back to the device locale (the bug I hit first).

Layout — physical → logical Tailwind utilities

So spacing/alignment flip under RTL and stay correct in LTR:
ml/mr → ms/me, pl/pr → ps/pe, text-left/right → text-start/end, and the FAB / corner-badge insets right → end (~70 occurrences, 33 files). flex-row auto-reverses from dir/forceRTL; symmetric left-4 right-4 left as-is. NativeWind 4 maps the logical classes to RN marginStart/End etc., which honour direction on both web and native.

Verified (browser, 375dp, dark)

  • zh/en LTR unchanged (margins intact — confirmed NativeWind renders ms-/me-).
  • Switching to العربية mirrors the whole shell — header, card icons, chevrons, section headers, bottom tab bar, text alignment — and persists across reload.
  • Switching back restores LTR.

tsc + lint clean; snapshots updated for the class rename; full suite 1337 passing.

Note

Native applies the direction on next launch — no expo-updates / react-native-restart is bundled to hot-reload, and adding a native module needs a rebuild. Web is instant. This is the one platform caveat; the mechanism + layout are complete.

🤖 Generated with Claude Code

…ty migration

Completes the last i18n gap. Arabic now lays out right-to-left, not just
translated LTR.

Mechanism (`lib/rtl.ts`):
- `syncRTL(lang)` — web sets `document.dir`; native sets `I18nManager.forceRTL`
  (persisted). Applied on launch from `_layout` for the active language.
- `setLanguage` persists the choice (so it survives the reload), flips direction
  via syncRTL, and on web reloads when the direction actually changes (en↔ar).
- i18n init now prefers the persisted language over device detection — without
  this the RTL reload reset back to the device locale.

Layout — migrate physical → logical Tailwind utilities so spacing/alignment
flip under RTL (and stay correct in LTR): `ml/mr→ms/me`, `pl/pr→ps/pe`,
`text-left/right→text-start/end`, and the FAB / corner-badge insets
`right→end`. `flex-row` auto-reverses from `dir`/`forceRTL`; symmetric
`left-4 right-4` left as-is. NativeWind 4 maps the logical classes to RN
`marginStart/End` etc., which honour direction on both web and native.

Verified on web: zh/en LTR unchanged; switching to العربية mirrors the whole
shell (header, cards, chevrons, tab bar, text alignment) and persists across
reload; switching back restores LTR. Snapshots updated for the class rename.
tsc + lint clean, full suite 1337 passing.

Note: native applies the direction on next launch (no `expo-updates` /
react-native-restart bundled to hot-reload); web is instant.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@os-zhuang os-zhuang merged commit 5304f5e into main Jun 11, 2026
@os-zhuang os-zhuang deleted the feat/rtl-arabic branch June 11, 2026 13:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant