Файлы перевода Symfony 4 в каталогах

Я хочу сохранить файлы перевода в каталоге, например:

      /translations/admin/messages.en.xlf
      /translations/admin/validation.en.xlf
      /translations/client/messages.en.xlf
     /translations/client/validation.en.xlf

И как использовать эти переводы в контроллерах и шаблонах Twig?

Стоит ли изучать PHP в 2026-2027 годах?
Стоит ли изучать PHP в 2026-2027 годах?
Привет всем, сегодня я хочу высказать свои соображения по поводу вопроса, который я уже много раз получал в своем сообществе: "Стоит ли изучать PHP в...
Symfony Station Communiqué - 7 июля 2023 г
Symfony Station Communiqué - 7 июля 2023 г
Это коммюнике первоначально появилось на Symfony Station .
Symfony Station Communiqué - 17 февраля 2023 г
Symfony Station Communiqué - 17 февраля 2023 г
Это коммюнике первоначально появилось на Symfony Station , вашем источнике передовых новостей Symfony, PHP и кибербезопасности.
Управление ответами api для исключений на Symfony с помощью KernelEvents
Управление ответами api для исключений на Symfony с помощью KernelEvents
Много раз при создании api нам нужно возвращать клиентам разные ответы в зависимости от возникшего исключения.
2
0
527
1

Ответы 1

Translation Resource/File Names and Locations

Symfony looks for message files (i.e. translations) in the following default locations:

  • the translations/ directory (at the root of the project);
  • the Resources/translations/ directory inside of any bundle.

The locations are listed here with the highest priority first. That is, you can override the translation messages of a bundle in any of the top two directories.

The override mechanism works at a key level: only the overridden keys need to be listed in a higher priority message file. When a key is not found in a message file, the translator will automatically fall back to the lower priority message files.

Источник: https://symfony.com/doc/4.2/translation.html#translation-resource-file-names-and-locations

И далее на той же странице/главе

You can add other directories with the paths option in the configuration:

config/packages/translation.yaml

framework:
    translator:
        paths:
            - '%kernel.project_dir%/translations/admin'
            - '%kernel.project_dir%/translations/client'

Вы можете использовать их как любые другие файлы перевода, помня механизм переопределения, указанный здесь выше.

Полная ссылка: https://symfony.com/doc/4.2/translation.html

Другие вопросы по теме