Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm using Justin Tadlock's Members plugin to create new roles and WP Role on Registration to display them on the registration form.

I've got a multilang site (English and Spanish) and I've localized my custom taxonomies using qTranslate.

I can't use qTranslate's quicktags in the Role Label field on the Member's plugin because it doesn't save it properly (even with $new_role_label = strip_tags( $_POST['role-label'] ); commented out on role-new.php) and I can't go into the database to make the changes there because then it breaks.

I've seen very scarce info about the WP function translate_user_role but I'm not sure it. There's not much else to go on.

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

I don't know the function you mention either, but I would venture to guess that that applies to default roles only anyhow.

Still, the link you posted does contain a pointer in the right direction. It speaks of "dummy gettext calls", which is exactly what you have to do.

In the following we will adjust the global $wp_roles object on init and hook a filter to the get_option( 'wp_user_roles' ) call.

function wpse92529_translatable_role_names() {
    global $wp_roles;

    $roles = $wp_roles->roles;
    $role_names = $wp_roles->role_names;

    /* define the translatable roles here */
    $translated_roles = array(
        'superuser' => _x( 'Superuser', 'Role Names', 'your-text-domain' ),
        'custom-role' => _x( 'The custom role', 'Role Names', 'your-text-domain' )
    );

    foreach ( $roles as $role_slug => $role_info ) {
        if ( array_key_exists( $role_slug, $translated_roles ) ) {
            $roles[$role_slug]['name'] = $translated_roles[$role_slug];
            $role_names[$role_slug] = $translated_roles[$role_slug];
        }
    }

    $wp_roles->roles = $roles;
    $wp_roles->role_names = $role_names;

    return $roles;
}

add_action( 'init', 'wpse92529_translatable_role_names', 1 );
add_filter( 'option_wp_user_roles', 'wpse92529_translatable_role_names', 11 );

The values of the $translated_roles array will now appear in your theme's / plugin's .pot file.

share|improve this answer
1  
Brilliant! Thank you! –  annabwashere Mar 27 '13 at 13:27
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.