itk-dev / drupal_translation_extractor
drupal_translation_extractor
Package info
github.com/itk-dev/drupal_translation_extractor
Type:drupal-module
pkg:composer/itk-dev/drupal_translation_extractor
Requires
- php: ^8.3
- drupal/core: ^10 || ^11
- symfony/translation: ^6 || ^7 || ^8
- symfony/twig-bridge: ^6 || ^7 || ^8
Requires (Dev)
- ergebnis/composer-normalize: ^2.48
- friendsofphp/php-cs-fixer: ^3.91
- phpstan/phpstan: ^2.1
- phpunit/phpunit: ^12.5
- rector/rector: ^2.3
- vincentlanglet/twig-cs-fixer: ^3.11
Suggests
None
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-09-21 09:32:28 UTC
README
Extracts translations from PHP files, Twig templates and JavaScripts files.
This Drupal translation extractor stands on the shoulders of giants:
- https://www.drupal.org/project/potx
- https://www.drupal.org/project/translation_extractor
- https://symfony.com/doc/current/translation.html#extracting-translation-contents-and-updating-catalogs-automatically
Installation
composer require --dev itk-dev/drupal_translation_extractor:^1.0 drush pm:install drupal_translation_extractor
Use
The main entrypoint is the drupal_translation_extractor:translation:extract Drush command. This command is basically
Symfony's translation:extract console
command
with a few changes and additions outlined below.
Changes from the Symfony command
The bundle argument doesn't make sense and has been removed.
The --clean option is a NOP since it doesn't make sense for our use. We
always write only existing translations.
A new argument has been added:
source The source path to extract translations from. For convenience, module:«name» and theme:«name» can be used
in the value and will be expanded to the full path to the module and/or theme respectively, i.e.
module:my_custom_module will be expanded to web/modules/custom/my_custom_module, say.
A new option has been added:
--output The output path. The value can use these placeholders:
| Name | Value |
|---|---|
%locale |
The locale being extracted |
%module |
The module name if specified using module:… in source |
%source_dir |
The directory of %source |
%source |
The expanded value of source |
%theme |
The theme name if specified using theme:… in source |
%language1 |
Alias for %locale |
%project 1 |
Alias for either %module or %theme (whichever is set) |
Example
Running
drush drupal_translation_extractor:translation:extract da --dump-messages --force module:my_module --output=%source/translation/%module.%locale.po
will find translations in all PHP, Twig and JavaScript files in the web/modules/custom/my_module directory and write
the result to web/modules/custom/my_module/translation/my_module.da.po.
Run
drush drupal_translation_extractor:translation:extract --help
to see all options and arguments.
Note
Much of the code in this module is stolen frombased on Symfony components and therefore we do not use Drupal coding
standards.
Footnotes
-
Matching placeholders used by the Locale module (cf. locale.api.php). ↩ ↩2