Automatically importing module-provided translations during installation I have a custom module whose interface strings have all been written in English. This module is not (and will not be) hosted on drupal.org, so I'd like to pack the translations for those texts directly with the module, and for those translations to be automatically imported by Drupal when the module is installed (provided the corresponding language is activated in Drupal, of course).

I've translated those texts in French and exported all those translations in a my_module-fr.po file. I've put this file in the "translations" folder inside my module folder.

As suggested in this answer, I used the interface translation properties in the my_module.info.yml, as follows:

'interface translation project': my_module
'interface translation server pattern': modules/custom/my_module/translations/my_module-%language.po


But when I install my module from scratch, those translations are not automatically imported.

In admin/reports/translations, it says "Missing translations for one project - my_module (1). File not found at modules/custom/my_module/translations/my_module-fr.po".

I've tried several variations for the interface translation server pattern value in the info.yml file, among them:


path relative to the module folder (translations/my_module-%language.po) instead of the Drupal folder
full path to the drupal install folder (since I'm on localhost and Drupal is in a subfolder) (_tests/drupal8/www/modules/custom/my_module/translations/my_module-%language.po)


But I always get the same "file not found" message in the admin report page, and nothing is imported.

What am I missing?



Side question: in the YML declaration above, is it allowed to use a path pattern relative to the module folder, as listed above? This would make a lot more sense to me, as I cannot predict whether the people will install my module in the "modules/contrib" folder, or in another subfolder, or directly in the "modules" folder (and if they install it from the Drupal UI, they may not even know it themselves).
Per the documentation:
https://api.drupal.org/api/drupal/core%21modules%21locale%21locale.api.php/group/interface_translation_properties/8.4.x


  Streamwrappers can be used in the server pattern definition. The interface translations directory (Configuration > Media > File system) can be addressed using the "translations://" streamwrapper. But also other streamwrappers can be used.


There are several examples given for valid server pattern definitions using different stream wrappers.

EDIT

I see what you mean about not wanting to use the translations:// stream wrapper.

Have you tried using the pattern definition exactly as given in the answer you cited?

modules/custom/example_module/translations/%language.po

If you do that, you should also take the name of your module out and just name the file fr.po.

Then make sure that you update translations with Drush:

drush locale-check &amp;&amp; drush locale-update &amp;&amp; drush cr

If that doesn't work, hopefully someone else can help, because I'm stumped.