1

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 Answer 1

4

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.

3
  • 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, 2018 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. Sep 16, 2018 at 12:31
  • This was also what I was looking for. Really great options for extracting translations.
    – NicklasF
    Nov 12, 2022 at 16:50

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.