I need to get the browser language with Python Flask. I have tried to use:
request.headers.get('languages')
This however returns None
.
I tried whoer.net and it returned it-IT
for my browser language. How can I detect the browser language with Python Flask ?
Check out Werkzeug's LanguageAccept data structure, or just try something like this to get a best match:
supported_languages = ["en", "nl", "it"]
lang = request.accept_languages.best_match(supported_languages)
If you need more than that, then check out Flask-Babel.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With