- Private CRM: an AI CRM where Claude does the data entry and you make the calls · part 8 of 12
- Tailwindcss
- ShadCN
- React
- CRM
- RTL
Arabic and right to left in a React and Inertia app, no library
Private CRM speaks Arabic with a right-to-left layout. Languages are JSON files, the server sets dir before render, and server messages translate by template.
5 min read
Private CRM has about 690 Arabic strings in a single JSON file, and no i18n library. Switching a user to Arabic translates every page and toast, down to notifications and validation messages, and the whole app comes back right to left with no flash of the English layout.
Here is how it works, in two commits and a few follow-ups.
A language is a JSON file
English is the source text. Every other language is resources/lang/<code>.json, mapping English strings to the translation, with two meta keys at the top:
{
"$name": "العربية",
"$dir": "rtl",
":count deals": "الصفقات: :count",
":count deals · :total": ":count صفقة · :total"
}
Using English as the key has one big advantage over deals.count-style keys: a missing translation shows readable English, not a key. It also means the code reads naturally: t('Save'), not t('common.buttons.save').
The Rust side reads the same folder at startup to build the list of languages:
//! Interface languages. English is the source text; every other language is a JSON file in
//! `resources/lang` that maps English strings to translations, plus `$name` and `$dir` (`ltr` or `rtl`).
//! Adding a language means adding its file.
The profile page's language picker is filled from that list, and the server only accepts a language that has a file. Adding a language is adding one file. No code change, no rebuild of the backend logic.
Setting dir before the first paint
The usual RTL bug is a flash: the page renders left to right, JavaScript loads, then everything jumps. Private CRM avoids it by setting direction on the server. The root view starts like this:
<html lang="{{ page.props.locale.code }}" dir="{{ page.props.locale.dir }}">
Inertia passes the user's locale as a shared prop, so an Arabic page arrives right to left from the first byte.
On the React side, the layouts call setLocale(code, dir) on every render before the page renders, so plain t() calls inside components see the right language. All language files ship in the bundle via an eager import.meta.glob. There's a comment saying that's fine for two languages and should switch to lazy loading when there are many.
What actually flips
Setting dir="rtl" does most of the work. The rest was a sweep:
- The sidebar moves to the right.
- The filter drawer and toasts open from the start side.
- Arrows and chevrons mirror.
- Every remaining
leftandrightTailwind class becamestartandend(ms-2,pe-4,start-0,text-start). - Radix gets the page direction, so submenus and switches flip too.
Later, when the app moved to a new shadcn preset (part 10), the regenerated components lost their RTL handling. shadcn's RTL migration put it back. If you switch presets on an RTL app, check the drawer and the dropdowns before anything else.
Dates and numbers
Dates follow the user's language, but with Latin digits:
/** Intl locale for dates and numbers: the user's language, with Latin digits. */
export function intlLocale() {
return `${current}-u-nu-latn`;
}
Amounts keep one format in every language. A KWD amount like 1,000.500 looks the same to an Arabic and an English user, which matters when they compare numbers on a call. The search folding from part 7 already turns Arabic-Indic digits into 0-9, so typing either kind finds the same record.
Translating what the server says
Pages are easy: wrap the string in t(). Server messages are harder. A validation error like "The :attribute field is required." arrives already filled in.
translateMessage handles it by template. Every English string with :name placeholders becomes a regular expression. The message is matched against the longest templates first, so ":from → :to: :reason" wins over ":from → :to". The captured values are translated too, and dropped into the Arabic template:
for (const pattern of patternsFor(current)) {
const match = pattern.regex.exec(message);
if (!match) continue;
const vars = Object.fromEntries(pattern.names.map((name, index) => [name, t(match[index + 1])]));
return fill(pattern.translation, vars);
}
The server keeps speaking English, the logs stay in English, and the user reads Arabic.
The bug that slipped through
The code review (part 12) found one place that didn't translate: stage moves on the Today page. The deal page showed "Lead → Qualified" in Arabic, Today showed it in English. Both had their own formatting code. The fix moved it into one shared helper both pages call. Anywhere you format the same thing twice, one copy will miss a translation.
The first pass in numbers
The translation commit put 500 Arabic strings into ar.json. Later features brought it to about 690. Contacts also carry a language field (English or Arabic), separate from the interface language, so the team knows which language to write to a client in.
Start with dir, then strings
If you're adding Arabic to a React app, set dir on the server first and switch your Tailwind classes to start and end. Translation strings are the easy part. Layout is what users notice. For component choices that respect dir, see why developers choose shadcn/ui over Radix UI.
Part 9 is about reaching people outside the browser tab: push notifications, task reminders, plus deals that have gone quiet.
Last updated 4 Dec 2026 · filed under Tailwindcss, shadcn, react, crm, rtl