translate_user_role()
Проверено на WordPress 6.9, обновлено Источник: WordPress Developer Resources.
Сигнатура
translate_user_role( string $name, string $domain = 'default' ): string
Описание
Поскольку имена ролей хранятся в базе данных, а не в исходном коде, для попадания их в POT-файл существуют фиктивные вызовы gettext, и эта функция корректно переводит их обратно.
Вызов before_last_bar() необходим, потому что в более старых установках роли хранятся в старом формате контекста: ‘Role name|User role’, и просто отбросить содержимое после последней вертикальной черты проще, чем исправлять их в базе данных. Новые установки этой проблемы лишены.
Оригинал (английский)
Since the role names are in the database and not in the source there are dummy gettext calls to get them into the POT file and this function properly translates them back.
The before_last_bar() call is needed, because older installations keep the roles using the old context format: ‘Role name|User role’ and just skipping the content after the last bar is easier than fixing them in the DB. New installations won’t suffer from that problem.
Параметры
$name
string
обязательный
$domain
string
необязательный
= 'default'
Возвращаемое значение
string
Исходный код
wp-includes/l10n.php:1532
function translate_user_role( $name, $domain = 'default' ) {
return translate_with_gettext_context( before_last_bar( $name ), 'User role', $domain );
}
История изменений
| Версия | Описание |
|---|---|
| 5.2.0 | Added the $domain parameter. |
| 2.8.0 | Introduced. |

