DEV Community

Udhyakumar Murugesan
Udhyakumar Murugesan

Posted on

Next Js Localisation

Hello All,

I am new to this community and thank you for your support and time.
I am working on a bilingual site (English and Japanese). I am using next-intl package to set the locale. I am trying to implement the following use cases

  1. Set the default language to user browser language
  2. Set the default language from EN -> JPA

Tech Stack : Next Js 14, Typescript

I tried changing the language, but its not setting the default languge.

Reference Link - https://next-intl-docs.vercel.app/examples

Thank You
Udhya

Top comments (2)

Collapse
 
drazenbebic profile image
Drazen Bebic •

This should already work out of the box.

Next.js will usually automatically detect the locale using the Accept-Language header which is sent by the client. If you're using a browser, this is usually identical to the navigator.languages values.

Can you show us what your i18n middleware looks like?

Collapse
 
udhyam profile image
Udhyakumar Murugesan •

export default async function middleware(request: any) {
const [, locale, ...segments] = request.nextUrl.pathname.split("/")

const handleI18nRouting = createIntlMiddleware({
defaultLocale: 'ja',
locales,
localePrefix
// localeDetection: false,
})