React › Internationalization (i18n) in React
How do you handle right to left languages, like Arabic, in a React app?
IntermediateAnswer
You set the direction attribute on your page, usually to rtl for right to left languages, which flips the layout so text and elements read from right to left instead of left to right. Your CSS may also need adjustments so spacing and icons that assume a left to right layout still look correct when flipped.
function App({ language }) {
const direction = language === 'ar' ? 'rtl' : 'ltr';
return (
<div dir={direction}>
<MainContent />
</div>
);
}Real-world example An app expanding into Middle Eastern markets automatically flips its entire layout to read right to left for Arabic speaking users, while keeping the normal left to right layout for everyone else.