-
Notifications
You must be signed in to change notification settings - Fork 17
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
Language code mismatch causes failure to load translations, because separator in language code is '-' #24
Comments
Hello dude |
@ruiheng is right, this needs to be resolved or language detection will be kind of useless otherwise. I have fixed it and sent a Pull request #26 with a performant solution. Please @Legopapurida could you take few minutes to take a look and create the new release v0.0.9? The old v0.0.8 crashes whenever the requested language doesn't exist instead of using a default language. There is no point of having a broken release when we already have that fixed. Thanks, |
Thanks for merging the PR @Legopapurida ! Any chance to update the pip package to v0.0.9? |
Before updating the pip package to v0.0.9 I think you should also merge this Pull request #29 @Legopapurida ! It adds a huge improvement, I am using his branch in production and works great, but would be better for everyone having it released as an official PIP version. |
Hello everybody I will check the issues and pull requests as soon as possible and this will be released to new version (v1) |
the problem has been fixed by @AnderUstarroz and a million thanks to @AnderUstarroz |
Thanks all |
Event using the lastest commit '47018bc', My FastAPI app still does not work.
My browser sends the following
Accept-Languages
header:After processing by the fastapi-babel middleware, the preferred languages list contains codes like "zh-CN". However, the language subdirectories under the
lang
directory use underscores instead of dashes, e.g. "zh_CN".This causes a failure to locate the proper MO files for translations.
The
lang
directory structure is created by the fastapi-babel command line tool, which only accepts language codes with underscores like "zh_CN". Codes with dashes like "zh-CN" cause errors in thebabel
library, which uses underscores by default.My suggested fix is to simply replace dashes with underscores in the language codes, as shown in this patch:
The text was updated successfully, but these errors were encountered: