Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: email i18n #2023

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open

feat: email i18n #2023

wants to merge 5 commits into from

Conversation

lfleischmann
Copy link
Member

@lfleischmann lfleischmann commented Jan 9, 2025

Description

Adds internationalization of emails.

Implementation

  • The API now accepts a custom X-Language header on all Flow API endpoints.
  • Hanko Elements now transmits the value of the lang attribute of the components as the value for the X-Language header.
  • Changing a component's lang attribute updates the language of underlying Hanko client used through a new setter function (only the underlying Flow client is updated since other clients are slated for removal in the near future)
  • For relying parties/clients that do not use Hanko Elements: the language can also be provided as an argument to the central Hanko client of the frontend SDK.
  • Providing a hyphenated version of language code (+ country code) is now required in order for emails to be correctly translated too - this currently only concerns Brazilian Portuguese. The hyphen is removed when passing the language to the frontend's translation context, so that frontend translations can still be resolved (the keys do not allow hyphens). "Old"-style arguments (i.e. "ptBR") still work but emails will not be translated - up for discussion whether this constitutes a breaking change.
  • The webhook token payload for the email.send event now also contains the transmitted X-Language header value in the language claim (the accept_language claim/field of the underlying backend struct has been marked as deprecated in order to be more consistent with the new headers' name and to prevent possible confusion regarding the syntax/semantics of the claim - its value does behave like a HTTP Accept-Language header, it is only one value instead of a list with quality values/weights).

How to test

Startup backend + Mailslurper (or equivalent, configure as required). Build Hanko Elements/Hanko Frontend SDK and use the example "application" in /frontend/elements/src/example.html to toggle languages and request emails. Alternatively, start up one of the examples in /frontend/examples and supply different values for the components' lang attribute.

Increase amount of expected setRequestHeader calls because the
client now also sets the "X-Language" header.
@lfleischmann lfleischmann changed the title Feat email i18n feat: email i18n Jan 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: 🆕 New
Development

Successfully merging this pull request may close these issues.

1 participant