Language of emails, pages and /docs¶
Use to choose the default language, store the user's preference, translate it yourself and set the language of the route docs.
Part of the Bundled auth flow (signup / activate / login / reset) recipe.
Email and page language (i18n)¶
Since v0.59.0, the emails and HTML pages the SDK ships out of the box
speak two languages: 🇧🇷 Brazilian Portuguese (pt-BR) — which is
the default — and 🇺🇸 US English (en-US). You don't need to
create any template for this to work. 🚀
The golden rule (memorize just this)¶
One flow, one language. The email and the page that email opens resolve the language the same way, in the same order — the first signal that exists wins:
| # | Signal | Where it comes from |
|---|---|---|
| 1 | ?lang= on the link |
The SDK stamps the language that email went out in onto its own link. |
| 2 | user.locale |
The preference you stored on the user row (the LocaleColumnMixin column). It is what the email resolves from — there is no link yet when it is built. |
| 3 | Accept-Language |
The browser of whoever clicked (pages only — an email has no browser). |
| 4 | AUTH_DEFAULT_LOCALE |
The last resort. |
Why does the link outrank the stored preference?
Because it records the language of that email. If the person changes their language in the app between the send and the click, the page still matches the message they are reading. Preferring the row would recreate the very split this order exists to close, only inverted.
Through v0.263.0 the two ends disagreed
The email read only AUTH_DEFAULT_LOCALE and the page negotiated
only Accept-Language. A signup with the pt-BR default and an
English browser sent the email in Portuguese and opened the page in
English — and no configuration fixed it, because setting
AUTH_DEFAULT_LOCALE=pt-BR was exactly the value the header
overrode. If you store the user's language, it now drives both ends.
Why does the link need to carry the language?
At signup the account was just born: there's no stored preference
yet. The only place the email's choice survives until the click is
the link itself — hence ?lang=. Turn it off with
AUTH_STAMP_LOCALE_IN_LINK=false if your front-end route rejects
unknown query parameters.
Step 1 — choose the default language¶
Just one environment variable. That's it:
Want everything in English? Switch to:
You don't need the exact case/format
The value is normalized for you. All of these become pt-BR:
pt-BR, PT-BR, pt_br, ptbr, pt. And all of these become
en-US: en-US, EN_us, enus, en. If you type something the
SDK doesn't know (like klingon), it falls back to the pt-BR
default instead of crashing.
Step 2 — (optional) store the user's preference¶
If your service lets people pick a language, store it on their row with
LocaleColumnMixin — and the SDK honors it on both ends, with no further
configuration:
from tempest_fastapi_sdk import BaseUserModel, LocaleColumnMixin
class UserModel(LocaleColumnMixin, BaseUserModel):
"""The BCP-47 `locale` column comes from the mixin."""
__tablename__ = "users"
Nothing breaks without the mixin: the SDK reads the attribute with
getattr, so a model without the column simply falls through to the next
signal.
user.locale = "pt-BR", en-US browser → email AND page in Portuguese
link says ?lang=pt-BR, row says en-US → page in Portuguese (matches the email)
neither, en-US browser → page in English
none of the above → AUTH_DEFAULT_LOCALE
Step 3 — (optional) translate/customize it yourself¶
The bundled templates live in per-language subfolders (pt-BR/,
en-US/). To change the text/look of just one language, drop a file
with the same name into the right subfolder of your template_dir
(e.g. template_dir/en-US/activation_success.html). The full lookup
order is in the "Override per language" tip further down, under
Mode E.
Bonus — short, readable expiry timestamp¶
The email used to show the raw, ugly expiry like this:
Now the SDK injects an expires_at_str variable into the template,
already formatted and without seconds, in the language's format:
| Language | How it looks |
|---|---|
pt-BR |
21/06/2026 23:25 (UTC) |
en-US |
2026-06-21 23:25 (UTC) |
In your custom templates, use {{ expires_at_str }} (short and pretty).
If you want to format it yourself, the raw datetime is still available
in {{ expires_at }}.
Recap
- One flow, one language: email and page resolve in the same
order — the link's
?lang=→user.locale→Accept-Language→AUTH_DEFAULT_LOCALE. - Stored the user's language? It drives both ends.
- The default is
pt-BR. Seten-USif you want English. AUTH_STAMP_LOCALE_IN_LINK=falseturns the?lang=stamp off.- Use
{{ expires_at_str }}to show the expiry without seconds.
Route documentation language (/docs) (v0.332.0+)¶
The email language does not change the /docs language. The summary and
description that make_auth_router writes into the OpenAPI document — what
shows up in Swagger, in ReDoc and in the comments of a generated client — are
English by default. To have them in Brazilian Portuguese, one environment
variable is enough:
The whole app, in one file, to check it:
from collections.abc import AsyncIterator
from fastapi import FastAPI
from sqlalchemy.ext.asyncio import AsyncSession
from tempest_fastapi_sdk import (
BaseUserModel,
UserAuthService,
make_auth_router,
make_user_token_model,
)
from tempest_fastapi_sdk.settings.mixins import AuthSettings, JWTSettings
class UserModel(BaseUserModel):
"""The product's account."""
__tablename__ = "users"
UserTokenModel = make_user_token_model(
user_table="users",
tablename="user_tokens",
class_name="UserTokenModel",
)
service: UserAuthService = UserAuthService(
user_model=UserModel,
token_model=UserTokenModel,
auth_settings=AuthSettings(),
jwt_settings=JWTSettings(),
email=None,
)
async def get_session() -> AsyncIterator[AsyncSession]:
"""Request-scoped database session (use your service's own)."""
raise NotImplementedError
yield
app: FastAPI = FastAPI()
app.include_router(make_auth_router(service, session_factory=get_session))
login: dict[str, str] = app.openapi()["paths"]["/auth/login"]["post"]
print(login["summary"])
$ python app.py
Log in with email + password → JWT pair
$ API_DOCS_LOCALE=pt-BR python app.py
Entrar com e-mail + senha → par JWT
Rather decide in code than in the environment? Every route factory accepts
docs_locale=, and the argument wins over the variable — in the example
above, make_auth_router(service, session_factory=get_session, docs_locale="pt-BR")
prints the Portuguese summary with or without API_DOCS_LOCALE.
Only the prose changes — the contract stays
Paths, operationId, parameter and field names, error codes and schema
titles are the same in both languages. A client generated from the
Portuguese document is the client generated from the English one; only
the comments differ.
Case does not matter
pt-BR, pt_br and pt become pt-BR; en-US, EN-us and en
become en-US. Unlike AUTH_DEFAULT_LOCALE, a language the catalog does
not carry (es-ES, pt-PT) does not fall back to the default: the
app refuses to start, naming API_DOCS_LOCALE. English documentation on
a deployment that asked for another language is the silent defect that
refusal prevents.
Which routers follow the variable today: every one the SDK builds that
appears in the schema — make_auth_router (and
UserAuthService.sse_router), make_sse_router, make_push_router,
make_web_push_router, make_health_router, make_logs_router,
make_tool_spec_router, make_app_error_router, make_session_router,
make_pdf_router, make_voice_router, make_chat_router,
make_genai_router, make_ai_chat_router, make_agent_router,
make_prediction_router, make_reviews_router, make_vision_router,
make_wallet_router, make_hostbridge_router, make_htmx_router,
make_web_app_router, make_zap_webhook_router and
make_revenuecat_webhook_router. A route kept out of the schema
(include_in_schema=False, like the admin panel, the auth pages and
/metrics) never shows in /docs, so it has no catalog entry.
The variable lives on ServerSettings.