Skip to content

Keep default language in Url path #1093

Closed Answered by zecka
zecka asked this question in Q&A
Discussion options

You must be logged in to vote

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.c…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by zecka
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant