10

I have been trying to import my custom interface translation during profile installation using a .po file that is put inside the translations folder in my custom module. After running:

drush locale-update && drush cr

All I get is community translations which are not accurate sometimes (no translation is imported from my .po file).

How can I import translations only from my local .po file?

Thank you.

2 Answers 2

12

To import your own translations you should use the interface translation properties on your module.

I'm using a folder translations in my modules where my language files like de.po or fr.po can be found. To load the translations you have to insert the following lines into your example_module.info.yml:

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

And to update your translations use this:

drush locale-check && drush locale-update && drush cr

EDIT: To update existent translations you should take a look at the settings page (/admin/config/regional/translate/settings):

enter image description here

You can try to use local translation files only or to overwrite any existing translation.

2
  • 4
    Thanks, this works but not exactly what I wanted. I prefer to override the provided translations (community translations) with my own translations. Jan 8, 2018 at 16:58
  • 1
    @AchrafJEDAY have you tested a different import behavior? I've updated my answer with some information about available interface translation settings.
    – RWAM
    Jan 9, 2018 at 7:41
2

Just import your own custom translations after importing the official ones:

drush locale:update -y
drush locale:import de ../translations/custom-translations.de.po --type=customized --override=all -y

you could do this in an update.sh after site install has run. Check the flags like --override=all

1
  • 1
    I understand that the most voted answer is the way to go for a contrib module, but for a custom, internal-use-only module this is certainly much simpler. Apr 8, 2022 at 13:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.