flask-bookshelf icon indicating copy to clipboard operation
flask-bookshelf copied to clipboard

Handling exception from Babel when no local found in url - babel.core.UnknownLocaleError

Open vinodMS opened this issue 6 years ago • 0 comments

I didn't entirely follow the tutorial but did find the Localisation part very helpful, hence I implemented the solution in my own app.

One issue I encountered with this implementation is that if I had a url like this "www.example.com/path-that-does-not-exit/" then instead of seeing a 404, I got a babel error.

The error was due to the fact that the localeselector in babel got the 'path-that-does-not-exit' as locale. To fix this, I did the following here, https://github.com/damyanbogoev/flask-bookshelf/blob/c1549bcf4a4675432f103fe2fcdda8500178d240/bookshelf/init.py#L44-L48

    def get_locale():
        if g.get('lang_code') not in app.config['SUPPORTED_LANGUAGES'].keys():
            return app.config['BABEL_DEFAULT_LOCALE']
        else:
            return g.get('lang_code', app.config['BABEL_DEFAULT_LOCALE'])```



vinodMS avatar Dec 03 '18 21:12 vinodMS