Problem/Motivation
Notification messages about created content use the [social_group:created_entity_link_html] token to display what type of content was created.
This token is handled by /modules/social_features/social_group/social_group.tokens.inc where a translatable language string is created, using either "a" or "an" plus the name of the content type (eg 'an @content_type').
However, it is hardcoded there starting at line 92, that the name of the content type will always be converted to lowercase for "photo" or "post":
// When it's a post or photo post.
case 'photo':
case 'post':
$display_name = Unicode::strtolower($entity->getEntityType()->getLabel());
This makes it impossible to actually use uppercase in any translations, even where they would be needed. Eg "a post" in German would be "ein Beitrag", but it will always be rendered as "ein beitrag".
The same problem exists in social_comment.tokens.inc and social_like.tokens.inc.
Steps to reproduce
- Translate the strings 'a @content-type' and 'an @content-type' to 'eine/n @content-type'
- Translate the string 'post' to 'Beitrag'
- Create a new post in a group
- Other group members will get the notification '[username] hat eine/n beitrag erstellt'
Proposed resolution
I think the cleanest solution would be to create a new language string for the content type including the article, like this, starting at line 104:
// When a name of content name starts from a vowel letter then
// will be added "an" before this name. For example "an
// event".
if (isset($display_name)) {
if (preg_match('/^[aeiou]/', $display_name)) {
$display_name = t('an ' . $display_name);
}
else {
$display_name = t('a ' . $display_name);
}
}
This has the additional benefit of allowing other languages to set the correct article for each possible case of @content_type, with the only downside being that it creates a couple of additional language strings that also have to be translated.
The same problem actually exists in four other token files that also set content type names to lowercase hardcoded:
- social_activity_tokens.inc
- social_comment_tokens.inc
- social_like_tokens.inc
- social_mentions_tokens.inc
In those four cases, the only solution is to create a new language string for the lowercase entity name, example from social_activity_tokens, code starting line 85
old code:
if ($group_content_type !== NULL) {
$display_name = mb_strtolower($group_content_type->label());
}
new code:
if ($group_content_type !== NULL) {
$display_name = t(mb_strtolower($group_content_type->label()), array(), array('context' => 'lowercase, used within a sentence'));
}
I'm aware this is a little bit clumsy, since it creates a lot of additional strings, and to my knowledge German might be the only language that actually requires nouns to be uppercase within a sentence. But it's the only solution I can think of.
Remaining tasks
User interface changes
API changes
Data model changes