Skip to Content
BBRICKSv0.7.4
Foundations

Languages and RTL

The language prop, the provider, bidirectional text and Arabic line height.

Every component speaks English and Arabic. The Arabic is Egyptian colloquial, written for the TRNDR products.

Setting the language

There are three levels, strongest first:

  1. A component's own language prop ('en' or 'ar').
  2. The language of the nearest BricksProvider.
  3. English, when there is no provider.
<BricksProvider preset={trndrPreset} language={language}>
  <Pager page={2} lastPage={9} total={86} perPage={10} loading={false} label="Creators" onPage={setPage} />
</BricksProvider>

Read it back with useLanguage(). Data hooks take their language from the DataProvider's language, or from the BricksProvider when that is not given.

Direction is yours

BricksProvider renders no element, so it cannot set dir. Set dir and lang on <html> or on a wrapper. (AppShell is the exception: it sets dir and lang on its own root element from its language.) The components use logical properties (margin-inline-start, inset-inline-end, text-align: start), so they mirror by themselves under dir="rtl". Where a piece of content must not flip, the component pins it: money (Money is dir="ltr"), chart values, page numbers in the pager, coupon and URL text.

Same components, both directions

The language is the provider's; the direction is the dir you put on a wrapper (the docs frame does it for you). Tables, tabs, the pager arrows and the start and end edges all flip, while money keeps its digits left to right. This example pins each side to its own language.

Pinned to TRNDR preset
Code
import { useState } from 'react';
import { Avatar, DataTable, Money, Pager, PillTabs, StatusPill, type DataColumn } from '@ergasti/bricks';

interface Row { id: number; name: string; amount: string; status: string }

const rows: Row[] = [{ id: 1, name: 'ليلى سعيد', amount: '12050.00', status: 'paid' }, { id: 2, name: 'Karim Hosny', amount: '3225.00', status: 'pending' }];

const columns: DataColumn<Row>[] = [
  { key: 'name', label: 'Creator', render: (r) => <span style={{ display: 'inline-flex', gap: 8, alignItems: 'center' }}><Avatar name={r.name} seed={r.id} size="sm" />{r.name}</span> },
  { key: 'amount', label: 'Amount', align: 'end', render: (r) => <Money value={r.amount} /> },
  { key: 'status', label: 'Status', render: (r) => <StatusPill status={r.status} /> },
];

function BothDirections() {
  const [tab, setTab] = useState('a');
  const side = (dir: 'ltr' | 'rtl') => (
    <div dir={dir} lang={dir === 'rtl' ? 'ar' : 'en'} style={{ display: 'grid', gap: 12, padding: 16, background: 'var(--card)', borderRadius: 18, minWidth: 0 }}>
      <PillTabs label="Demo" idPrefix={`rtl-${dir}`} value={tab} onChange={setTab}><PillTabs.Tab value="a" count={3}>{dir === 'rtl' ? 'الكل' : 'All'}</PillTabs.Tab><PillTabs.Tab value="b">{dir === 'rtl' ? 'المعلّق' : 'Pending'}</PillTabs.Tab></PillTabs>
      <DataTable label="Payouts" columns={columns} rows={rows} rowKey={(r) => r.id} />
      <Pager page={2} lastPage={9} total={86} perPage={10} loading={false} label="Payouts" onPage={() => {}} />
    </div>
  );
  return <div style={{ display: 'grid', gap: 16, gridTemplateColumns: 'repeat(auto-fit, minmax(340px, 1fr))' }}>{side('ltr')}{side('rtl')}</div>;
}

Numbers and dates

The library writes Western digits in both languages ("12,500", not "١٢٬٥٠٠"): count(n, lang) uses ar-EG-u-nu-latn, dates use shortDate(iso, lang) ("1 Nov 2026" or "1 نوفمبر 2026"), and the Arabic day count has its own noun forms (days: يوم واحد, يومين, 3–10 أيام, 11+ يوماً). An amount inside an Arabic sentence goes through amountInText, which wraps the figure in left-to-right isolation marks so it does not reorder.

Numbers inside Arabic text

amountInText wraps the figure in left-to-right isolation marks so "EGP 5,000" does not reorder inside a right-to-left sentence; formatMoney returns the bare string.

Code
import { Button, amountInText, formatMoney, useLanguage } from '@ergasti/bricks';

function Sentences() {
  const language = useLanguage();
  return (
    <div style={{ display: 'grid', gap: 8 }}>
      <p>{language === 'ar' ? `تم تحويل ${amountInText('5,000', 'ar')} لصانع المحتوى.` : `${amountInText('5,000', 'en')} was sent to the creator.`}</p>
      <p>{formatMoney('61840.00', { language })} · {formatMoney('184300.00', { language, compact: true })}</p>
      <Button size="sm">{language === 'ar' ? 'حفظ' : 'Save'}</Button>
    </div>
  );
}

count

function

"12,500" in both languages: grouped, Western digits (the console's number rule).

function count(n: number, lang: Lang): string

Prop

Type

Source: src/lib/format.ts (line 150)

shortDate

function

"1 Nov 2026" / "1 نوفمبر 2026", Western digits, or '—' for a missing or unparseable date. A date-only string ("2026-11-01") is a calendar date: the same day in every time zone. A date-time is shown in timeZone (an IANA name, e.g. "Africa/Cairo") when given, else in the viewer's own zone.

function shortDate(iso: string | null | undefined, lang: Lang, options3?: { timeZone?: string; }): string

options3: { timeZone?: string; }

Prop

Type

Source: src/lib/format.ts (line 161)

days

function

Arabic counted noun for days: يوم واحد / يومين / 3–10 أيام / 11+ يوماً (accusative singular).

function days(n: number, lang: Lang): string

Prop

Type

Source: src/lib/format.ts (line 181)

Arabic line height

Arabic in Cairo needs more leading than Latin text, or tight lines clip the marks. The kit's tight line heights read var(--lh-ar, <latin value>), and tokens.css sets --lh-ar: 1.6 itself on every element that declares lang="ar" (or ar-EG and the like) or dir="rtl", inherited by everything below. An Arabic page is right with no help from the app, provided it loads tokens.css and declares its language (<html lang="ar" dir="rtl">, or the wrapper AppShell and LoginLayout put it on). An island that declares another language (lang="en" inside an Arabic page) goes back to the Latin values. A test refuses any new unitless line-height under 1.6 that lacks the fallback.

You only set --lh-ar yourself to want more than 1.6, for a display font or a denser table. Set it with a selector at least as specific as the library's, for example on the element that carries the language, or on a wrapper inside it:

html[lang='ar'] {
  --lh-ar: 1.7;
}

Fonts

The tokens name Cairo for Arabic after Inter, but the library ships no font files. Load Cairo (the docs do, from Google Fonts).

Error messages

httpError(status, language) turns a failed request status into a sentence in the page's language, never a raw "HTTP 500". The data hooks use it.

httpError

function

A human message for a failed console request; never a raw "HTTP 500".

function httpError(status: number, lang: Lang): string

Prop

Type

Source: src/lib/format.ts (line 197)

Adding words, not ternaries

A guard test refuses language === 'ar' ? 'نص' : 'text' anywhere in the source. Copy lives in keyed English and Arabic tables, so a missing side, a repeated string or a word an app cannot override is caught. See Words and labels.

On this page