Background and attribution
Red Cards are small, wallet-sized cards that state a person's constitutional rights, most often the right to remain silent and the right to refuse consent to a search.
They are often used during encounters with law enforcement to:
- communicate rights without escalating a situation
- overcome language barriers
- provide clarity under stress
The cards, and the translations this project uses, come from the Immigrant Legal Resource Center (ILRC), who created the original red cards. The original materials are at ilrc.org/red-cards (opens in a new tab). This project is not affiliated with the ILRC and is not legal advice.
What I set out to add was distribution: a way to get a card onto a phone or onto paper in any of 56 languages, without an account, a connection, or a working printer being required at the moment it matters.
What I built
Two repositories that work together, and work apart.
- A FastAPI service that renders print-ready PDFs in 56 languages across 20 Unicode scripts, from Latin and Cyrillic to CJK, Arabic, Hebrew, Thai, Khmer, Myanmar and Ethiopic. It also serves the card text and the print options as JSON.
- A React app, live at redcard.pages.dev (opens in a new tab), that shows a card full-screen in the visitor's language. The card text is bundled into the app, so it works with no server and no connection. The API is only needed for PDF downloads.
Every card has a translated front and a fixed English back explaining Fourth and Fifth Amendment rights — the side you show to an officer.
The frontend, in priority order
The design goals were ranked, and the ranking decided the arguments.
1. A card in one tap. Home opens with the visitor's remembered or browser language as one large button, with every other language below it listed by its own name — Español, العربية, ភាសាខ្មែរ. Browser language matching handles region and script fallbacks and aliases (es-MX→es, zh-Hant-HK→zh-tw, fa-AF→prs, fil→tl). Search ignores accents, so espanol finds Español.
2. It works with no server and no connection. The dataset is bundled and precached by a service worker, and every language's card page is prerendered to static HTML at build time. At runtime the app asks the backend only which languages have PDF fonts and what the print layouts are — both in the background, with timeouts and retries. If those calls fail, cards and browser printing still work, and a non-blocking notice explains that only PDF download is unavailable.
3. It's usable in the moment. The full-screen card has a large Show to officer toggle to the English side. It keeps the screen awake, offers bigger text, saves the card as an image, shares a link, and reads the card aloud where the device has a voice for the language.
4. It doesn't track anyone. No analytics, no third-party requests — fonts are self-hosted — and a strict Content-Security-Policy shipped as a build-time meta tag so it applies on any host. The chosen language lives on the device only, and the home page can forget it.
A print workspace at /redcards handles preview, browser fold-sheet printing and backend PDFs. A translation builder at /builder gives translators a guided form with live preview instead of hand-edited JSON; it's lazy-loaded, so people who just want a card never download it.
API design
The endpoints keep content retrieval separate from PDF generation, and separate liveness from readiness — fonts take a second or two to register at startup, and a load balancer shouldn't send traffic before then.
| Endpoint | Purpose |
|---|---|
GET /api/health | Liveness. 200 while the process is up. |
GET /api/ready | Readiness. 503 until fonts are registered, then 200. |
GET /api/config | Valid layouts, render modes, page size — so the frontend hardcodes no backend constraints. |
GET /api/languages | Every language with native, rtl, official, fontSupported and source attribution. |
GET /api/card/{code} | Structured card content for one language. |
GET /api/render/{code} | A PDF, built in memory, streamed back. |
Two render modes: grid puts 4, 6, 8 or 12 cards on a page, fronts on page 1 and backs on page 2 for duplex printing; fold puts 4, 5 or 6 rows on a single page, each row front | back, to fold down the middle.
Errors always have the same shape, {detail, code}, with codes the frontend can branch on: language_not_found, invalid_request, font_not_available (which also names the script and language), rate_limited with a Retry-After header, not_ready, render_timeout. Internal failures are logged, never returned. JSON responses cache for five minutes and PDFs for an hour; rendered PDFs are also held in memory, and a cache hit doesn't spend a request from the rate limit.
Settings are CARD_* environment variables. In production the service refuses to start if the CORS origins only allow localhost or *.
Rendering
A render is four steps, and the interesting part is that the text is planned once per sheet rather than once per card.
- Pick the font. The language code maps to a script, and the script to a Noto font.
- Plan the sheet. Wrapping is attempted at a range of text scales, and a binary search finds the largest scale that still fits the card. Verbose languages shrink, terse ones grow, and both sides of the card get the same treatment.
- Shape and wrap. Arabic-script languages (Arabic, Farsi, Dari, Pashto, Urdu), Devanagari, Bengali, Tamil, Gurmukhi, Thai, Lao, Khmer and Myanmar are shaped with HarfBuzz, and their line widths are measured from the shaped glyphs rather than from character counts. Right-to-left text is wrapped in logical order, then each line's runs are laid out right to left. Lines break at spaces, or between characters for CJK, and never inside a letter cluster.
- Draw the planned lines into every card position on the sheet.
Font coverage is checked, not assumed. The test suite renders every language and fails if a card uses a glyph its font lacks, and a validation script checks the dataset for schema, glyph coverage and corruption heuristics. fontSupported is computed per language and surfaced in the API, so the frontend can disable PDF download for a script the backend can't draw — browser printing still covers it.
Operational notes
Three things about this service matter more than the code:
- It runs behind a proxy with forwarded headers. Without them every client looks like the proxy and shares one rate-limit bucket.
- One worker per container. Fonts are about 150 MB resident, and the PDF cache and rate limiter are per-process. Scale by adding containers. Output is deterministic, so a CDN absorbs repeat downloads.
- The container healthcheck points at
/api/ready, not/api/health.
What's honest about it
Three translations need native-speaker review. Khmer, Tamil and Pashto were reconstructed from ILRC artwork that is itself badly typeset — the Khmer card is cut off at the end, the Pashto card drops two words. Rather than ship them silently, they're marked unverified in the data with a review note, the API returns that note, and the validation script lists them. Arabic, Farsi, Dari and Marshallese were corrected against clean artwork.
The same applies to the frontend's interface strings: the card-view controls are translated for twelve languages, drafted without native review and flagged as needing it. Outside the card view the interface is English only.
The font files are large. About 60 MB, 58 MB of it CJK fonts used by five languages. Subsetting them to the characters the cards actually use would cut that to a few megabytes.
Builder translations aren't submitted back to the API yet, and browser print fidelity still depends on the print dialog.
Links
- Live app: redcard.pages.dev (opens in a new tab)
- Backend API: github.com/pierre-projects/redcardapi (opens in a new tab)
- Frontend app: github.com/pierre-projects/redcardapi-frontend (opens in a new tab)
Both are MIT licensed. The translations are the ILRC's.








