Custom Post Type and taxonomies’s labels localization not working

after a few hours serching on the net I decided to ask here my problem.
I’m in a multi site environment and I have this custom post type code:

$products_labels = array(
    'name'                => _x( 'Prodotti', 'General post type name', 'textdomain' ),
    'singular_name'       => _x( 'Prodotto', 'General post type name', 'textdomain' ),
    'menu_name'           => _x( 'Prodotti', 'General post type menu label', 'textdomain' ),
    'parent_item_colon'   => __( 'Genitore elemento:', 'textdomain' ),
    'all_items'           => __( 'Tutti gli elementi', 'textdomain' ),
    'view_item'           => __( 'Vedi', 'textdomain' ),
    'add_new_item'        => __( 'Aggiungi nuovo elemento', 'textdomain' ),
    'add_new'             => __( 'Aggiungi nuovo', 'textdomain' ),
    'edit_item'           => __( 'Modifica', 'textdomain' ),
    'update_item'         => __( 'Aggiorna', 'textdomain' ),
    'search_items'        => __( 'Cerca', 'textdomain' ),
    'not_found'           => __( 'Non trovato', 'textdomain' ),
    'not_found_in_trash'  => __( 'Non trovato nel cestino', 'textdomain' ),
);
$products_args = array(
    'label'               => __( 'Prodotti', 'textdomain' ),
    'description'         => __( 'Prodotti', 'textdomain' ),
    'labels'              => $products_labels,
    'supports'            => array( 'title', 'thumbnail', 'editor', 'excerpt', 'revisions', 'page-attributes' ),
    'taxonomies'          => array( 'product_category' ),
    'hierarchical'        => false,
    'public'              => true,
    'show_ui'             => true,
    'show_in_menu'        => true,
    'show_in_nav_menus'   => true,
    'show_in_admin_bar'   => true,
    'menu_position'       => 5,
    'menu_icon'           => '',
    'can_export'          => true,
    'has_archive'         => true,
    'exclude_from_search' => false,
    'publicly_queryable'  => true,
    'capability_type'     => 'page',
);

One of my sites is on german language and the backoffice has been set in german as well.
All the strings are correctly translated (the frontend works without problems) and the de_DE.mo file is well loaded but the labels from the admin perspective are not localized and I can’t understand why not 🙁

This is the load text domain

load_theme_textdomain( 'textdomain', THEMEPATH . '/languages' );

pls find the attached image
enter image description here

Hope you can help me 🙁

UPDATE:

I’noticed that all strings written in functions.php file are not translated.
The only way to translate them is to insert strings in a new function called on init action.

exemple:

NOT TRANSLATED

$str = __('My string','textdomain');

TRANSLATED:

function my_function_name()
{
    $str = __('My string','textdomain');
    echo $str;
}

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

UPDATE 2:

SOLVED.
You have to load the load_theme_textdomain not by action but directly written as first line on the file functions.php
Now my custom post type labels are finally translated 🙂

2 Answers
2

SOLVED. You have to load the load_theme_textdomain not by action but directly written as first line on the file functions.php Now my custom post type labels are finally translated 🙂

Leave a Comment