I am rather new to Drupal module development and am facing a problem with automatically updating translations of a .po file using the update.php procedure.
There is an existing custom module currently used with translations.
The custom's module info.yml implements the following (translation settings):
'interface translation project': custom_module
'interface translation server pattern': modules/custom/custom_module/translations/%language.po
The .po file is located in the designated directory.
I had to add some new t() in a login form as below
class EntryGlobalLogin extends FormEntryAbstract {
...
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
...
// legend explaining that fields containing * are required
$form['legend'] = [
'#type' => 'html_tag',
'#tag' => 'p',
'#value' => $this->t('* This field is required.'),
'#attributes' => ['class' => ['form-legend']],
];
...
return $form;
}
}
When I manually import the new .po file via
[weburl]/de/admin/config/regional/translate/import
the aforementioned value is correctly translated, so there is no error with the .po file.
However, I cannot find a way to automatically update the translations of the updated .po file using the update.php procedure.
As found somewhere else I added the following to the HOOK_update_N hook of the .module file
function custom_module_update_8049() {
...
// add new translations via de.po update file
Drupal::moduleHandler()->loadInclude('locale', 'compare.inc');
locale_translation_check_projects_local(['custom_module']);
}
The update.php procedure runs without an error and the referred update is being mentioned in pending updates and finally executed without updating the desired translation.
Therefore my question is: How do I programmatically update the translations of a changed .po file (within an HOOK_update_N hook) ?
Is this possible, or is this change only possible manually running some drush commands or importing the .po file in the admin sites?
Thanks in advance.
Drupal Version 8.9.17
Best regards, Patrick