You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I want the ability to set the locale (apply the configuration of user selected locale from the database into the layout.tsx), what I mean by that is right at the moment when the user is loggedIn, I want to allow to get the locale and apply it in the (UI) immediately, I have my project setup correctly following the docs, but at the moment in my current setup, after I sign in, the user will need to hard-reload for their selected locale (from the database) to be applied!
These is my configurations:-
1. src/i18n/request.ts
import{getLocale,getRequestConfig}from'next-intl/server'import{getUserLanguage}from'@/actions/users/user-language'import{routing}from'@/i18n/routing'exporttypeLocale=(typeofrouting.locales)[number]exportdefaultgetRequestConfig(async()=>{constlanguage=awaitgetUserLanguage()// this get [ "ar" | "en" from the database ]letlocale=language??(awaitgetLocale())if(!locale||!routing.locales.includes(localeasLocale)){locale=routing.defaultLocale}return{ locale,messages: (awaitimport(`@/../messages/${locale??'en'}.json`)).default}})
import{Analytics}from'@vercel/analytics/react'import{NextIntlClientProvider}from'next-intl'import{getLocale,getMessages}from'next-intl/server'import{getUserLanguage}from'@/actions/users/user-language'import{Providers}from'@/providers'import'./globals.css'exportdefaultasyncfunctionRootLayout({ children }: {children: React.ReactNode}){constlanguage=awaitgetUserLanguage()// this get [ "ar" | "en" from the database ]constlocale=language??(awaitgetLocale())constmessages=awaitgetMessages({ locale })return(<htmllang={locale}dir={locale==='en' ? 'ltr' : 'rtl'}suppressHydrationWarning><head>...</head><bodyclassName='min-h-screen bg-background'suppressHydrationWarning><NextIntlClientProvidermessages={messages}locale={locale}><Providers>{children}<Analytics/></Providers></NextIntlClientProvider></body></html>)}
The > src/app/layout.tsx works when the user signs in, and it does apply the correct lang={} and dir={} in here correctly:-
<html lang={locale} dir={locale === 'en' ? 'ltr' : 'rtl'}>...
But I'm not sure why or HOW I'm suppose to apply the locale in my app.
For more context of my project please checkout the repo:-
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
So I'm using NextJS "15.0.2", and this is my project structure:-
I want the ability to set the locale (apply the configuration of user selected locale from the database into the layout.tsx), what I mean by that is right at the moment when the user is loggedIn, I want to allow to get the locale and apply it in the (UI) immediately, I have my project setup correctly following the docs, but at the moment in my current setup, after I sign in, the user will need to hard-reload for their selected locale (from the database) to be applied!
These is my configurations:-
The > src/app/layout.tsx works when the user signs in, and it does apply the correct lang={} and dir={} in here correctly:-
<html lang={locale} dir={locale === 'en' ? 'ltr' : 'rtl'}>...
But I'm not sure why or HOW I'm suppose to apply the locale in my app.
For more context of my project please checkout the repo:-
https://github.com/MHMDHIDR/crm
Beta Was this translation helpful? Give feedback.
All reactions