Skip to content

twilio/voice: translate spoken call prompts via Twilio.VoiceLanguage - #4515

Open
Vr00mm wants to merge 1 commit into
target:masterfrom
Vr00mm:twilio-voice-translations
Open

twilio/voice: translate spoken call prompts via Twilio.VoiceLanguage#4515
Vr00mm wants to merge 1 commit into
target:masterfrom
Vr00mm:twilio-voice-translations

Conversation

@Vr00mm

@Vr00mm Vr00mm commented Jun 23, 2026

Copy link
Copy Markdown

Summary

Twilio voice calls currently speak hardcoded English regardless of the
configured Twilio.VoiceLanguage — that setting only drives Polly TTS
pronunciation, so e.g. fr-FR reads English text with a French accent.

This adds a small i18n layer (golang.org/x/text/message) so the spoken call
prompts are translated to the configured language, with English as the
fallback.

Behavior & compatibility

  • No behavior change without an explicit config change. With
    Twilio.VoiceLanguage empty (the default), output is byte-for-byte identical
    to today: English text, no language attribute.
  • A configured language that has a translation is spoken in that language;
    regional variants resolve to their base (fr-CAfr, pt-BR/pt-PT
    pt, cmn-CN/cmn-TWzh, all en-* → English).
  • A configured language with no translation falls back to English text
    spoken with an en-US voice (so text and voice stay consistent).
  • Purely additive: no schema/migration/DB change, instantly reversible by
    clearing the config value.

What's included

  • notification/twilio/voicemsg.go: catalog + language matcher; voicePrinter()
    resolves VoiceLanguage to a printer and the <Say> language attribute.
  • twiml.go / voice.go: literal prompts routed through the printer
    (Sayf/sayT); raw pre-built bodies stay untranslated to avoid %-format
    breakage from user content (e.g. an alert summary containing %).
  • 33 base-language translation files covering all 67 Twilio voice locales.
  • Config description + generated mapconfig.go updated.

Testing

  • golangci-lint (project version) clean on changed packages; go mod tidy
    and gofmt clean; go generate leaves the tree clean.
  • Unit tests: key-set completeness guard (every translation key must exist in
    the canonical list), fallback behavior, and multi-argument rendering across
    Latin and non-Latin scripts.
  • Behavioral smoke test (test/smoke/twiliovoicetranslated_test.go): with
    Twilio.VoiceLanguage=fr-FR, a voice alert and its acknowledgement are
    asserted to be spoken in French; existing English voice smoke tests still
    pass.

⚠️ Note for reviewers

The 33 translation files are machine-generated and would benefit from
review by native speakers before merge — the infrastructure and the English
default are the parts I'm confident about. Happy to split this into an
infrastructure-only PR (English + the i18n plumbing) and land languages
separately if that's preferred, or to open a tracking issue first per
CONTRIBUTING.

🤖 Generated with Claude Code

Twilio voice calls previously spoke hardcoded English regardless of the
configured Twilio.VoiceLanguage, which only drove TTS pronunciation. This
adds an i18n layer so the spoken prompts are translated to the configured
language, falling back to English (text + en-US voice) when no translation
is available.

- voicemsg.go: x/text message catalog + language matcher; voicePrinter()
  resolves VoiceLanguage to a printer and the <Say> language attribute.
- twiml.go/voice.go: route literal prompts through the printer (Sayf/sayT),
  while raw pre-built bodies stay untranslated (avoids %-format breakage).
- 33 base-language translation files covering all 67 Twilio voice locales
  (regional variants resolve to their base via the matcher).
- Guard tests: key-set completeness, fallback behaviour, multi-arg rendering.
- Smoke test: voice alert + ack spoken in French via Twilio.VoiceLanguage.
- Config description and generated mapconfig updated.

Translations are machine-generated and should be reviewed.

Signed-off-by: Rémi ZIOLKOWSKI <remi.ziolkowski@gmail.com>
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.

1 participant