You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have looked for existing issues (including closed) about this
Feature Request
Add an extractor for the preferred language for a user
Motivation
It is not uncommon to want to return a response in the users language, especially when building user interfaces. While it is not hard to implement this on your own, it is nevertheless some boilerplate code that could be avoided.
Additionally, having a canonical way to get the request language would allow other extractors and middleware to rely on that extractor to get the user language, e.g. to return localized error responses.
Proposal
Add a UserLanguage extractor that reads from the request a list of preferred user languages and makes them available for the user. Standard sources of languages could include the Accept-Language header, a :lang path segment and a lang query parameter.
It may make sense to make the language sources configurable as well as allowing to add custom sources, such as reading the language from a cookie.
Alternatives
This could also be implemented in a crate outside of axum. The advantage being less maintenance overhead for axum and allow for more diversity in implementations. The main drawback would be that there is no canonical way for library crates to read the preferred user language. Relying on a specific third party crate may not be desirable in such cases.
Implementation
If this feature is something that would fit into the scope of axum, I would like to contribute this in a pull request.
The text was updated successfully, but these errors were encountered:
Feature Request
Add an extractor for the preferred language for a user
Motivation
It is not uncommon to want to return a response in the users language, especially when building user interfaces. While it is not hard to implement this on your own, it is nevertheless some boilerplate code that could be avoided.
Additionally, having a canonical way to get the request language would allow other extractors and middleware to rely on that extractor to get the user language, e.g. to return localized error responses.
Proposal
Add a
UserLanguage
extractor that reads from the request a list of preferred user languages and makes them available for the user. Standard sources of languages could include theAccept-Language
header, a:lang
path segment and alang
query parameter.It may make sense to make the language sources configurable as well as allowing to add custom sources, such as reading the language from a cookie.
Alternatives
This could also be implemented in a crate outside of axum. The advantage being less maintenance overhead for axum and allow for more diversity in implementations. The main drawback would be that there is no canonical way for library crates to read the preferred user language. Relying on a specific third party crate may not be desirable in such cases.
Implementation
If this feature is something that would fit into the scope of axum, I would like to contribute this in a pull request.
The text was updated successfully, but these errors were encountered: