Translation and direction
What you need to know
Language and writing direction are separate document properties. Set lang to the content language and dir to its base direction; use CSS logical properties to support both left-to-right and right-to-left layouts.
By the end, you can: set lang and dir from supported locale; use logical CSS.
Map supported locales to direction
type Locale='en'|'fa';function direction(locale:Locale):'ltr'|'rtl' { return locale==='fa'?'rtl':'ltr';}console.log(direction('fa'));Expected behavior: rtl. The output is a direction token, not translated content.
How it works
English normally uses LTR and Persian uses RTL. An application must derive both from the validated locale, not simply reverse every component or translate strings mechanically. Set lang and dir on the root html element so browsers and assistive technology have context. Logical CSS uses inline/block axes, so padding-inline-start and margin-inline-end adapt to direction. Code samples, identifiers and technical tokens may need explicit LTR presentation inside RTL prose; use appropriate isolation for mixed-direction user-provided text, for example a bdi element around an unknown-direction display name. Render that name as ordinary escaped React text; direction isolation is not HTML sanitization. Keep meaningful DOM order rather than reversing focus order to match a visual design. Format dates, numbers and currency with explicit Intl locale, timezone and units; language is not a reliable indicator of a user's currency or location. Use fixed timestamps in tests. A dictionary should have typed keys and a deliberate fallback for missing strings; a fallback must not be published as a genuine translation. This batch includes only English instructional strings and a synthetic direction test, not Persian translated pages.
Logical layout and isolated code
.card { padding-inline-start: 1rem; border-inline-start: 3px solid teal; text-align: start; }.card code { direction: ltr; unicode-bidi: isolate; }Expected behavior: The border is on the inline start edge in either direction; code stays isolated LTR. Actual reflow and keyboard order need a browser.
Common mistake
Do not use right-align as a substitute for dir=rtl, and do not assume locale determines time zone or currency. Avoid visually reversing focus order.
Practice and verification
Compare an English fixture with a direction-only test container using the same English strings (label it synthetic, not a translated page). Check start-side padding, code order, Tab sequence, narrow viewport and explicit Intl formatting.
Scope: Proposed Next.js 16.x / React 19, Cache Components disabled unless noted. Framework and browser examples are staged; local standalone tests are reported separately. Exact dependency patches and platform contracts pending.