QuiiBz / next-international

Type-safe internationalization (i18n) for Next.js
https://next-international.vercel.app
MIT License
1.19k stars 52 forks source link

Should I place my api routes under [locale] ? #389

Open dBianchii opened 3 months ago

dBianchii commented 3 months ago

I am using this library, and I managed to get this to work when my api folder is not inside the [locale] folder. Is this the correct way to do it?

If I don't have locale accessible inside the api, this will mean I won't have access to the user's selected language in there, yes? I'm not sure if this will be a problem

gustaveWPM commented 1 month ago

Just an example from my own project:

image


If I don't have locale accessible inside the api, this will mean I won't have access to the user's selected language in there, yes? I'm not sure if this will be a problem

I guess you should add the locale in headers/parameters of your API endpoint, then?

kejiahp commented 1 month ago

I don't believe it's necessary to place your API routes inside the [locale] folder. You can access the locale via the NEXT_LOCALE cookie or the Accept-Language header an if that won't do you can also access the locale by formatting the URL gotten from the Referer header.