-
Any way to keep the default language in url path ? I have following config module.exports = {
locales: ['en', 'fr'],
defaultLocale: 'en',
}; Any way to keep the defaultLocale in url a path. I mean instead of having site.com/mypage Have: |
Beta Was this translation helpful? Give feedback.
Answered by
zecka
Jun 28, 2023
Replies: 1 comment
-
My bad it was describe on README: https://github.com/aralroca/next-translate#3-configuration So i just update my i18n.js module.exports = {
locales: ['default', 'en', 'fr'],
defaultLocale: 'default',
pages: {
'*': ['common'],
'/': ['home', 'example'],
'/about': ['about'],
},
}; And add a middleware import { NextRequest, NextResponse } from 'next/server'
const PUBLIC_FILE = /\.(.*)$/
export async function middleware(req: NextRequest) {
if (
req.nextUrl.pathname.startsWith('/_next') ||
req.nextUrl.pathname.includes('/api/') ||
PUBLIC_FILE.test(req.nextUrl.pathname)
) {
return
}
if (req.nextUrl.locale === 'default') {
const locale = req.cookies.get('NEXT_LOCALE')?.value || 'en'
return NextResponse.redirect(
new URL(`/${locale}${req.nextUrl.pathname}${req.nextUrl.search}`, req.url)
)
}
} |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
zecka
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
My bad it was describe on README:
https://github.com/aralroca/next-translate#3-configuration
So i just update my i18n.js
And add a middleware