MCPcopy Create free account
hub / github.com/internetarchive/openlibrary / get_request_lang

Function get_request_lang

openlibrary/plugins/worksearch/code.py:211–220  ·  view source on GitHub ↗

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

()

Source from the content-addressed store, hash-verified

209
210@public
211def 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
223async def get_solr_works_async(work_keys: set[str], fields: Iterable[str] | None = None, editions=False) -> dict[str, web.storage]:

Callers

nothing calls this directly

Calls 1

getMethod · 0.45

Tested by

no test coverage detected