DEV Community

Udhyakumar Murugesan
Udhyakumar Murugesan

Posted on

3 1 1 2 1

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,
})

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay