Need help with i18next package config in my project
Unanswered
Japanese jack mackerel posted this in #help-forum
Japanese jack mackerelOP
So my application has a OAuth service and the callback uri is limited to /auth?code=23..... but when am using the package i cannot redirect as the routes are all either /fr/auth or /en/auth depending the preference. How can i solve this issue.
11 Replies
@Japanese jack mackerel So my application has a OAuth service and the callback uri is limited to /auth?code=23..... but when am using the package i cannot redirect as the routes are all either /fr/auth or /en/auth depending the preference. How can i solve this issue.
you normally have a middleware, that allows you to automatically get the preference. Like that you can return the user to
Do you have a middleware, that handles that?
/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?
Japanese jack mackerelOP
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
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
@Japanese jack mackerel 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)?Japanese jack mackerelOP
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);
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);
@Japanese jack mackerel 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?Japanese jack mackerelOP
yes
@Japanese jack mackerel yes
can you clarify this then:
i cannot redirect as the routes are all either /fr/auth or /en/auth
Japanese jack mackerelOP
so whenever i redirect to /auth or any route without the prefix i can see this error
Unable to find
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
@Japanese jack mackerel 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.
change this to
And also change the matcher, so it match also unlocalized routes:
truelocaleDetection: falseAnd also change the matcher, so it match also unlocalized routes:
matcher: ['/', '/(fr|en)/:path*'] // this is your code, that you need to change@Japanese jack mackerel solved?