Skip to content
العربية
Foundations

Language and direction

English and Arabic, RTL rules and built-in strings.

  • English is the main language; Arabic is right to left. Set lang and dir on <html> and lang on PercentProvider.
  • Use logical utilities only: ms-, pe-, start-, text-start. Never ml-, pr-, left-.
  • Direction icons (arrows, chevrons) mirror with rtl:-scale-x-100. Nothing else mirrors: not the % mark, not the slash angle.
  • Digits are Western in both languages. Money: the Riyal sign left of the number, never “SAR”.
  • Wrap ids, codes and English inside Arabic text with isolate().
  • Built-in strings (Close, Next, …) come from useStrings(); override single ones with <PercentProvider strings>.
  • To scramble the visible built-in strings on a language switch too, pass <PercentProvider text={(s) => <ScrambleText>{s}</ScrambleText>}>.

isolate()

رقم الطلب ⁦#4821-B⁩ جاهز.

Built-in strings

closeClose
menuMenu
homeHome
siteLinksSite links
mainNavigationMain navigation
loadingLoading
previousPrevious
nextNext
paginationPagination
morePagesMore pages
breadcrumbBreadcrumb
skipToContentSkip to content

Give the app's own words

  • Pass the app's words to <PercentProvider strings>. The components then show no built-in word.
  • Type each object as the exported Strings type. A missing key is then a build error, also when a new version adds a key.
  • Keep the objects outside render (a module constant), so the reference stays the same and the components do not render again.
  • Helpers called outside components take a strings argument: saudiError, phoneIssueMessage, formatDateTime, plateIssueMessage, plateLabel. Pass the app's words.
  • Invoice shows its labels in both languages: give the second language with otherLanguageStrings.
app/strings.tsx
import { formatDateTime, Invoice, PercentProvider, saudiError, type Strings } from "@percentsa/ui";

// app/strings.ts: every key in the app's words. A missing key is a build error.
export const WORDS: Record<"en" | "ar", Strings> = {
  en: { close: "Close", next: "Next" /* …every key of Strings */ },
  ar: { close: "إغلاق", next: "التالي" /* …every key of Strings */ },
};

// A module constant: the same reference on every render.
<PercentProvider lang={lang} strings={WORDS[lang]}>{children}</PercentProvider>;

// Outside components, pass the same words.
saudiError("iban", value, lang, WORDS[lang]);
formatDateTime(createdAt, { lang, strings: WORDS[lang] });

// Invoice: the labels of the second language.
<Invoice {...invoice} otherLanguageStrings={WORDS[lang === "ar" ? "en" : "ar"].invoice} />;