translate_user_role() WordPress Function

The translate_user_role() function is used to translate a user role name into a different language. This is useful for multilingual sites where the user roles need to be displayed in the language of the user.

translate_user_role( string $name, string $domain = 'default' ) #

Translates role name.


Description

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.


Top ↑

Parameters

$name

(string)(Required)The role name.

$domain

(string)(Optional) Text domain. Unique identifier for retrieving translated strings.

Default value: 'default'


Top ↑

Return

(string) Translated role name on success, original name on failure.


Top ↑

Source

File: wp-includes/l10n.php

function translate_user_role( $name, $domain = 'default' ) {
	return translate_with_gettext_context( before_last_bar( $name ), 'User role', $domain );
}


Top ↑

Changelog

Changelog
VersionDescription
5.2.0Added the $domain parameter.
2.8.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.