Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when language is pt-BR because of '-'. Maybe adding sep param to get_locale? #243

Open
wesleyfralima opened this issue Nov 22, 2024 · 0 comments

Comments

@wesleyfralima
Copy link

Hey, thanks for the great job. I just started using flask-babel and it's been a blast!

I got an error, could you help me to solve it in a proper way?

My browser is set to Brazilian Portuguese and seems like it sends the info 'pt-BR'. But, sadly, the app crashes with the following error:

ValueError: expected only letters, got 'pt-br'

I read a little bit of the Babel's code and realised that get_locale calls Locale.parse. Locale.parse accepts a sep parameter, but seems it is not being used here (because get_locale itself does not pass it nor accepts a sep parameter).

I edited get_locale like the following and it worked:

Line 250 for me:
It is: def get_locale() -> Optional[Locale]: ...
I made: def get_locale(sep: str = None) -> Optional[Locale]: ...

Line 268 for me (still get_locale):
It is: locale = Locale.parse(rv)
I made: locale = Locale.parse(rv, sep=sep)

Is this a bug or is it me who can't use the code properly?

Thank you in advance!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant