def current_locale(self) -> Locale: """Get current locale.""" locale = current_locale.get() if locale is None: self.current_locale = self.cfg.default_locale locale = current_locale.get() return locale
async def my_app(scope, receive, send): """Get a current locale.""" locale = current_locale.get().language.encode() hello_world = gettext('Hello World!').encode() await send({"type": "http.response.start", "status": 200}) await send({ "type": "http.response.body", "body": b"Current locale is %s\n" % locale, "more_body": True }) await send({"type": "http.response.body", "body": hello_world})
async def app(scope, receive, send): locale = current_locale.get() response = ResponseHTML( "<link rel='stylesheet' href='https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css'>" # noqa "<div class='container p-3'>" # Translate text f"<h2>{ 'ASGI-Babel Example (only en/fr supported)' }</h2>" "<h3>" + gettext('Hello World!') + "</h3>" "<h3>" + gettext('Locale information:') + "</h3>" "<ul>" f"<li>Display name: {locale.display_name}</li>" f"<li>Language code: {locale.language}</li>" f"<li>Decimal symbols: {locale.number_symbols['decimal'] }</li>" f"<li>First week day: {locale.first_week_day }</li>" f"<li>Monday names: {locale.days['format']['wide'][1] }</li>" f"<li>See babel docs for more</li>" "</ul>" "</div>" ) await response(scope, receive, send)
async def locale(request): return current_locale.get()