How Neuro Cart implements multi-language support (English & Arabic) with RTL layout compatibility.
- Library:
next-intl - Pattern: App Router internationalization with middleware/proxy
- Formats: JSON-based messages
| Language | Code | Direction |
|---|---|---|
| English | en |
LTR |
| Arabic | ar |
RTL |
Each app has its own translations:
apps/*/messages/en.json
apps/*/messages/ar.json
Configures the loader for the messages:
import { getRequestConfig } from "next-intl/server";
export default getRequestConfig(async ({ locale }) => ({
messages: (await import(`./messages/${locale}.json`)).default,
timeZone: "UTC",
}));The layout.tsx detects the locale and applies the correct dir attribute:
export default async function RootLayout({ children, params }) {
const { locale } = await params;
const direction = locale === "ar" ? "rtl" : "ltr";
return (
<html lang={locale} dir={direction}>
<body>{children}</body>
</html>
);
}- Add the key to
en.json - Add the corresponding translation to
ar.json - Use the
useTranslationshook in your component:
const t = useTranslations("common");
return <h1>{t("title")}</h1>;Utility classes or conditional logic are used for direction-specific styling:
.container {
padding-left: 1rem; /* LTR */
}
[dir="rtl"] .container {
padding-left: 0;
padding-right: 1rem; /* RTL */
}Neuro Cart primarily uses logical CSS properties (padding-inline-start, etc.) where possible for automatic support.