-2

I want to save translation files in directory, for example:

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

And how to use these translations in Controllers and Twig templates ?

pietrach
  • 47
  • 1
  • 8

1 Answers1

3

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.

Source: https://symfony.com/doc/4.2/translation.html#translation-resource-file-names-and-locations

And later on the same page / chapter

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'

You can use those as any other translation files, remembering the overriding mechanism quoted here above

Full reference: https://symfony.com/doc/4.2/translation.html

β.εηοιτ.βε
  • 33,893
  • 13
  • 69
  • 83