DocsBuild

i18n

Nexy does not translate your application. It has no locale middleware, no trans helper and no locale files: an application picks the i18n library that suits it, as it picks an ORM.

The command line (nx) is translated; see the CLI.

In a handler

A handler reads what it needs from the request. This one answers in the language of the Accept-Language header:

src/routes/hello.py
from nexy.http import Header

MESSAGES = {"en": "Hello", "fr": "Bonjour"}


async def GET(accept_language: str = Header("en")):
    language = accept_language.split(",")[0].split("-")[0].lower()
    return {"message": MESSAGES.get(language, MESSAGES["en"])}

In a page

Use the library of your frontend for client-routed pages (for example i18next, vue-i18n or a Svelte store), and your Python library (gettext from the standard library, or Babel) for .nexy pages. Set <html lang> in the root layout.

Next steps

Edit on GitHub

Enter opens the result, Esc closes.