Getting a role based on a localized role name

I use the following code to get the Administrator role

$admin = get_role('administrator');  This works fine, but on a different WordPress language setup, this code breaks. For example, in French it should be $admin = get_role('adminstrateur');


Any cross-language solution?

• Interesting question. +1 I never noticed this (using german lang installations), but maybe you have/had some role manager, membership or capability editor plugins installed? – kaiser Apr 5 '12 at 4:32

\$admin = get_role( __( 'administrator' ) );

If you're trying to make sure that WP translates the string for a specific locale, __() will return the translated string. So if get_role('administrator') works and on a French setup get_role('administrateur') would work, then the above code snippet should do what you need.
• Calling __( 'some text' ) is identical to calling __( 'some text', 'default' ) ... it will use WP's default text domain. – EAMann Apr 4 '12 at 23:05
• I guess it would be (uppercase 1st char) Administrator. – kaiser Apr 5 '12 at 4:30