Technical Mid Level

How does internationalisation work in Symfony? Explain how translations are defined, loaded, and used in controllers, services, and Twig templates.

Quick Tip

I define translation keys in YAML files by domain. Twig templates use the trans filter. I run translation:extract to find any untranslated keys. The locale comes from the URL prefix and falls back to the default locale in config.

What good answers include

Translations live in translations/ as YAML, XLIFF, or PHP files, named by domain and locale (messages.en.yaml, validators.fr.yaml). In Twig: use the trans filter or trans block. In PHP: inject TranslatorInterface and call trans(). The locale is set per request — typically from the URL, session, or Accept-Language header. ICU message format handles pluralisation and complex rules. Strong candidates discuss: translation domains for organising large projects, the translation:extract command for finding missing keys, fallback locales, and how to handle locale switching in routes with _locale parameter.

What interviewers are looking for

Tests readiness for international projects. Candidates who hardcode strings in templates or use ad-hoc translation solutions will struggle when the project needs a second language. Those who understand domains and ICU format handle complex translation requirements cleanly.

← All Symfony questions