#Need help with i18next package config in my project
12 messages · Page 1 of 1 (latest)
🔎 This post has been indexed in our web forum and will be seen by search engines so other users can find it outside Discord
🕵️ Your user profile is private by default and won't be visible to users outside Discord, if you want to be visible in the web forum you can add the "Public Profile" role in id:customize
✅ You can mark a message as the answer for your post with Right click -> Apps -> Mark Solution
(if you don't see the option, try refreshing Discord with Ctrl + R)
you normally have a middleware, that allows you to automatically get the preference. Like that you can return the user to /what/ever/route/you/need/ and the user will be redirected (though middleware) to /fr/what/ever/route/you/need/ or /en/what/ever/route/you/need/ or ...
Do you have a middleware, that handles that?
import createMiddleware from 'next-intl/middleware';
import { routing } from './i18n/routing';
export default createMiddleware(routing, {
localeDetection: false
});
export const config = {
// Match only internationalized pathnames
matcher: ['/', '/(fr|en)/:path*']
};
i have basic middleware like this one
and does it do what you expect: redirecting /your/route to /en/your/route (with preference)?
yea its supposed to as am passing the routing
import { defineRouting } from 'next-intl/routing';
import { createSharedPathnamesNavigation } from 'next-intl/navigation';
export const routing = defineRouting({
// A list of all locales that are supported
locales: ['en', 'fr'],
// Used when no locale matches
defaultLocale: 'en',
localePrefix: 'never'
});
// Lightweight wrappers around Next.js' navigation APIs
// that will consider the routing configuration
export const { Link, redirect, usePathname, useRouter } =
createSharedPathnamesNavigation(routing);
so when redirecting the user to /auth?code=23..... the user will be redirected to /en/auth?code=23..... or /fr/auth?code=23..... or ..., right?
yes
can you clarify this then:
i cannot redirect as the routes are all either /fr/auth or /en/auth
so whenever i redirect to /auth or any route without the prefix i can see this error
Unable to find next-intl locale because the middleware didn't run on this request. See https://next-intl-docs.vercel.app/docs/routing/middleware#unable-to-find-locale. The notFound() function will be called as a result.
am so sorry am really new to this job and dont have much experiance
change this to true
localeDetection: false
And also change the matcher, so it match also unlocalized routes:
matcher: ['/', '/(fr|en)/:path*'] // this is your code, that you need to change