Allow overriding how the locale is set#50
Open
aceisace wants to merge 1 commit intoAnbarryprojects:mainfrom
Open
Allow overriding how the locale is set#50aceisace wants to merge 1 commit intoAnbarryprojects:mainfrom
aceisace wants to merge 1 commit intoAnbarryprojects:mainfrom
Conversation
Allow providing locale_selector for more flexibility
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Analog to the flask-babel locale_selector, these small, but effective changes provide a much higher user-comfort as they are not restricted to only the integrated locale-selection method.
For instance, some users may want to save the locale of a logged-in-user which has a preferred locale in the request session or even as a cookie. Currently, it is not possible except to override the locale inside a view function like this:
Which is fairly un-pythonic and adds a lot of repetitive code when you have a lot of view functions. Instead of this, one can, optionally override this behaviour like this:
In
main.py:Which does the following;
if a user is logged in, take their preferred locale to set the babel locale. If no user was found (i.e. not logged in), use the accept-language header instead. Of course, the user is free to set the locale in whichever way they want, e.g. database queries, cookies, sessions etc.
On my end, I have done some testing with some fairly good results. I kindly ask to merge the changes into main after doing some tests on your end too and having these changes available in the next release in the near future.