Files
mohd d40bb10876 Updated PLANS.md, AGENTS.md, and arabic-localization.md to reflect the “foundations now, full translations later” approach and marked progress accordingly.
Implemented localization foundations across backend and frontend (locale settings/middleware, preferred language, i18n wiring, RTL support, minimal Arabic UI strings, Accept-Language).
Added targeted backend and frontend tests plus a risks note for pending full translation coverage.
2026-02-28 11:48:58 +03:00

29 lines
841 B
Python

import re
from django.utils.translation import gettext as _
def normalize_phone_number(raw_phone: str) -> str:
if not raw_phone:
raise ValueError(_("Phone number is required"))
phone = re.sub(r"[\s\-\(\)]", "", raw_phone)
if phone.startswith("00"):
phone = "+" + phone[2:]
if phone.startswith("+"):
digits = phone[1:]
if not digits.isdigit() or not (8 <= len(digits) <= 15):
raise ValueError(_("Invalid phone number format"))
return "+" + digits
digits = re.sub(r"\D", "", phone)
if digits.startswith("0") and len(digits) == 10 and digits[1] == "5":
return "+966" + digits[1:]
if digits.startswith("5") and len(digits) == 9:
return "+966" + digits
raise ValueError(_("Phone number must be in E.164 format or a valid Saudi mobile"))