Translations in API routes (app directory) #368
Is your feature request related to a problem? Please describe.We have no way to get the locale from an API route. Describe the solution you'd likeExport
|
Replies: 2 comments 5 replies
|
If you want to resolve the locale based on the next-intl/packages/next-intl/src/middleware/resolveLocale.tsx Lines 38 to 47 in 88eabc7 I'll move this to a discussion, as this is more a usage question—I hope you understand! |
|
How can we use next-intl in API routes? why we don't have any example about it on the docs? EDIT: Ok I think it is here: https://next-intl.dev/docs/environments/actions-metadata-route-handlers#route-handlers |
resolveLocaleis currently not intended to be exported. You can receive thelocalein your Route Handler by accepting it either as a route param or search param to be called accordingly from the client side (e.g./api/hello?locale=enor/en/api/hello).If you want to resolve the locale based on the
accept-languageheader, you can use the same code that we use in the middleware (it's really not much):next-intl/packages/next-intl/src/middleware/resolveLocale.tsx
Lines 38 to 47 in 88eabc7