Skip to content

Commit

Permalink
Merge pull request #766 from City-of-Helsinki/UHF-9361
Browse files Browse the repository at this point in the history
UHF-9361: Add translation context to email field in social media module
  • Loading branch information
hyrsky authored May 27, 2024
2 parents 9ebb3f1 + 725e9bf commit d547114
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 0 deletions.
15 changes: 15 additions & 0 deletions documentation/translations.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,21 @@ Create and update hook for your module to import the translations.

See [Development](/documents/development.md) for more information.

### Translation context for configuration

We might want to customize some strings from contrib modules without overriding the string globally. Contrib modules can specify translation context for translatable strings in [configuration schema](https://www.drupal.org/docs/drupal-apis/configuration-api/configuration-schemametadata). However, not all contrib modules use translation contexts. To customize the context, use `hook_config_schema_info_alter()`:

```
/**
* Implements hook_config_schema_info_alter().
*/
function my_module_config_schema_info_alter(array &$definitions) : void {
if (isset($definitions['social_media.item.email'])) {
$definitions['social_media.item.email']['mapping']['text']['translation context'] = 'Social media: email';
}
}
```

## Creating custom/helfi module UI translations
Make sure the translations are imported during locale import (`drush locale:update`) by checking
the module/theme has the following information in `module_name.info.yml`. For an example, check [helfi_content.info.yml](https://github.com/City-of-Helsinki/drupal-helfi-platform-config/blob/main/helfi_features/helfi_content/helfi_content.info.yml#L46).
Expand Down
10 changes: 10 additions & 0 deletions helfi_platform_config.module
Original file line number Diff line number Diff line change
Expand Up @@ -495,3 +495,13 @@ function helfi_platform_config_user_cancel_methods_alter(array &$methods): void
}
}
}

/**
* Implements hook_config_schema_info_alter().
*/
function helfi_platform_config_config_schema_info_alter(array &$definitions) : void {
// Add translation contexts to contrib modules.
if (isset($definitions['social_media.item.email'])) {
$definitions['social_media.item.email']['mapping']['text']['translation context'] = 'Social media: email';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,11 @@ function helfi_paragraphs_contact_card_listing_update_9003() : void {
\Drupal::service('helfi_platform_config.config_update_helper')
->update('helfi_paragraphs_contact_card_listing');
}

/**
* Fix email translations.
*/
function helfi_paragraphs_contact_card_listing_update_9004() : void {
\Drupal::service('helfi_platform_config.config_update_helper')
->update('helfi_paragraphs_contact_card_listing');
}
8 changes: 8 additions & 0 deletions modules/helfi_tpr_config/helfi_tpr_config.install
Original file line number Diff line number Diff line change
Expand Up @@ -414,3 +414,11 @@ function helfi_tpr_config_update_9065(): void {
\Drupal::service('helfi_platform_config.config_update_helper')
->update('helfi_tpr_config');
}

/**
* Fix email translations.
*/
function helfi_tpr_config_update_9066(): void {
\Drupal::service('helfi_platform_config.config_update_helper')
->update('helfi_tpr_config');
}

0 comments on commit d547114

Please sign in to comment.