Skip to content

fix: thread lang attribute through HTMLEmailTemplate#415

Open
smcmurtry wants to merge 1 commit into
mainfrom
fix/email-html-lang-attribute
Open

fix: thread lang attribute through HTMLEmailTemplate#415
smcmurtry wants to merge 1 commit into
mainfrom
fix/email-html-lang-attribute

Conversation

@smcmurtry

Copy link
Copy Markdown
Contributor

Summary | Résumé

Hardcoded <html lang="en"> in the email template caused screen readers to
announce French and bilingual emails using English phonemes (WCAG 3.1.1 fail).

  • Add optional lang kwarg to HTMLEmailTemplate and EmailPreviewTemplate
    (default "en"), threaded into email_template.jinja2 as
    <html lang="{{ lang }}">.
  • Callers can pass "fr", "fr-CA", or "und" (for bilingual content,
    where add_language_divs already emits inline <div lang="en-ca"> /
    <div lang="fr-ca">).
  • Tests cover the default, parametrized en/fr/fr-CA/en-CA/und values,
    a None fallback, and a bilingual lang="und" case.

Companion change in notification-api passes lang from get_html_email_options.

Related Issues | Cartes liées

cds-snc/notification-planning#3309

Test instructions | Instructions pour tester la modification

TBD

Release Instructions | Instructions pour le déploiement

None.

Reviewer checklist | Liste de vérification du réviseur

  • This PR does not break existing functionality.
  • This PR does not violate GCNotify's privacy policies.
  • This PR does not raise new security concerns. Refer to our GC Notify Risk Register document on our Google drive.
  • This PR does not significantly alter performance.
  • Additional required documentation resulting of these changes is covered (such as the README, setup instructions, a related ADR or the technical documentation).

⚠ If boxes cannot be checked off before merging the PR, they should be moved to the "Release Instructions" section with appropriate steps required to verify before release. For example, changes to celery code may require tests on staging to verify that performance has not been affected.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR addresses an accessibility issue where HTML emails were always rendered with a hardcoded <html lang="en">, causing screen readers to announce non-English email content incorrectly (WCAG 3.1.1).

Changes:

  • Adds an optional lang kwarg (defaulting to "en") to HTMLEmailTemplate and EmailPreviewTemplate.
  • Threads lang into the Jinja render context and updates email_template.jinja2 to use it in the <html lang="…"> attribute.
  • Adds tests covering default behavior, several explicit language tags (including "und"), and a bilingual content case.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
notifications_utils/template.py Adds lang parameter to email template classes and passes it into Jinja render context.
notifications_utils/jinja_templates/email/email_template.jinja2 Replaces hardcoded lang="en" with a templated lang value on the <html> tag.
tests/test_template_types.py Adds test coverage for default and parameterized lang behaviors and bilingual content rendering.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

{% if complete_html %}
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html lang="en">
<html lang="{{ lang | default('en', true) }}">
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