Playground

i18n and RTL

Direction, locale props, Intl formatting, long text and translated copy.

Direction

Set lang and dir on <html>. Layout that follows the document direction flips on its own. The Customise panel in these docs has a Direction switch that sets dir on <html> and remembers it, so you can try any component in right-to-left.

index.html
<html lang="ar" dir="rtl" data-theme="warm" data-accent="orange">

An RTL pass over the component stylesheets is in progress on a separate branch (logical properties instead of left and right). Until it is merged, some components may still look left-biased in right-to-left; check the ones you use.

DirectionProvider

Radix primitives decide arrow-key behaviour and popover placement from a direction provider, not from the dir attribute. A DirectionProvider re-export from @monoline/react is coming with the RTL work and is not in this version. Until then use Radix's own, which Monoline already depends on (radix-ui; install it in your app if it is not hoisted). Once the Monoline one is merged the import will change and the props will be the same.

app.tsx
import {Direction} from 'radix-ui';

// Radix primitives (Tabs, Select, menus, Slider, Accordion...) read their direction from this provider,
// not from the dir attribute. Without it, arrow keys and popover placement stay left-to-right.
export function App({dir, children}: {dir: 'ltr' | 'rtl'; children: React.ReactNode}) {
  return <Direction.Provider dir={dir}>{children}</Direction.Provider>;
}
app.tsx
// Keep the document and the Radix provider in step.
useEffect(() => { document.documentElement.dir = dir; }, [dir]);

SegmentedControl does not accept a dir prop; it takes the direction from the provider.

Locale props

Components that print dates take a BCP 47 locale. Calendar has locale for month and weekday names and weekStartsOn (0 for Sunday, 1 for Monday). DatePicker passes both through, plus format (Intl.DateTimeFormat options) for the text on the button and placeholder. Neither sets the first day of the week from the locale for you.

date.tsx
import {Calendar, DatePicker, Field} from '@monoline/react';

const locale = 'de-DE';
<Field label="Datum">
  <DatePicker locale={locale} weekStartsOn={1} format={{dateStyle: 'long'}} placeholder="Datum wählen" />
</Field>
<Calendar locale={locale} weekStartsOn={1} aria-label="Kalender" />

NumberInput wraps a native type="number" input, so the browser decides how the digits and the decimal separator look and there is no locale prop. To show a formatted number as text (a price, a total), use Intl.NumberFormat yourself.

intl.ts
const nf = new Intl.NumberFormat('de-DE', {style: 'currency', currency: 'EUR'});
nf.format(1234.5);                      // "1.234,50 €"
new Intl.DateTimeFormat('ar-EG', {dateStyle: 'medium'}).format(new Date());
new Intl.PluralRules('en').select(1);   // "one", use it to pick the right string
new Intl.RelativeTimeFormat('fr', {numeric: 'auto'}).format(-1, 'day'); // "hier"

Long text and wrapping

  • Translated labels are often 30% to 50% longer than English. Do not size buttons or table columns to the English text; let them grow and wrap.
  • In a flex or grid child that holds text, set min-width: 0 so a long word can wrap instead of pushing the layout wide.
  • For user-generated or very long strings (file names, emails) add overflow-wrap: anywhere on the element.
  • Write your own CSS with logical properties: margin-inline-start, padding-inline, text-align: start, inset-inline-end. They follow dir; margin-left does not.
  • Icons that point (arrows, chevrons) need mirroring in right-to-left. Icons that mean something physical (a clock, a play button) do not.
  • Numerals, code and URLs stay left-to-right inside right-to-left text. Wrap them in an element with dir="ltr" where it matters.

Translating copy

Monoline has no translation layer. Every visible string is a prop or a child, so pass the translated value from your own i18n library. Props that carry a string:

Form
errorsTitle, default “Fix these to continue”.
Combobox, MultiSelect
emptyText, default “No matches”.
DatePicker
placeholder, default “Pick a date”.
Command
title, placeholder, emptyText.
Spinner, FileUpload
label.
Names
aria-label on Breadcrumb, ColorPicker, OtpInput, Rating, Slider, SegmentedControl, Pagination.
copy.tsx
import {Form, Combobox, Spinner} from '@monoline/react';

const t = (key: string) => messages[key]; // your i18n library goes here

<Form errors={errors} errorsTitle={t('form.fixThese')}>...</Form>
<Combobox options={options} emptyText={t('combobox.empty')} aria-label={t('country.label')} />
<Spinner label={t('loading')} />

Known English strings with no prop yet (checked in the source at the time of writing): the Calendar buttons “Previous month” and “Next month”, the DatePicker popover name “Choose a date”, the NumberInput buttons “Decrease” and “Increase”, PasswordInput “Show” and “Hide”, the DataTable “Select all rows” checkbox and the FileUpload list name “Selected files”. Adding a prop for each is a compatible change; open an issue if you need one.