Skip to content

i18n(pt-BR): add Brazilian Portuguese AI and insight locale support - #1251

Merged
MBombeck merged 10 commits into
MBombeck:mainfrom
dareoon:feat/i18n-pt-br
Oct 23, 2026
Merged

MBombeck merged 10 commits into
MBombeck:mainfrom
dareoon:feat/i18n-pt-br

Conversation

@dareoon

@dareoon dareoon commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Adds Brazilian Portuguese (pt-BR) support to the medication-extraction and AI insight surfaces, following the AI-initial locale approach used by the Dutch locale PR (#1246).

This PR includes the complete messages/pt-BR.json UI translation bundle and focuses on the AI-facing per-locale tables and safety-relevant surfaces that must understand Brazilian Portuguese output.

I am a native Brazilian Portuguese speaker and reviewed the Portuguese wording and linguistic details in this change. I also used AI assistance to adapt the existing locale architecture and generate the initial Portuguese patterns/copy; the AI output was reviewed and refined for Brazilian Portuguese usage.

UI bundle

  • Adds messages/pt-BR.json with Brazilian Portuguese UI translations.

Medication extraction

  • NaturalLanguageExtractorProps.locale now uses the shared Locale type, so it accepts pt-BR natively.
  • MedicationWizardDialog passes its resolved reader locale directly, without a type cast.

Coach prose grounding

Adds Brazilian Portuguese population-norm framing patterns to coach-prose-grounding.ts, covering common forms such as:

  • “a faixa normal é…” / “faixa de referência”
  • “a maioria dos adultos…”
  • “os médicos recomendam…”
  • “entre X e Y”

Insight fallbacks

Adds Brazilian Portuguese no-AI-key fallback copy for the insight floors in no-key-fallbacks.ts.

Each floor opens with an honest statement that no assessment is available — for example, “Não há avaliação disponível para este cartão no momento.” — and continues with meaning-first guidance rather than clinical instructions.

Tone harness

Adds the pt-BR no-read sentinel to tone-harness.test.ts:

"pt-BR": /n[aã]o h[áa] (?:uma )?avalia[çc][aã]o/i,

Lab reference ranges

Adds a Brazilian Portuguese entry to RANGE_PROSE in parse-reference-range.ts, using folded, accent-free forms such as:

  • ate, menos de, abaixo de, maximo
  • a partir de, no minimo, acima de, maior que
  • valores de referencia, faixa de referencia

Coach read dates

Adds pt-BR expected date coverage to the Coach read strip test.

Test plan

  • pnpm exec tsc --noEmit
  • Targeted Vitest runs for:
    • src/components/insights/derived/__tests__/coach-read-strip-latest-date.test.tsx
    • src/lib/insights/eval/__tests__/tone-harness.test.ts
    • src/lib/insights/__tests__/no-key-fallbacks.test.ts
    • src/lib/labs/__tests__/parse-reference-range.test.ts
  • Existing outbound-screen safety tests continue to pass.

Reference

This follows the AI-initial locale model of #1246, adapted to the current pt-BR scope.

…t flows

Add pt-BR locale coverage across medication extraction, coach prose
grounding, no-key insight fallbacks, coach read dates, and lab reference
range parsing.

- Accept pt-BR natively in NaturalLanguageExtractorProps.
- Add Brazilian Portuguese population-norm framing patterns.
- Add pt-BR no-assessment fallback copy for all insight floors.
- Add pt-BR expected date coverage to the Coach read strip test.
- Add pt-BR lab range prose vocabulary.
- Keep existing locale behavior and safety-contract coverage unchanged.

@MBombeck MBombeck left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for this, @dareoon. The Portuguese reads really well, and the safety and disclaimer copy is careful. A few things keep it from landing yet:

  1. pt-BR isn't registered in src/lib/i18n/config.ts, so the bundle never loads and the Record<Locale, …> additions fail typecheck. The Dutch locale (#1246, commit c6f61fa) shows the full set of places a locale needs, including outbound-screen.ts (the medication safety patterns), the prompt language files, format-locale.ts, calendar-locale.ts and no-key-fallbacks.ts, which the description mentions but the diff doesn't contain.
  2. The bundle's shape drifts from en.json: about 420 stray top-level keys duplicated from settings, thresholds/gettingStarted/trendHints wrapped in arrays, and selfDescription missing. i18n-locale-integrity fails on this. After rebasing on main, 135 current keys are also missing.
  3. About 35 strings change placeholders (for example {when} for {date}, dropped {since}/{list}). Several settings.integrationCard.* strings look translated from the key name rather than the English text.
  4. telegram.helpBody documents tomado <nome>, but the bot only accepts taken <name>.
  5. In coach-prose-grounding.ts a match exempts a number from grounding. (?:entre|de)\s+…geralmente and singular médico … recomenda also match ordinary sentences about the user's own readings ("Sua pressão de 158/97 geralmente…"), so please narrow them and add a couple of negative cases.
  6. Small wording point: "dose" now stands for both the intake event and the amount. "tomada" for intake would remove the ambiguity.

Happy to help with any of it. If you prefer, I can push the wiring (registration, bundle shape, rebase on main) onto your branch and leave the wording to you. Just say which way you'd like it.

@MBombeck

Copy link
Copy Markdown
Owner

@dareoon, a quick heads-up so this doesn't sit around: I'd like Brazilian Portuguese to ship with the next release (1.45), so I'm going to push the wiring onto your branch over the next day or so, the way I offered above:

  • register pt-BR in the locale config and everything that hangs off it
  • reshape the bundle where it differs from the English structure, and fix the placeholders
  • fill the keys that were added since you started (marked for your review)
  • add the Portuguese coach safety patterns and narrow the two patterns that were too broad

Your commits stay as they are and the merge keeps them under your name. You'll be credited in the release notes. Your wording stays yours: anything I add is a first draft you're welcome to change, and if you'd rather do some of it yourself, say so here and I'll leave that part to you.

@MBombeck MBombeck mentioned this pull request Oct 22, 2026
@dareoon

dareoon commented Oct 22, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the heads-up and for offering to help complete the pt-BR wiring.

Please feel free to push the locale registration, bundle restructuring, missing-key updates, and coach safety patterns to the branch. I’ll review the Portuguese wording and linguistic details before the release, especially anything marked for my review.

As a native Brazilian Portuguese speaker, I’m happy to refine the copy and ensure the register and phrasing feel natural for Brazilian users.

@MBombeck
MBombeck merged commit 402daa2 into MBombeck:main Oct 23, 2026
18 of 25 checks passed
@MBombeck

Copy link
Copy Markdown
Owner

Brazilian Portuguese is live in v1.45.0, @dareoon. Thank you! Your commits are in under your name. On top of them I registered the locale everywhere, aligned the bundle with the English structure, filled the keys added since you started, used "tomada" for an intake and "dose" for the amount, added Brazil's crisis lines (CVV 188, SAMU 192), and added Portuguese coach safety patterns. One change you should know about: the PHQ-9, GAD-7, WHO-5 and sleep questionnaire items now show their original English wording in pt-BR, because a free translation invalidates the score; if a licensed validated Brazilian version is available, we can switch to it. Anything you'd word differently: the new Translating section in CONTRIBUTING links a browser editor that opens a pull request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants