amannn / next-intl

🌐 Internationalization (i18n) for Next.js
https://next-intl-docs.vercel.app
MIT License
2.58k stars 236 forks source link

Can we export a method to get the current locale as a string? #1457

Closed ozooxo closed 3 weeks ago

ozooxo commented 3 weeks ago

Is your feature request related to a problem? Please describe.

In some cases, I need to know the current locale value as a string. For example, I may need to pass it to a redirect({href: '...', locale: '...'}). It will be the best if this can be exported, and be callable from the library.

Describe the solution you'd like

I think export the useLocale() function https://github.com/amannn/next-intl/blob/5d60cdf3d0806a900216c76768111d172065ae72/packages/next-intl/src/react-client/useLocale.tsx#L6 or https://github.com/amannn/next-intl/blob/5d60cdf3d0806a900216c76768111d172065ae72/packages/next-intl/src/server/react-server/getRequestConfig.tsx#L14 for external use will work.

Describe alternatives you've considered

I can potentially:

amannn commented 3 weeks ago

This is already exported, please see here: useLocale