• Hi,
    I am writing a plugin to create custom user roles and to remove wordpress default user roles except the admin one.

    Everything is ok, but custom roles are not translated in the wordpress back-office (in user profil for example, or in settings=>general=>default role).

    My plugin code is translation ready: i have created a .pot file and .po and .mo myplugin-fr_FR local. Translation files are ok, because i can see translated description and plugin name in admin plugin page.

    /*
    Plugin Name: My Website User Roles
    Description: Custom user roles and capabilities for my website.
    Version:     1.0
    Author:      me
    License:     GPL2
    License URI: https://www.gnu.org/licenses/gpl-2.0.html
    Text Domain: my_website_user_roles
    Domain Path: /languages
    */
    class My_Website_User_Roles {
    
        public function __construct() {
            // on activation
            register_activation_hook( __FILE__, array( 'My_Website_User_Roles', 'activate' ) );
    
            /** other stuff like deactivation, etc... */
    
            // translation
            add_action( 'plugins_loaded', array( $this, 'load_textdomain' ) );
        }
    
        public function load_textdomain() {
            load_plugin_textdomain( 'my_website_user_roles', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' );
        }
    
        public static function activate() {
            // remove wp default roles except admin
    	remove_role( 'editor' );
    	remove_role( 'author' );
    	remove_role( 'contributor' );
    	remove_role( 'subscriber' );
    
    	add_role(
    		'basic_contributor',
    		__( 'Occasional Contributor', 'my_website_user_roles' ),
    		array(
    			'read'         => true,
    			'edit_posts'   => true,
    			'delete_posts' => true,
    		)
    	);
    
    	add_role(
    		'expert_contributor',
    		__( 'Expert Contributor', 'my_website_user_roles' ),
    		array(
    			'read'          => true,
    			'edit_posts'    => true,
    			'delete_posts'  => true,
    			'publish_posts' => false,
    			'upload_files'  => true,
    			'edit_others_posts' => true,
    			'edit_published_posts' => true,
    		)
    	);
    
    	add_role(
    		'moderator',
    		__( 'Moderator', 'my_website_user_roles' ),
    		array(
    			'read'                   => true,
    			'edit_posts'             => true,
    			'delete_posts'           => true,
    			'publish_posts'          => true,
    			'edit_published_posts'   => true,
    			'delete_published_posts' => true,
    			'moderate_comments'      => true,
    		)
    	);
        }
    
    }

    On my languages directory, i have created my_website_user_roles-fr_FR.po and my_website_user_roles-fr_FR.mo files that should translate Occasional Contributor to ‘contributeur occasionnel’, Expert Contributor to ‘contributeur expert’ and Moderator to ‘modérateur’.
    But in the wordpress admin back office, custom user roles are in english but not in french.
    Localisation files are loaded because they also translate the plugin description and i can see the description in french on the plugins page.

    How can i see the custom user roles in a local language on the back office ? what am i doing wrong ?

Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Custom user roles translation not working’ is closed to new replies.