Hello! I do not use RealName module cause I need lightweight fast working code. Here it is an example of replacing user login in Submitted string and everywhere on a site: user profile, views and even in the admin pages - with user's name that he places in field_imya- this is Russian word name. Or if user had not filled this field replace with line User id
function mydisplayname_user_format_name_alter(&$name, $account) {
// Display filed_imya or the user's uid instead of login.
$user = \Drupal\user\Entity\User::load($account->id());
$langcode = \Drupal::languageManager()->getCurrentLanguage()->getId();
if ($translation = \Drupal::service('entity.repository')->getTranslationFromContext($user)) {
$user = $translation;
}
//if this is not user deletion process
if ( !is_null($user)) {
$imya = $user->get('field_imya')->value;
if ($imya) {
$name = $imya;
} else {
$name = t('User @uid', array('@uid' => $account->id(),));
}
}
}
imya - is user's display name that he fills in field_imya.
This module uses translations with getTranslationFromContext($user) from here getTranslationFromContext/8.7.x That allows you not to check by your hands if user has translation or not.
getTranslationsFromContext This will check whether a translation for the desired language is available and if not, it will fall back to the most appropriate translation based on the provided context.