0

I've developed some custom modules for a client and implemented the $this->t() method to enable translations on static strings, like table headers. Is there a way to export only the translatable strings from my custom module into a .po file that I can handoff to someone for translation? I ideally want to export each modules translations separately so each module can be self contained.

1

You can give Translation template extractor a spin. While there is no official release for Drupal 8 available (yet), there already is a development version that seems to work for your use case when using the GUI:

https://www.drupal.org/project/potx/releases

Using composer, just install it like

composer require drupal/potx

After enabling the module, you'll have a new menu entry Configuration > Regional and language > User interface translation > Extract (/admin/config/regional/translate/extract)

There you can extract language and module specific translation templates from your custom module's PHP files.

Disclaimer: As mentioned, this module's Drupal 8 version has not been released yet. It may contain bugs and is not feature complete/en par with the 7.x version. Better use it in your development environment only.

  • Thanks for that I'll give that a try, using it only in a development environment is just fine for our use case. – Neil Nand Sep 16 '18 at 12:00
  • @NeilNand I actually tried it in one of our module playgrounds after posting my answer. In my tests it successfully extracted all strings from $this->t() and t(), and also from class annotations and log messages. The Drush command is not available though. But the back-end forms seem to work just fine. – Mario Steinitz Sep 16 '18 at 12:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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