The request's UI language, safe to call from templates rendered on either the legacy web.py server or the FastAPI server. The Templetor global `get_lang()` reads `web.ctx.lang` directly, which isn't populated by FastAPI — partials rendered there would AttributeError. Reading from the
()
| 209 | |
| 210 | @public |
| 211 | def get_request_lang() -> str: |
| 212 | """The request's UI language, safe to call from templates rendered on |
| 213 | either the legacy web.py server or the FastAPI server. The Templetor |
| 214 | global `get_lang()` reads `web.ctx.lang` directly, which isn't populated |
| 215 | by FastAPI — partials rendered there would AttributeError. Reading from |
| 216 | the unified `req_context` works on both. Falls back to 'en'.""" |
| 217 | try: |
| 218 | return req_context.get().lang or "en" |
| 219 | except LookupError: |
| 220 | return "en" |
| 221 | |
| 222 | |
| 223 | async def get_solr_works_async(work_keys: set[str], fields: Iterable[str] | None = None, editions=False) -> dict[str, web.storage]: |