At the moment, all interactions with the "Translation Extractor" Module like exporting and importing PO files must be done in the Drupal admin interface. This could be time consuming.
In order to save some clicks, I implemented drush commands for module PO export and import.
Additionally these commands handeling importing and exporting the base PO file using the "--base-po-folder" option.
The documenation shown below is available via drush help trex-export
and drush help trex-import
1. translation-extractor:export (alias trex-export)
/**
* Extract translations from the specified module's source code, translate those strings to
* the given language, and finally store the module PO file to the file system.
*
* Following a simple and full command example:
*
* # Simple command example:
*
* drush trex-export my-module de
*
* This command extracts all strings from the module "my-module",
* searches for existing "de" translations in the database, and creates the
* PO translation file to "/your-site/web/modules/custom/my-module/translations/my-module.de.po"
*
* Set different module PO folder (optional):
*
* You can use the "--module-po-folder=" option to specify a different
* folder for the generated module translation file. The filename is automatically generated based
* on the provided module and language parameters. (e.g. "my-module.de.po")
*
* Initially import base PO file (optional):
*
* Use the "--base-po-folder=" option to initially import the base
* translation file for the language code from the given folder. If you set "de" as language code, it will
* load the "de.po" from this folder. This will ensure an up-to-date translation
* database in your Drupal site before extracting, translating, and generating the new module translation file.
* If not set, the base PO file is not imported.
*
* Use the "--show" flag to output the generated PO file to the console.
*
* # Full command example:
*
* drush trex-export my-module de \
* --base-po-folder=/my-site/config \
* --module-po-folder=/my-site/web/modules/custom/my-module/translations
*
* The output should be:
*
* Start exporting "de" translations for module "my-module"
* Base PO file "/my-site/config/de.po" imported into database.
* Module PO file "/my-site/web/modules/custom/my-module/translations/my-module.de.po" exported to file system.
*/
2. translation-extractor:import (alias trex-import)
/**
* Import all translation from the module PO file to the database. Optionally, the base PO file can be exported
* to the filesystem after the module was imported using the "--base-po-folder" option.
*
* Following a simple and full command example:
*
* # Simple command example:
*
* drush trex-import my-module de
*
* This will import translations from your module PO file
* "./path-to/modules/custom/my-module/translations/my-module.de.po" into the database.
*
* Set different module PO folder (optional):
*
* You can use the "--module-po-folder=" option to specify a different
* folder to load the module PO file. The filename is automatically generated based
* on the provided module and language parameters. (e.g. "my-module.de.po")
*
* Export base PO file (optional):
*
* Use the "--base-po-folder=" to set the folder which contains the base PO file.
* This file is exported to the filesystem after importing the module PO file.
* If not set, the base PO file is not exported.
*
* # Full command example:
*
* drush trex-import my-module de \
* --module-po-folder=/my-site/web/modules/custom/my-module/translations \
* --base-po-folder=/my-site/config
*
* The output should be:
*
* Start importing "de" translations for module "my-module"
* Module PO file "/my-site/web/modules/custom/my-module/translations/my-module.de.po" imported into database.
* Base PO file "/my-site/config/de.po" exported to file system. (Contains all translations from database)
*/
Active
2.0
Code