I’ve been looking into wpse archives to solve my problem but I can’t manage to do such a thing. I built this code :
$args = array('fields' => 'all_with_meta');
$users = get_users($args);
foreach ($users as $user) {
echo esc_html( translate_user_role( ucfirst ( $user->roles[0] ) ) );
}
I made a print_r()
to see what I get. Everything is fine, I mean I grab user role but it does not translate by itself. Do I need to do more?
I think your function nesting is slightly muddled; callucfirst
after translating, like so:My bad, completely skipped a beat there. You should instead be using:
It’s unreliable to assume that all role display names are simply
ucfirst( $role key )
. If that still does not work, are you sure the language files you’re using have fully translated WordPress?Please note that
translate_user_role
doesn’t work in the front-end currently.Here is a workaround, you can place this in your theme: