Internationalization - Next.js 14 and Storyblok
Unanswered
Northeast Congo Lion posted this in #help-forum
Northeast Congo LionOP
Hi!
I am making a multilingual website as a thesis project (using TypeScript, Next.js 14, Vanilla Extract/CSS, translations coming from the CMS Storyblok). I have two questions!
1) Favicon and Images not working with Next.js 14's Internationalization
In the recent documentation about internationalization, it says to skip all internal paths in the middleware
My issue is that language and other slugs are working with that implementation, but the favicon (located in the
Errors:
GET http://localhost:3000/sv/background_1.png 500 (Internal Server Error)
GET http://localhost:3000/sv/favicon.ico 500 (Internal Server Error)
I came up with one solution resulting in images and favicon working fine, but that solution made the language slugs stop working. I have narrowed it down to the matcher, where one makes the images work and the other make the languages work. Any ideas on how to solve this?
2) i18n
I am seeing a lot of people using i18n. If my translations come from Storyblok, do I need i18n for any other reason?
I am making a multilingual website as a thesis project (using TypeScript, Next.js 14, Vanilla Extract/CSS, translations coming from the CMS Storyblok). I have two questions!
1) Favicon and Images not working with Next.js 14's Internationalization
In the recent documentation about internationalization, it says to skip all internal paths in the middleware
matcher: ['/((?!_next).*)'] (https://nextjs.org/docs/app/building-your-application/routing/internationalization)My issue is that language and other slugs are working with that implementation, but the favicon (located in the
app/[...lang] folder) and images (public) are not. Errors:
GET http://localhost:3000/sv/background_1.png 500 (Internal Server Error)
GET http://localhost:3000/sv/favicon.ico 500 (Internal Server Error)
I came up with one solution resulting in images and favicon working fine, but that solution made the language slugs stop working. I have narrowed it down to the matcher, where one makes the images work and the other make the languages work. Any ideas on how to solve this?
let locales = ['sv', 'fa-ir']
function getLocale(request: any) {
return 'sv'
}
export function middleware(request: any) {
const { pathname } = request.nextUrl
const pathnameHasLocale = locales.some(
(locale) => pathname.startsWith(`/${locale}/`) || pathname === `/${locale}`
)
if (pathnameHasLocale) return
const locale = getLocale(request)
request.nextUrl.pathname = `/${locale}${pathname}`
return Response.redirect(request.nextUrl)
}
// // // Background image working, but not language slugs.
// export const config = {
// matcher: ['/((?!api|_next|.ico|).*)'],
// }
// Language slugs working, but not background image.
export const config = {
matcher: ['/((?!_next).*)'],
}2) i18n
I am seeing a lot of people using i18n. If my translations come from Storyblok, do I need i18n for any other reason?