How it works
Every page exists in both languages, with the language in the address: /ar/... and /en/.... Arabic is the default: a visitor who opens / goes to /ar. The layout sets lang and dir on the page, so Arabic pages are right to left and English pages left to right, including the dashboard and these docs.
Two kinds of text:
- Interface texts (buttons, labels, page texts) in
messages/ar.jsonandmessages/en.json. Both files have exactly the same keys. - Store content (product names and descriptions, categories, edits, shipping methods, store name) in the database, with an Arabic and an English column each (
nameAr,nameEn...). The dashboard edits both side by side.
Prices, dates and numbers are formatted for the language with the Intl API: Arabic pages use Latin digits (ar-OM-u-nu-latn), which most Omani shoppers prefer for prices and phone numbers. To use Arabic-Indic digits, change ar-OM-u-nu-latn to ar-OM in src/lib/pricing.ts and the dashboard's date helper.
Right to left details
- Layout uses logical CSS (
ms-,me-,start-,end-,ps-,pe-), so it mirrors by itself. - Arrows that point "forward" carry the class
flip-rtl. - Codes, SKUs, emails and phone numbers sit in
ltr-numsordir="ltr"so thatSQ-7KQ2-M9XDor+968 9123 4567never get scrambled inside Arabic text. - Search folds Arabic spelling variants (أ إ آ → ا, ة → ه, ى → ي, diacritics removed), so «عباءه» finds «عباءة». See
normalizeTextinsrc/lib/filters.ts.
Changing a text
Open messages/en.json or messages/ar.json, find the key and change the value. Plurals use ICU format, for example:
"products": "{count, plural, =0 {No products} one {# product} other {# products}}"
Arabic has more plural forms (zero, one, two, few, many, other); the existing Arabic messages show how they are used.
Adding a language
- Add the code to
localesinsrc/i18n/routing.ts, and to the matcher insrc/proxy.ts(/(ar|en)/becomes/(ar|en|fr)/). - Copy
messages/en.jsontomessages/fr.jsonand translate it. - Add database columns for the content (
nameFr,descFr...) inprisma/schema.prisma, runnpx prisma db push, and show them in the dashboard forms. - Update the places that choose between
nameArandnameEn(search the code for? p.nameAr : p.nameEn). - Add the language to
isRtlinrouting.tsif it is written right to left.