Closed ruiheng closed 4 months ago
Hello dude we have tried this method, thanks for announcing us due this problem, we will be glad if you can fix this code and contribute to the project.
@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 https://github.com/Anbarryprojects/fastapi-babel/pull/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? Then you could close the following issues:
Before updating the pip package to v0.0.9 I think you should also merge this Pull request https://github.com/Anbarryprojects/fastapi-babel/pull/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 apologize for the long gap in checking the issues and pull requests. I was so busy in these days.
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: