Example content left in English
A name, a label or a placeholder that stays English on the Persian page (Maryam, Connected, Delete Campaign…, Choose file) breaks the example’s promise that the component works in Persian.
- Every example string goes through ex.t(), names, placeholders and captions included; numbers in the example’s digits.
- Only code, file names and brand names stay Latin.
A sheet that opens from the wrong side in Persian
Every backoffice task opened with side="right": right for English, where the end side is the right, but in Persian the menu sits on the right and the sheet came in over it from the same side, the start, instead of the end. A width set only for data-[side=right] was lost too, once the sheet came from the left.
- Open a task with side="end" and a menu with side="start": Sheet.Content turns them into the right or the left from the page’s language.
- Give a sheet’s width for both sides (data-[side=left]:w-… and data-[side=right]:w-…).
- pnpm divan:lint flags a fixed side="left" or side="right" (sheet-physical-side); a page that decides it in code (side={isFa ? …}) is left alone.
- Open every sheet with the page in Persian as well as in English.
A Latin value that flips inside Persian text
Without an isolate, a path read “episode/” for “/episode”, a handle put its “@” at the wrong end («سارا@» for a Persian name), and “net +12” or “+۵ pts” read backwards once a word sat inside the left-to-right part.
- Wrap each Latin value (handle, path, URL, e-mail, id, env name) in <bdi dir="ltr">; in a string inside a .svelte file build the isolate with String.fromCharCode(0x2066…0x2069).
- Keep words outside the isolate: the number alone in <bdi dir="ltr">, the word beside it in the page’s language.
- A display name gets no “@”: only a handle does.
- A name a person typed (a type, a title, a folder) can be in either script: inside Persian words wrap it in a first-strong isolate, \u2068name\u2069, so a Latin one keeps its place (the studio’s New Type wrote «Prophecy» into a Persian sentence and its words came out of order).
A text arrow that points the wrong way in Persian
“Open ↗”, “← All users”, “↳” and the “→” between steps (“Supabase → SQL Editor”) are text: they point the same way in Persian, where forward is to the left.
- Use a lucide arrow icon with rtl:-scale-x-100, or wrap the glyph in <span class="inline-block rtl:-scale-x-100" aria-hidden="true"> with a word for screen readers.
- pnpm divan:lint flags an arrow glyph on a line without rtl:-scale-x-100 (text-arrow); an English-only path shown left to right can say why with divan-ignore.
A search field whose icon and text disagree
A search input with dir="ltr" or dir="auto" next to an icon placed at start-3: the input’s padding (ps-9) follows its own direction, so in Persian the icon sat on the right, the padding on the left, and typed text ran under the icon.
- The input keeps the page’s direction (no dir), so icon, padding and placeholder agree.
- Add [unicode-bidi:plaintext] so a typed Latin handle keeps its own order.
Latin words jump inside Persian text
An @handle, e-mail, URL or a number with a sign inside a Persian sentence is reordered by the browser: “@yourchannel” shows as “yourchannel@”, a full stop lands on the wrong side.
- Wrap the Latin part in <bdi dir="ltr">…</bdi>, or in Unicode isolates (\u2066…\u2069) inside translation strings.
- Give fields for handles, e-mails, phone numbers and codes dir="ltr".
- pnpm divan:lint flags an e-mail address or a domain in a Persian string outside isolates (latin-in-persian), in .svelte files and in the words files (words.ts, src/lib/i18n): the company form’s “مثل name@company.com.” put its full stop on the wrong side.
- A sentence that starts with a name (“{name} gave 50,000 toman”) keeps the page’s direction: split the template around {name} and wrap the name in <bdi>, never dir="auto" on the sentence, which turns the whole line around when the name is in the other script.
- A text box cannot hold <bdi>, so the isolates go in the text itself: the studio’s composer wraps each @mention and #move of a Persian prompt in \u2066…\u2069 as it goes in (and any typed by hand when the box loses focus), and takes them out before the prompt goes to a model.
اینطور بنویس: @yourchannel
اینطور بنویس: @yourchannel
A Persian prompt that turns left to right because it starts with a mention
The studio’s prompt box and the prompts under each shot used dir="auto", which takes the direction from the first letter. “@image1 کنار @rostam” starts with the Latin letters of a mention, so the whole Persian line read left to right. Every other box people type in and the places that show what they wrote (the room’s chat, a question card, comments, replies and messages in the backoffice, the card in Claude) still used dir="auto", so “@rostam کجاست؟” read left to right there, its @ at the far side.
- Take the direction from the words, not the handles: promptDir() skips @mentions and #tags and looks at the first letter after them.
- Anywhere people type text that can start with a Latin token (a handle, a tag, a brand), set dir from its words the same way, not dir="auto".
- Input and Textarea do it for every field with dir="auto": past a Latin @handle or #tag at the start they take the direction of the words (fieldDir, src/lib/direction.ts), and otherwise keep dir="auto", so a box of several lines still reads each line in its own direction.
- Show what people wrote with <Written text={…} /> (src/lib/components/Written.svelte) inside its dir="auto" block: each Latin @handle and #tag sits in a <bdi>, which dir="auto" and unicode-bidi: plaintext pass over, so the line reads in its words’ direction and the @ stays in front of its word. pnpm divan:lint flags a dir="auto" block with unicode-bidi: plaintext that shows a bare {…} (written-words).
- While it is typed, the @ of a handle still shows at the far side of a Persian box: a text box cannot hold a <bdi>, so only what Studio puts in the text itself (the Composer’s mentions) carries isolates.
A page in English because the phone is in English
divanworks.com/yt, the page behind every YouTube link we hand out, chose Persian only when the phone or Instagram was set to Persian. Many people in Iran keep their phone in English, so our Persian audience got the English page, and it had no language switch to change it.
- A page our own links lead to opens in Persian unless the visitor chose English (the language switch, saved in the site’s cookie) or the link asks for it (?lang=en: an invite Ravi wrote in English, a link on the site’s English pages; channelLink and inLang in #lib/youtube-invite.ts). Neither the phone’s language nor the country is a clear signal: many Persian speakers, in Iran and abroad, keep their phone in English.
- Every page people land on has the language switch, a one-button page too: SiteHeader variant="task" brings it, and the choice is saved in the site’s cookie (LANG_COOKIE), so the server draws the next visit in it.
A value cell that takes its text’s direction
An item card in the room listed its fields as label and value, with dir="auto" on the value’s cell. In an English page a Persian value moved to the far right of its cell, away from its label. In the Viewer, where values sit at the end, a Persian credit jumped to the other side.
- Keep a cell in the page’s direction and put its value in a <bdi>: the value reads in its own direction and stays where every other value is.
- Divan’s lint flags dir="auto" on a <dd>, <td> or <th> (cell-takes-text-direction), in Svelte and in the HTML a .ts module builds. In a text’s table (renderMarkdown), the cells keep the table’s own direction.
- A line that opens with the page’s own words takes the page’s direction too (“Risks: …”, “Why now: …”, “(شاهنامه, line 13)”): no dir="auto" on it, and the value from elsewhere in a <bdi>. dir="auto" turned the room’s Ideas source lines right to left on an English page, because their first letter was a Persian title’s. The lint rule page-words-take-text-direction catches it.
Persian names listed in an English sentence
The room’s Ideas panel said who backed each idea, “By گفتوگونویس, فیلمنامهنویس, روانشناس”, on a page in English for a Persian story. Unisolated, the names and the commas between them ran together right to left, so the English reader met the last name first and the commas fell on the wrong sides.
- Isolate each name in a list that goes into a sentence (nameList in src/lib/studio/room-words.ts wraps each in U+2068 … U+2069; in markup, a <bdi> each). The room’s convene card, its experts at work and its Ideas use it.
- A book’s title beside its line is a name too: isolate the title alone inside the words (U+2068 … U+2069), and keep the phrase in the page’s direction, in a <span>, never a <bdi>. A <bdi> takes its direction from its first letter, a letter inside an isolate included: around “شاهنامه, line 14” it went right to left and put “line 14” before the title, on a card’s departure from the source and in the Ideas panel’s sources, isolated title or not. The room’s “Read “شاهنامه (متن)” from line 12” turned its brackets around too until the title was isolated.
Lines of a text that share one direction
Dabir’s question to the room, on its convene card, lost its line breaks, and once they showed, every line took the direction of the text’s first letter (dir="auto"). The Persian lines it quoted from the Library, each with its place («زال زر چو از کوه آمد فرود» (شاهنامه، سطر 13)), ran right to left inside a left-to-right paragraph: the list came out in the wrong order, its brackets at the wrong end. A person’s own message in the room, a file’s description, and comments, direct messages and Telegram messages in the backoffice mixed their lines the same way.
- Show a text’s own line breaks (whitespace-pre-line or whitespace-pre-wrap) and give each line its own direction: [unicode-bidi:plaintext] beside dir="auto". The lint rule lines-share-one-direction catches a block without it.
A book’s lines in the page’s direction
The Library’s book reader gave its numbered lines the page’s direction. In an English Studio a Persian book (the Shahnameh) put each number at the left edge and each line (dir="auto") at the right, the width of the page between them, so no number could be read with its line.
- Give a list of a text’s lines (a book, a script, a quote with its line numbers) the text’s own direction and language on the list itself (dir and lang from the book’s language, or from its letters: bookLang in src/lib/studio/library.ts), so its numbers sit beside its lines, in its digits.
- It is “A value cell that takes its text’s direction” again, in a list: in a row laid out in the page’s direction, never give one cell dir="auto".
A name in the other script cut at its beginning
A row keeps the page’s direction with the name in a <bdi>, so a name in the other script sits where the row starts. Cut short, though, it ran off at the row’s far side, where its own first words are: on a Persian shot page the takes’ English titles read “…d lifts off the white” and the strip’s “… workshop at dawn”, and the Canon’s tree did the same; a Persian name on an English page lost its first words the same way, and so did a name beside a label in one row (the backoffice’s filters, a shot’s code and title under the episode’s player).
- Let a name in a <bdi> of its own cut its own words: layout.css gives a <bdi> that is a cut-short element’s only child display inline-block, max-width 100% and its own ellipsis, so the row keeps the page’s side and the name keeps its beginning, in either direction.
- Where words share the row with the name (a label, a separator, a count, another name), give each its own element: the row flex with min-w-0, the words shrink-0, each name in <bdi class="min-w-0 truncate">. Left in one cut-short element, a lone <bdi> is one block on the line, and a long name is hidden whole behind the ellipsis (“on …” under a comment); pnpm divan:lint flags it (bdi-beside-words-cut-short).
- Give the element wholeWhenCut as before: it looks inside such a <bdi> for the cut, so the whole name still shows on hover (src/lib/cut-short.ts).
- Look at a long name in the other script where it is cut short (an English title on a Persian page, a Persian one on an English page): it shows its beginning and ends with an ellipsis.
A Persian date that starts with its year
Studio’s story history headed each day with dateStyle: 'full', and Learning’s days apart formatted the weekday, day, month and year at once. In Persian both read «۱۴۰۵ آذر ۱۲, پنجشنبه»: the year first and a Latin comma, where a reader expects «پنجشنبه ۱۲ آذر ۱۴۰۵». The weekday alone, and the day, month and year alone, come out right.
- Write a day in full with fullDay(at, lang) from #lib/time.js, or format the weekday on its own and put it before the day, month and year. On a chosen calendar, dayLabel in src/lib/learning/calendar.ts writes a day out, and the Calendar names its days with it: bits-ui’s own names for screen readers read year first too.
- The lint rule persian-full-date flags dateStyle: 'full' and one format with both a weekday and a year.
An empty field that starts at the far side
Studio’s question card in Claude put the placeholder of its own-words box («پاسخ خودت…») on the left of a Persian card, where a Persian line ends, with its “…” at the wrong end. dir="auto" takes a field’s direction from its first letter, and an empty field has none, so the browser makes it left to right: on a Persian page, the placeholder and the caret of every empty field with dir="auto" sat on the left until something was typed, in the room, Studio’s sheets and the backoffice (85 fields), and in an empty Canon file.
- Add nothing to a field with dir="auto": layout.css keeps it in the page’s direction while its placeholder shows and reads the placeholder in its own direction, so a Latin one (https://…) stays whole, and aligns it to the side the page starts on, so its caret starts there too; Input and Textarea leave dir off an empty field with no placeholder. Once something is typed, it takes the direction of its first letter, as before.
- Leave a filled field to dir="auto". Kept in the page’s direction with unicode-bidi: plaintext instead, it looks the same in Chrome, but in Safari a long line in the other script cannot be scrolled to its end.
- A page with its own style, outside layout.css (Studio’s card in Claude), carries the same two rules, and a field it builds leaves dir off while it is empty and has no placeholder (ownDir in src/lib/server/studio/connector-card-app.ts). A text editor’s line with no letters starts where the words around it start, and the words it shows in an empty text where the page starts (data-dir, src/lib/studio/line-direction.ts).
- pnpm divan:lint flags the browser’s own <input> or <textarea> with dir="auto" and no placeholder (empty-field-far-side): use Input or Textarea, or dir={value ? "auto" : undefined}.
A month grid whose arrow keys run backwards in Persian
bits-ui’s Calendar moves to the day before on the left arrow in either direction, so on a Persian grid, whose week runs from the right, every arrow press went the wrong way (found while building Learning’s booking page). On its own it also starts every week on Sunday, names its buttons Previous and Next in English, and opens a Gregorian month in a Persian grid with no day chosen yet; and Intl titles a Persian month «۱۴۰۵ آذر», the year first.
- Choose a day with Calendar (#lib/components/ui/calendar): the arrows trade places in Persian, a Persian week starts on Saturday (شنبه) and a Gregorian one on Monday, its words and digits follow lang, and the page gets the same ISO day (YYYY-MM-DD) from either calendar.
- Days with nothing free go to isDateUnavailable: dimmed, and a press on them does nothing, rather than a no after the press. Days of the month before and after stay empty, so none reads as a dimmed one.
- pnpm divan:lint flags bits-ui’s Calendar or RangeCalendar imported anywhere else (calendar-by-hand).
A blank line whose caret starts at the far side
An empty field on a Persian page showed its placeholder at the right but its caret at the left when it had room for several lines (the room’s chat, a question card’s own words), and so did a blank line, a new list item and an emptied table cell in the Canon editor. unicode-bidi: plaintext, which the browser gives a <textarea> with dir="auto" and the editor gives every line so that mixed text reads well, takes a line’s direction from its first letter, and lays out a line with no letters left to right whatever direction says, in Chrome, Safari and Firefox. The check after the fix for empty fields read the placeholder and the computed direction, and both were right; only the caret showed it.
- Look at the caret as well as the placeholder: press into the empty field, or press Enter after a Persian line, and see where it blinks.
- An empty field: layout.css aligns it to the side the page starts on while its placeholder shows (text-align from --start-side, which the nearest dir="rtl" or dir="ltr" sets) and keeps plaintext, so a Latin placeholder still reads whole. unicode-bidi: isolate would move the caret too, but Firefox reads the placeholder with the field’s own unicode-bidi and shows https://… as …/https://; and :dir(rtl) would not do, because the build turns it into a list of languages (:lang(ar), :lang(fa)…).
- A line with no letters in a text editor: unicode-bidi: isolate and the direction of the words before it (after it, at the top; the page’s, in a text with no words), as data-dir from src/lib/studio/line-direction.ts. A new line after an English one starts at the left, after a Persian one at the right.