Symfony

Translations & i18n

Translation service, domains, locales, YAML/XLIFF files, ICU MessageFormat, pluralization

16 питань зі співбесід·
Mid-Level
1

Which Symfony service should be used to translate strings in a controller?

Відповідь

The TranslatorInterface service is the main service for handling translations in Symfony. It can be injected into controllers, services, or other classes via autowiring. This service loads translation files from the translations/ folder and returns the translation corresponding to the active locale.

2

In which folder are translation files stored by default in Symfony?

Відповідь

The translations/ folder at the project root is the default location for translation files in Symfony. Files follow the naming convention domain.locale.format (e.g., messages.fr.yaml). Bundles can also provide their own translations in Resources/translations/.

3

What is the correct naming convention for a YAML translation file for the 'messages' domain in French?

Відповідь

The Symfony naming convention for translation files is domain.locale.format. For the messages domain in French with YAML format, the file must be named messages.fr.yaml. The default domain is 'messages', but custom domains like validators.fr.yaml or security.fr.yaml can be created.

4

How to translate text with dynamic parameters using the Translator?

5

What is the role of a translation domain in Symfony?

+13 питань зі співбесід

Опануй Symfony для наступної співбесіди

Отримай доступ до всіх питань, flashcards, технічних тестів, вправ code review та симуляторів співбесід.

Почни безкоштовно