
return ( <span dir="rtl" lang="ar" ...props> formattedContent </span> ); ; const ArabicText = ( children, ...props ) => // Automatically handle mixed LTR/RTL content const wrappedChildren = React.Children.map(children, child => if (typeof child === 'string') // Wrap English/LTR segments in bdi tags const parts = child.split(/([a-zA-Z0-9\s]+)/); return parts.map((part, i) => if (/[a-zA-Z]/.test(part)) return <bdi key=i>part</bdi>; return part; ); return child; ); return ( <span dir="rtl" lang="ar" ...props> wrappedChildren </span> ); ; 3. With Font Optimization Hook import React, useEffect, useState from 'react'; const useArabicFont = () => const [fontLoaded, setFontLoaded] = useState(false);
function ProductCard() return ( <div> <ArabicText> سعر المنتج: $49.99 </ArabicText> /* Renders as: سعر المنتج: ٤٩.٩٩ $ */ </div> ); Arabic Text.jsx
useEffect(() => // Check if Arabic font is supported const checkFont = async () => if ('fonts' in document) await document.fonts.ready; setFontLoaded(true); return ( <span dir="rtl" lang="ar"
return fontLoaded; ;
; checkFont(); , []);