You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
What operating system, Node.js, and npm version?
Windows 11
node 18.19.1
npm 10.0.0
yarn 4.1.1
What happened?
I have been trying to get the package working. I am using the pages router.
I am using the useTranslation hook to get the t function. The problem is that the values do not load properly when in the development environment. When running next build and then starting the compiled version it works fine, the problem only exists in the development environment.
While it does not break the application, it is quite annoying to develop an app without knowing if any of the translations are going to work before compiling the application.
I have also noticed that the lang coming from the useTranslation hook seems to be an empty string, but I am not sure if that is the cause of the translations not being loaded.
// middleware.tsimporttype{NextRequest}from'next/server'import{NextResponse}from'next/server'/** Regex to check if current path equals to a public file */constPUBLIC_FILE=/\.(.*)$//** Ignore non-page paths */constshouldProceed=(pathname: string)=>{if(pathname.startsWith('/_next')||pathname.includes('/api/')||PUBLIC_FILE.test(pathname)){returnfalse}returntrue}exportasyncfunctionmiddleware(request: NextRequest){const{ locale, pathname }=request.nextUrl/** Ignore non-page paths */if(!shouldProceed(pathname))returnif(locale==='default'){/** Get user's locale */conststoredLocale=request.cookies.get('NEXT_LOCALE')?.valueconstresponse=NextResponse.redirect(newURL(`/${storedLocale||'en'}/${pathname}`,request.url),)/** Store default locale in user's cookies */if(!storedLocale){response.cookies.set('NEXT_LOCALE','en',{path: '/',})}/** Redirect user to default locale */returnresponse}/** Adds ?lang={locale} for next-translate package */request.nextUrl.searchParams.set('lang',locale)returnNextResponse.rewrite(request.nextUrl)}
What version of this package are you using?
2.6.2
What operating system, Node.js, and npm version?
Windows 11
node 18.19.1
npm 10.0.0
yarn 4.1.1
What happened?
I have been trying to get the package working. I am using the pages router.
I am using the
useTranslation
hook to get the t function. The problem is that the values do not load properly when in the development environment. When running next build and then starting the compiled version it works fine, the problem only exists in the development environment.While it does not break the application, it is quite annoying to develop an app without knowing if any of the translations are going to work before compiling the application.
I have also noticed that the
lang
coming from theuseTranslation
hook seems to be an empty string, but I am not sure if that is the cause of the translations not being loaded.i18n.js
middleware.ts
next.config.mjs
What did you expect to happen?
The
t
function should get the translation from the locale file and provide the correct translation.Are you willing to submit a pull request to fix this bug?
Not currently, as I am very unsure what the problem is. If I find a suitable solution, sure.
The text was updated successfully, but these errors were encountered: