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
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 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! |
Beta Was this translation helpful? Give feedback.
resolveLocale
is currently not intended to be exported. You can receive thelocale
in 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=en
or/en/api/hello
).If you want to resolve the locale based on the
accept-language
header, 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