Skip to content

feat: Allow to render Twig templates with a specific locale#265

Open
Jean-Beru wants to merge 2 commits into
sensiolabs:1.xfrom
Jean-Beru:feat/locale-aware-rendering
Open

feat: Allow to render Twig templates with a specific locale#265
Jean-Beru wants to merge 2 commits into
sensiolabs:1.xfrom
Jean-Beru:feat/locale-aware-rendering

Conversation

@Jean-Beru
Copy link
Copy Markdown
Contributor

@Jean-Beru Jean-Beru commented Apr 30, 2026

Summary

  • Add a locale(string) method on builders using Twig templates (HtmlPdfBuilder, MarkdownPdfBuilder, UrlPdfBuilder and their Screenshot counterparts) to render content, header and footer templates with the given locale via Symfony's LocaleSwitcher.
  • Behavior is unchanged when locale() is not called: symfony/translation remains an optional dependency. A clear LogicException is thrown if locale() is called without it installed.
  • Exposed as a YAML configuration node via WithConfigurationNode so it can be set globally per builder.

Credits

Original idea by @StevenRenaux.

Add a `locale(string)` method on builders using Twig (HtmlPdfBuilder,
MarkdownPdfBuilder and their Screenshot counterparts) to render content,
header and footer templates with the given locale via Symfony's
LocaleSwitcher. The current application locale is restored after each
rendered template.

The `symfony/translation` dependency is optional: when no locale is
set, behavior is unchanged. When `locale()` is called without
`symfony/translation` installed, a clear LogicException is thrown.

The locale is also exposed as a YAML configuration node via
WithConfigurationNode so it can be set globally per builder.

Original idea by @StevenRenaux.

Co-authored-by: Steven Renaux <59167761+StevenRenaux@users.noreply.github.com>
Assisted-by: Claude:claude-opus-4-7
@Jean-Beru Jean-Beru force-pushed the feat/locale-aware-rendering branch from 801afaf to edd2f4b Compare April 30, 2026 13:01
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