Languages

How Arabic and English work, how to change texts, and how to add a third language.

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.json and messages/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-nums or dir="ltr" so that SQ-7KQ2-M9XD or +968 9123 4567 never get scrambled inside Arabic text.
  • Search folds Arabic spelling variants (أ إ آ → ا, ة → ه, ى → ي, diacritics removed), so «عباءه» finds «عباءة». See normalizeText in src/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

  1. Add the code to locales in src/i18n/routing.ts, and to the matcher in src/proxy.ts (/(ar|en)/ becomes /(ar|en|fr)/).
  2. Copy messages/en.json to messages/fr.json and translate it.
  3. Add database columns for the content (nameFr, descFr...) in prisma/schema.prisma, run npx prisma db push, and show them in the dashboard forms.
  4. Update the places that choose between nameAr and nameEn (search the code for ? p.nameAr : p.nameEn).
  5. Add the language to isRtl in routing.ts if it is written right to left.