0

I'm encountering a weird behavior with the translation for a custom plugin I've made for a customer.

The translation files are in the plugin languages folder and I load them with load_plugin_textdomain.

In the plugin page inside wp-admin, I see the translation:

enter image description here

In the front-end pages, I see the translation:

enter image description here

In the custom post page in wp-admin not:

enter image description here

If I move the *.mo file in the wp-content/languages/plugin folder, it works fine.

enter image description here

why? is it a normal behavior? Am I doing something wrong?

Here's the code:

Pluginname: interzero_team.php in folder interzero_team

/*
* Text Domain:   interzero_team
* Domain Path:   /languages
*/

/**
 * create custom post type for the staff members
 */
function interzero_team_create_cpost_staff(){
    
    $labels = array(
        'name'               => esc_html__( 'Team members', 'interzero_team' ),
        'singular_name'      => esc_html__( 'Team member', 'interzero_team' ),
        'add_new'            => esc_html__( 'Add a new member', 'interzero_team' ),
        'add_new_item'       => esc_html__( 'Add a new member', 'interzero_team' ),
        'edit_item'          => esc_html__( 'Edit team member', 'interzero_team' ),
        'new_item'           => esc_html__( 'New team member', 'interzero_team' ),
        'all_items'          => esc_html__( 'Show the team', 'interzero_team' ),
        'view_item'          => esc_html__( 'View a member', 'interzero_team' ),
        'search_items'       => esc_html__( 'Search for a member', 'interzero_team' ),
        'not_found'          => esc_html__( 'No member found', 'interzero_team' ),
        'not_found_in_trash' => esc_html__( 'No member found in the Trash', 'interzero_team' ), 
        'parent_item_colon'  => esc_html__( 'Parent', 'interzero_team' ),
        'menu_name'          => esc_html__( 'Team', 'interzero_team' )
    );
    $args = array(
        'labels'                => $labels,
        'description'           => 'Team members',
        'public'                => true,
        'publicly_queryable'    => true,
        'hierarchical'          => false,
        'menu_position'         => 10,
        'menu_icon'             => 'dashicons-groups',
        'show_in_rest'          => false,
        'supports'              => array( 'title', 'editor', 'thumbnail', 'custom-fields', 'excerpt', 'post-formats' ),
        'has_archive'           => true,
        'rewrite'               => array(
            'with_front' => false,
            'slug'       => 'staff'
        ),
        'query_var'             => true,
        'taxonomies'            => array('department')
    );
    register_post_type( 'team-member', $args );
}
add_action( 'init' , 'interzero_team_create_cpost_staff', 0);

/**
 * localize
 */
function interzero_team_load_plugin_textdomain() {
    load_plugin_textdomain( 'interzero_team', false, basename( __DIR__ ) . '/languages/' );
}
add_action( 'init', 'interzero_team_load_plugin_textdomain' );

1 Answer 1

0

I solved it. It was a priority problem:

The

add_action( 'init' , 'interzero_team_create_cpost_staff', 0);

had a priority of 0, so it was loaded before the translations where available.

ciao

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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