Skip to content

Nuxt RTL: Arabic and right-to-left in Nuxt

Configure Nuxt I18n for Arabic routes, server-rendered language and direction, locale-aware metadata, and component styles that work in both directions.

By , Founder of Ritla

Guide13 min read

An Arabic Nuxt page can finish loading in RTL while its original HTML was LTR. A language button can translate the heading without changing the localized route. A correctly mirrored page can still advertise the English URL as its canonical. These failures come from different parts of the locale integration.

Nuxt I18n can describe each locale's language and direction, generate localized routes and supply locale-related head metadata. The application still needs to apply that metadata during rendering, switch locales through the module's routing flow and make its own styles direction-aware.

This guide uses a geological-sample loan portal. The examples follow Nuxt 4's directory layout and Nuxt I18n v10 APIs, checked against the v10.6 documentation. Retain your project's configured source directory when adapting them to Nuxt 3. Avoid mixing these examples with older iso fields or obsolete head-composable options.

Define language, direction and routing in the locale configuration#

Install a compatible @nuxtjs/i18n release using its installation instructions, then register the module. This example uses English without a prefix and Arabic beneath an Arabic prefix:

ts
// nuxt.config.tsexport default defineNuxtConfig({  modules: ['@nuxtjs/i18n'],  i18n: {    baseUrl: 'https://samples.example.org',    defaultLocale: 'en',    strategy: 'prefix_except_default',    detectBrowserLanguage: false,    langDir: 'locales',    locales: [      { code: 'en', language: 'en-GB', dir: 'ltr', name: 'English', file: 'en.json' },      { code: 'ar', language: 'ar-EG', dir: 'rtl', name: 'العربية', file: 'ar.json' },    ],  },});

Replace the example origin with the portal's actual production origin before deployment. The regional language choices here are British English and Egyptian Arabic; select language tags that describe your product's audience rather than copying a region by habit.

The locale code identifies the locale in module APIs and routes. The language field is a language tag used by locale metadata and matching. The dir field states the intended layout direction. Keep those roles separate: an Arabic message bundle does not itself declare HTML direction.

Use the module's configuration reference when upgrading. In the default v10 structure, langDir is relative to the root i18n directory. It is not automatically relative to Nuxt 4's app directory, and the leading slash in an asset URL is not appropriate for this filesystem option.

For the examples below, the relevant files are:

text
nuxt.config.tsi18n/locales/en.jsoni18n/locales/ar.jsonapp/app.vueapp/components/LocaleSwitcher.vueapp/pages/loans.vue

Keep the message files at the configured paths. A missing Arabic file can look like a direction bug when English fallback text changes the page's wrapping and alignment, but repairing CSS will not load the missing messages.

Add complete messages for the first localized page#

Start with the page title, description and states the loan page actually exposes. These files give the later examples a defined translation source:

json
{  "pageTitle": "Geological sample loans",  "pageDescription": "Review loan requirements and the return schedule for geological samples.",  "loadingLoans": "Loading loan requests",  "loanError": "Loan requests could not be loaded. Try again."}

Save that as i18n/locales/en.json, and the following as i18n/locales/ar.json:

json
{  "pageTitle": "طلبات إعارة العينات الجيولوجية",  "pageDescription": "راجع متطلبات إعارة العينات الجيولوجية ومواعيد إعادتها.",  "loadingLoans": "جارٍ تحميل طلبات الإعارة",  "loanError": "تعذر تحميل طلبات الإعارة. حاول مرة أخرى."}

Nuxt I18n's translation-loading guide describes loading messages through locale files. Check the production build as well as development: a file resolving through a local path assumption may fail in the deployed environment.

Test a cold Arabic load, then a switch from English. The first verifies the initial locale's messages; the second verifies loading during navigation. Include a failed data request so the translated error message is exercised, not just the heading.

Keep language fallback distinct from direction. An English fallback label on an Arabic route is missing content to fix. It is not a reason to turn the surrounding document LTR.

Apply locale head output during server rendering#

Putting dir: 'rtl' in a locale object describes the locale. Apply the generated head properties so that the actual document receives that direction.

Use one application-level integration in app/app.vue:

vue
<script setup lang="ts">const localeHead = useLocaleHead({ dir: true, lang: true, seo: true }); useHead(() => ({  htmlAttrs: { ...localeHead.value.htmlAttrs },  link: [...(localeHead.value.link ?? [])],  meta: [...(localeHead.value.meta ?? [])],}));</script> <template>  <NuxtLayout>    <NuxtPage />  </NuxtLayout></template>

These composables and Nuxt components are supplied by the configured application and module. The example uses the ordinary useLocaleHead integration, with experimental strict SEO mode left at its default of disabled. If your application enables that mode, follow its documented head-management path rather than stacking integrations.

The current useLocaleHead API uses dir, lang and seo options. Its returned ref contains metadata; the useHead call applies it. Returning the values through a reactive callback keeps them connected to locale changes. Nuxt's useHead reference describes reactive head management and document attributes.

For the configured Arabic page, expect an Arabic language tag and dir="rtl" on the root HTML element. The W3C direction guidance explains why an Arabic lang value alone does not supply direction.

Inspect the response HTML before relying on the interactive DOM. R001 covers document direction missing, contradicted, or declared only in CSS. R002 covers html[lang] missing, non-Arabic, or contradicting detected content. Neither result establishes that a language switch preserves the current loan record.

Remove competing writers when the values disagree. A static htmlAttrs.dir in configuration, a layout-level override and a client plugin writing the root can produce different results across navigation paths. Keep locale-derived document attributes under one integration, and use local boundaries only for content that needs another direction.

Avoid copying the head fields into a plain object once during setup and expecting that copy to follow later navigation. The initial Arabic response can pass while the same application instance retains Arabic attributes after switching to English. The callback above reads the current ref when head state is evaluated. Test both directions on the existing instance, and inspect canonical and alternate links along with the attributes; a stale head integration can affect more than layout.

Verify routes independently of translated text#

With prefix_except_default and English as the default, the loan list has an English route at /loans and an Arabic route at /ar/loans. Both come from app/pages/loans.vue; a locale prefix does not require duplicating the page component.

Nuxt I18n's routing-strategy guide describes the alternatives. Choose a strategy deliberately. Changing to no_prefix removes the language distinction from these URLs and changes the locale-resolution and caching problem the application must solve.

Create the initial page probe:

vue
<!-- app/pages/loans.vue --><script setup lang="ts">const { t } = useI18n(); useSeoMeta({  title: () => t('pageTitle'),  description: () => t('pageDescription'),  ogTitle: () => t('pageTitle'),  ogDescription: () => t('pageDescription'),});</script> <template>  <main>    <h2>{{ t('pageTitle') }}</h2>    <p>{{ t('pageDescription') }}</p>  </main></template>

The module handles locale routing; this page supplies its application-owned title and description. Nuxt's useSeoMeta documentation explains the getter form used for reactive values.

Open each URL directly, refresh it and navigate to it through the application. Record the resolved route, root attributes and heading together. If only the heading changes, the text layer has passed while the route or document layer still needs investigation.

Use locale-aware route helpers for application links rather than manually concatenating the Arabic prefix. The module's usage guide documents useLocalePath and localized route names. Prefix concatenation becomes harder to maintain once routes have custom translations or dynamic parameters.

Switch language through Nuxt I18n's navigation flow#

Assigning a Vue I18n locale ref directly can change message rendering without performing the Nuxt module's complete switch. Use the module's setLocale method for a button-driven change:

vue
<!-- app/components/LocaleSwitcher.vue --><script setup lang="ts">const { setLocale } = useI18n();</script> <template>  <div>    <button type="button" lang="ar" @click="setLocale('ar')">العربية</button>    <button type="button" lang="en" @click="setLocale('en')">English</button>  </div></template>

Render LocaleSwitcher in the shared application shell or layout. Nuxt I18n's language-switching guide explains why its navigation flow matters: the module coordinates translation loading, hooks and the locale cookie when one is used.

For an actual language link, use the module's SwitchLocalePathLink component. It resolves the equivalent page in the requested locale and supports the module's handling of dynamic route parameters during server rendering. Decide whether the control is a navigation link or a button-driven action instead of making a nonfunctional link with a click handler.

For a loan-detail route with a stable identifier, confirm that switching preserves that identifier. If a public page uses translated slugs, provide the translated parameter mapping through useSetI18nParams. Do not assume changing the prefix also translates the remaining path.

Check rapid repeated selection, failed message loading and the return transition to English. A successful first switch does not verify an interrupted navigation or a restored history entry. Keep unsent loan notes and selected samples in the test so a remount cannot hide lost state.

Page transitions introduce another visible boundary. By default, the locale changes during navigation, so the outgoing page can acquire the new language before its leave animation finishes. If that causes the loan form to reflow mid-transition, diagnose the sequence rather than adding a timeout around the root direction update.

The module documents an optional skipSettingLocaleOnNavigate flow with finalizePendingLocaleChange in the transition's onBeforeEnter hook. Enable the option only when implementing that complete lifecycle. A pending locale that is never finalized leaves navigation and translation out of agreement. Keep the head integration derived from the committed locale instead of running a separate delayed direction timer.

Test a switch while a loan error is visible and while a popup is open, with animations enabled and with reduced motion. Decide whether the popup should close before navigation. Changing transition timing should preserve the selected sample and unsent text; using a locale-dependent key to recreate the whole page can conceal the timing problem by discarding that state.

The example disables browser-language detection so the localized route is the explicit language choice. That makes direct-load tests easier to interpret; it is a product policy, not a requirement for every Nuxt site.

If the product offers language detection, configure it deliberately. Nuxt I18n's browser-detection guide documents request-header detection, browser detection and cookie persistence. It recommends root-only detection so visitors and crawlers can access a specifically requested language URL.

Test an Arabic deep link with an English browser preference and an existing English locale cookie. Also test the reverse combination. Record the redirect chain and final URL before examining layout. If the visitor is sent to English first, another RTL stylesheet is not the repair.

When cookies are enabled, verify that an explicit language switch updates the preference through the module's supported flow. A stale cookie can explain why a later navigation returns to the previous language. Clearing cookies may help reproduce the boundary, but it is not a product fix.

Keep redirect policy separate from document direction. The final Arabic route still needs Arabic head attributes, regardless of whether the user arrived through detection, a bookmark or a language control.

Prevent localized data from retaining the previous language#

The heading can change correctly while loan rows keep English descriptions fetched earlier. Application data is another locale consumer, separate from the message catalog.

Include locale in both the request contract and the identity of locale-dependent async data. Within the loan page's setup, this pattern assumes the portal already provides /api/loans, accepting a locale query and returning loan objects:

ts
const { locale } = useI18n();const loanDataKey = computed(() => `sample-loans:${locale.value}`); const { data: loans, status, error } = await useAsyncData(  loanDataKey,  () => $fetch<Array<{ id: string; description: string }>>('/api/loans', {    query: { locale: locale.value },  }),);

Add this to the page's existing setup; the endpoint is the application's API, not an endpoint supplied by Nuxt. Render loadingLoans and loanError for its pending and failed states, and keep list keys tied to stable loan identifiers.

Nuxt's useAsyncData reference documents reactive keys and shared keyed data. A locale-dependent response should not be treated as the same data identity merely because the page component is unchanged.

Include other response-changing inputs, such as the selected sample or filter, in the relevant data identity too. Keep this separate from backend or CDN caching: changing a Nuxt key does not establish that every upstream cache distinguishes localized responses.

Delay responses while switching languages and confirm that the displayed descriptions match the current locale and loan identifiers. Then refresh the Arabic URL to test the server path. A correct client-side refetch is not evidence that the initial response used the same data contract.

Separate stored values from their translated presentation. A sample's stable identifier should remain the same across languages, while an API-provided description can change. Keep that identifier when rendering list keys, submitting a loan action and matching delayed responses to the selected sample. Do not make a translated display label the request identifier just because it is the most visible value in the Arabic interface.

Treat SSR, generated pages and caches as separate verification paths#

Do not recreate a browser locale singleton as mutable server-wide state. Request-specific locale decisions belong in the Nuxt application context. If additional shared application state is needed, Nuxt's useState reference describes its SSR-friendly keyed state and hydration behavior. Direction itself can remain derived from the resolved locale rather than becoming another independently mutable store.

Compare the first HTML response with the hydrated page. A client-only plugin or onMounted assignment can make the latter look correct while the server still sends the wrong attributes. Fix the request-to-render locale handoff rather than suppressing the resulting mismatch.

Repeat requests in both language orders and in a fresh browser session. Compare the title, heading, root attributes and representative loan description. This exposes state that only appears correct after an earlier visit loaded the other bundle.

For prerendered deployment, inspect the generated Arabic output and its deployed URL. Localized route generation does not by itself prove that the deployment generated, published and serves every intended route. Check the prerender route list or crawl results and any hosting fallback behavior.

Include missing-record and failed-load responses in deployment checks. A loan detail that renders correctly with valid data can take another rendering path when its record is absent. Inspect the response status, visible language and document attributes on that path rather than treating the normal page as coverage for it. Keep a screenshot of the error alongside its request URL so the result can be reproduced without relying on a transient API failure.

If response caching is enabled, verify its language boundary using the actual request paths, queries or headers on which the response depends. With the example's distinct locale paths, test each path against the deployed cache. A cookie-dependent language at one shared URL requires a different cache design; do not assume that changing dir on hydration fixes the cached response.

Configuration does not mirror the portal's custom CSS#

Once the document is correct, inspect the loan toolbar's own layout. A physical margin in a component stylesheet remains physical even when Nuxt I18n supplies RTL attributes.

Suppose its action group should sit at reading end. This rule works in the English horizontal flex toolbar:

css
/* Problem: the application's toolbar styles. */.loan-toolbar { display: flex; align-items: center; }.loan-actions { display: flex; gap: 0.75rem; margin-left: auto; }

The intended relationship is free space before the action group, not a permanent physical left margin. Replace that property in the same component:

css
.loan-toolbar { display: flex; align-items: center; }.loan-actions { display: flex; gap: 0.75rem; margin-inline-start: auto; }

Here .loan-actions is the toolbar's action-group flex item. The English layout retains its left auto margin; horizontal RTL maps the free-space relationship to the opposite side. The logical-properties specification defines the mapping, and the flexbox specification defines auto-margin alignment.

R030 covers direction-sensitive physical properties without an RTL override. Review inline styles, imported themes and plugin CSS alongside the page's scoped styles. A locale-aware Nuxt layout cannot rewrite a stylesheet that still fixes an element to a physical edge.

Test the toolbar at narrow widths with the longest translated actions. Correct alignment does not establish that everything fits. Keep DOM order meaningful and inspect wrapping before adding reverse-order classes or hiding overflow.

For mixed-content sample identifiers, technical inputs and directional icons, keep the boundary local to the value or control. Use Arabic and English mixed text for isolation decisions and what should be mirrored in RTL for icon semantics.

Inspect library popups and Teleport output separately#

An equipment selector or scheduling popup may render outside the loan page's wrapper. Inspect its final DOM location and computed direction instead of relying on where its component appears in the template.

Vue's Teleport documentation distinguishes logical component relationships from rendered DOM ancestry. A popup can retain injected application state while inheriting direction from its destination. Global root direction helps document-wide Arabic interfaces; a locally different-direction preview needs its own explicit contract.

Check the library's locale or direction provider too. Its translated buttons, layout settings and date-adapter formatting may be separate options. Drive them from the resolved Nuxt locale without creating a second language preference inside the widget.

Follow the installed Nuxt and library integration's SSR target requirements for teleported content. Do not move an overlay to a different target just to inherit dir without testing hydration, clipping and focus behavior. A client-only wrapper changes when the content exists; it is not proof of correct server output.

Open the popup after a direct Arabic load and while switching from English. Test keyboard entry, dismissal and focus return. Include the narrow layout and long translated options, since a closed trigger cannot reveal the popup's layout or inherited direction.

Verify locale metadata without expanding this into a separate SEO system#

The root integration forwards the locale head's links and metadata as well as its HTML attributes. Nuxt I18n's SEO guide documents language tags, alternate links, canonical URLs and locale metadata. The configured production base URL is part of that setup.

Inspect the Arabic response's actual canonical and alternate links. Confirm that their origins are the intended deployment origin and that the linked pages exist in the stated language. R003 covers an hreflang alternate set lacking any Arabic entry on an Arabic page. That check does not establish that every alternate describes the same loan content.

Keep application titles and descriptions translated through the page's useSeoMeta configuration. Generated locale metadata does not translate an arbitrary title left in English. Also search for another SEO module or layout emitting competing canonical links before adding a manual replacement.

For translated dynamic paths, compare the server-rendered alternate URLs with the language switcher's destinations and the actual detail pages. A correct prefix around an untranslated or nonexistent slug is still the wrong destination. Test direct requests to those destinations rather than accepting the head markup as sufficient evidence.

Verify the same loan journey across response and navigation states#

Use a saved loan request and repeat the journey against a production build.

Keep separate evidence for a direct response and a client navigation. For the example configuration, /loans should resolve to English with LTR direction, and /ar/loans to Arabic with RTL direction. Capture each response before running the switcher, then compare the same destinations reached through navigation. If only navigation fails, investigate reactive head updates, retained component state or pending locale work. If the response is already wrong, start with route resolution and rendering instead.

Check the document and application state together:

  • Open the Arabic list and a detail deep link directly, then refresh both.
  • Inspect root language and direction in the response and after hydration.
  • Switch languages and confirm that the route, title, descriptions and selected loan agree.
  • Open library popups and test pending, error and validation states.
  • Compare logical toolbar alignment in English and Arabic at wide and narrow widths.
  • Repeat with conflicting browser preferences or cookies if detection is enabled.
  • Verify generated pages, response caches and alternate destinations on the deployed site.

When a discrepancy remains, record the request URL, redirect chain, resolved locale, root attributes and failing component state. That evidence separates a locale-resolution problem from head application, data reuse or custom CSS.

A free Ritla scan of the Arabic loan page can show missing or contradictory document direction in the page being served. Continue with Arabic localization testing to cover the complete loan journey, or debugging RTL layout problems when document attributes are correct but a component still uses the wrong side.

Checks in this guide

See what your Arabic pages are hiding

Paste a URL. Ritla renders the page on desktop and mobile, runs every check, and shows the top issues with screenshot evidence.

Scan a page freeBrowse the checks