python-babel / flask-babel

i18n and l10n support for Flask based on Babel and pytz
https://python-babel.github.io/flask-babel/
Other
444 stars 159 forks source link

missing sep argument #136

Closed jonasrla closed 4 years ago

jonasrla commented 6 years ago

A missing sep='-' on this line raised

  File "/home/ubuntu/venv/local/lib/python2.7/site-packages/flask/app.py", line 1982, in wsgi_app
    response = self.full_dispatch_request()
  File "/home/ubuntu/venv/local/lib/python2.7/site-packages/flask/app.py", line 1614, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/home/ubuntu/venv/local/lib/python2.7/site-packages/flask/app.py", line 1517, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/home/ubuntu/venv/local/lib/python2.7/site-packages/flask/app.py", line 1612, in full_dispatch_request
    rv = self.dispatch_request()
  File "/home/ubuntu/venv/local/lib/python2.7/site-packages/flask/app.py", line 1598, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/home/ubuntu/venv/local/lib/python2.7/site-packages/superset/views/core.py", line 2614, in welcome
    'common': self.common_bootsrap_payload(),
  File "/home/ubuntu/venv/local/lib/python2.7/site-packages/superset/views/base.py", line 214, in common_bootsrap_payload
    locale = str(get_locale())
  File "/home/ubuntu/venv/local/lib/python2.7/site-packages/flask_babel/__init__.py", line 248, in get_locale
    locale = Locale.parse(rv)
  File "/home/ubuntu/venv/local/lib/python2.7/site-packages/babel/core.py", line 268, in parse
    parts = parse_locale(identifier, sep=sep)
  File "/home/ubuntu/venv/local/lib/python2.7/site-packages/babel/core.py", line 1094, in parse_locale
    raise ValueError('expected only letters, got %r' % lang)
ValueError: expected only letters, got u'pt-br'

https://github.com/python-babel/flask-babel/blob/9045eaaacf8d101ada140aa0347a7042ab965c15/flask_babel/__init__.py#L261

tvuotila commented 5 years ago

sep is a optional argument and it defaults to _ ref. So, it is not actually "missing".

u'pt-br' should be u'pt_br' or you can change your locale selector function to return a Locale object:

@babel.localeselector
def get_locale():
    return Locale.parse(u'pt-br', sep='-')

You probably have something smarter there, but that is the theory.