Lazy gettext with FastAPI response_model
Hi, I'm facing some errors related to lazy gettext with FastAPI response_model, It seem like lazytext not be evaluated correctly. ` error_message = _("Some error message")
@app.get("/multilingual/template", response_class=JSONResponse) async def multilingual_template(request: Request): raise HTTPException(status_code=400, detail=error_message)
@app.get("/multilingual/template", response_class=JSONResponse) async def multilingual_template(request: Request): return {"data": error_message} ` then both 2 endpoints raises "Lazytext is not Jsonable".
As I know, lazytext be evaluated (translated to string) when it needed, But how to force to do the translation in the view itself.
@phamvanvuhb1999
I will fix this issue by forcing the lazy gettext object to be evaluated as a string (using str()) before returning it in FastAPI responses or exceptions.