2

I have my translation files in app/Resources/translations. Now I wanted to manage them better and create some subfolders, but then it seems that the file is not loaded:

{% trans_default_domain 'sub/messages' %} 
{{ 'message'|trans }} #does not work

I also called php bin/console cache:clear after reordering

Asara
  • 2,791
  • 3
  • 26
  • 55

3 Answers3

2

I've tested this and here are my conclusions:

If you have :

translation:
| - sub :
|       | - messages.en.xlf (with message = 'message in sub')
| - messages.en.xlf (with message = 'message in translation')

{{ 'message'|trans }} // echo 'message in sub'

{% trans_default_domain 'messages' %}
{{ 'message'|trans }} // echo 'message in sub'

{% trans_default_domain 'sub/messages' %}
{{ 'message'|trans }} // echo 'message' -> don't translate (it's your problem)

To resolve your problem you can rename the files in sub directory

translation:
| - sub :
|       | - submessages.en.xlf (with message = 'message in sub')
| - messages.en.xlf (with message = 'message in translation')

{% trans_default_domain 'submessages' %}
{{ 'message'|trans }} // echo 'message in sub'
doydoy44
  • 5,720
  • 4
  • 29
  • 45
  • Correct, now i am remembering, also if you set subfolders as locales (en, nl, de, etc.) symfony will also recognize this – Nickolaus Sep 02 '16 at 19:38
1

I'm not sure about subfolders for storing translation files. Translation Resource Symfony documentation part says nothing about subfolders.

However, you can organize your translation messages into groups (domains). In this case each message file must be named according to the following path: domain.locale.loader, so you can have e.g. the file admin.en.yml for your admin group or user.en.yml for your user group.

Lukas Hajdu
  • 806
  • 7
  • 18
  • sorry, that does not help. Of course I can create different files (domains), but then all domains/files are in one folder – Asara Jul 01 '16 at 11:06
1

I think you there is no other way than writing a Custom Loader in order to do this: https://symfony.com/doc/current/components/translation/custom_formats.html#creating-a-custom-loader

Nickolaus
  • 4,785
  • 4
  • 38
  • 60