This thread is resolved. Here is a description of the problem and solution.
Problem:
How to translate the custom post type menu in the dashboard? I use Metabox to create custom post type.
Solution:
You can not translate the menu label for the post types created by Metabox plugin. Instead, you need to create the custom post type yourself and in the code use Gettext
https://developer.wordpress.org/reference/hooks/gettext/
An example:
'menu_name' => __( 'Bla', 'blabla' ),
After that, scan the plugin or theme that you added the code in and do the translation in string translation.
Relevant Documentation:
https://wpml.org/documentation/getting-started-guide/string-translation/
This is the technical support forum for WPML - the multilingual WordPress plugin.
Everyone can read, but only WPML clients can post here. WPML team is replying on the forum 6 days per week, 22 hours per day.
This topic contains 6 replies, has 2 voices.
Last updated by marcoR-2 1 year, 11 months ago.
Assisted by: Christopher Amirian.
Author | Posts |
---|---|
April 16, 2022 at 5:10 am #11031241 | |
marcoR-2 |
Tell us what you are trying to do? Is there any documentation that you are following? Is there a similar example that we can see? What is the link to your site? I create a CPT with metabox and now I want to see the name of this CPT (in admin) in another language the post bellow was marked as resolved but was not really resolved |
April 16, 2022 at 1:44 pm #11032239 | |
Christopher Amirian Supporter
Languages: English (English ) Timezone: Asia/Yerevan (GMT+04:00) |
Hi there, Would you please search for the value of the custom post type title inside the Admin Text section of the string translation and register it to be able to translate it. Here is how to do so: (Check the Register Strings for Translation section) Thanks. |
April 16, 2022 at 3:41 pm #11032491 | |
marcoR-2 |
Hi! Thank you for the response. |
April 18, 2022 at 1:37 pm #11038795 | |
Christopher Amirian Supporter
Languages: English (English ) Timezone: Asia/Yerevan (GMT+04:00) |
Hi there, Would you please kindly contact Metabox support and ask them if they add their post type into a gettext wrap in the generated code? For example the code below registers a post type: // Register Custom Post Type function bla_custom_post_type() { $labels = array( 'name' => _x( 'Blas', 'Post Type General Name', 'blabla' ), 'singular_name' => _x( 'Bla', 'Post Type Singular Name', 'blabla' ), 'menu_name' => __( 'Bla', 'blabla' ), 'name_admin_bar' => __( 'Post Type', 'blabla' ), 'archives' => __( 'Item Archives', 'blabla' ), 'attributes' => __( 'Item Attributes', 'blabla' ), 'parent_item_colon' => __( 'Parent Item:', 'blabla' ), 'all_items' => __( 'All Items', 'blabla' ), 'add_new_item' => __( 'Add New Item', 'blabla' ), 'add_new' => __( 'Add New', 'blabla' ), 'new_item' => __( 'New Item', 'blabla' ), 'edit_item' => __( 'Edit Item', 'blabla' ), 'update_item' => __( 'Update Item', 'blabla' ), 'view_item' => __( 'View Item', 'blabla' ), 'view_items' => __( 'View Items', 'blabla' ), 'search_items' => __( 'Search Item', 'blabla' ), 'not_found' => __( 'Not found', 'blabla' ), 'not_found_in_trash' => __( 'Not found in Trash', 'blabla' ), 'featured_image' => __( 'Featured Image', 'blabla' ), 'set_featured_image' => __( 'Set featured image', 'blabla' ), 'remove_featured_image' => __( 'Remove featured image', 'blabla' ), 'use_featured_image' => __( 'Use as featured image', 'blabla' ), 'insert_into_item' => __( 'Insert into item', 'blabla' ), 'uploaded_to_this_item' => __( 'Uploaded to this item', 'blabla' ), 'items_list' => __( 'Items list', 'blabla' ), 'items_list_navigation' => __( 'Items list navigation', 'blabla' ), 'filter_items_list' => __( 'Filter items list', 'blabla' ), ); $args = array( 'label' => __( 'Bla', 'blabla' ), 'description' => __( 'Post Type Description', 'blabla' ), 'labels' => $labels, 'supports' => a There is an option for menu name here: 'menu_name' => __( 'Bla', 'blabla' ), As you can see it is wrapped into __() function. That causes the name to be available in String Translation. But it the code is like this: 'menu_name' => 'Bla' Then it will not be available for string translation. Now I am not sure how Metabox add their underlying code. By the way that Admin menu will be shown as translated after it is in the string translation and translated only and only when you go to Users > Profile and change the admin language to the language that you translated to. Thanks |
April 19, 2022 at 9:49 am #11043991 | |
marcoR-2 |
Hi! Thank you From metabox they confirmed me that I have to add the code manually. Even that, I still not seen it. I left at the end the code that I'm using. I tried to not put "esc_html" <?php add_action( 'init', 'slwly_register_post_type' ); function slwly_register_post_type() { $labels = [ 'name' => esc_html__( 'Patrocinadors', 'slwly-wpml' ), 'singular_name' => esc_html__( 'Patrocinador', 'slwly-wpml' ), 'add_new' => esc_html__( 'Add New', 'slwly-wpml' ), 'add_new_item' => esc_html__( 'Add new patrocinador', 'slwly-wpml' ), 'edit_item' => esc_html__( 'Edit Patrocinador', 'slwly-wpml' ), 'new_item' => esc_html__( 'New Patrocinador', 'slwly-wpml' ), 'view_item' => esc_html__( 'View Patrocinador', 'slwly-wpml' ), 'view_items' => esc_html__( 'View Patrocinadors', 'slwly-wpml' ), 'search_items' => esc_html__( 'Search Patrocinadors', 'slwly-wpml' ), 'not_found' => esc_html__( 'No patrocinadors found', 'slwly-wpml' ), 'not_found_in_trash' => esc_html__( 'No patrocinadors found in Trash', 'slwly-wpml' ), 'parent_item_colon' => esc_html__( 'Parent Patrocinador:', 'slwly-wpml' ), 'all_items' => esc_html__( 'All Patrocinadors', 'slwly-wpml' ), 'archives' => esc_html__( 'Patrocinador Archives', 'slwly-wpml' ), 'attributes' => esc_html__( 'Patrocinador Attributes', 'slwly-wpml' ), 'insert_into_item' => esc_html__( 'Insert into patrocinador', 'slwly-wpml' ), 'uploaded_to_this_item' => esc_html__( 'Uploaded to this patrocinador', 'slwly-wpml' ), 'featured_image' => esc_html__( 'Featured image', 'slwly-wpml' ), 'set_featured_image' => esc_html__( 'Set featured image', 'slwly-wpml' ), 'remove_featured_image' => esc_html__( 'Remove featured image', 'slwly-wpml' ), 'use_featured_image' => esc_html__( 'Use as featured image', 'slwly-wpml' ), 'menu_name' => esc_html__( 'Patrocinadors', 'slwly-wpml' ), 'filter_items_list' => esc_html__( 'Filter patrocinadors list', 'slwly-wpml' ), 'filter_by_date' => esc_html__( '', 'slwly-wpml' ), 'items_list_navigation' => esc_html__( 'Patrocinadors list navigation', 'slwly-wpml' ), 'items_list' => esc_html__( 'Patrocinadors list', 'slwly-wpml' ), 'item_published' => esc_html__( 'Patrocinador published', 'slwly-wpml' ), 'item_published_privately' => esc_html__( 'Patrocinador published privately', 'slwly-wpml' ), 'item_reverted_to_draft' => esc_html__( 'Patrocinador reverted to draft', 'slwly-wpml' ), 'item_scheduled' => esc_html__( 'Patrocinador scheduled', 'slwly-wpml' ), 'item_updated' => esc_html__( 'Patrocinador updated', 'slwly-wpml' ), 'text_domain' => esc_html__( 'slwly-wpml', 'slwly-wpml' ), ]; $args = [ 'label' => esc_html__( 'Patrocinadors', 'slwly-wpml' ), 'labels' => $labels, 'description' => 'Patrocinadors económics de la entitat', 'public' => true, 'hierarchical' => false, 'exclude_from_search' => false, 'publicly_queryable' => true, 'show_ui' => true, 'show_in_nav_menus' => true, 'show_in_admin_bar' => true, 'show_in_rest' => true, 'query_var' => true, 'can_export' => true, 'delete_with_user' => true, 'has_archive' => true, 'rest_base' => '', 'show_in_menu' => true, 'menu_position' => '', 'menu_icon' => 'dashicons-money-alt', 'capability_type' => 'post', 'supports' => ['title'], 'taxonomies' => [], 'rewrite' => [ 'with_front' => false, ], ]; register_post_type( 'patrocinador', $args ); } |
April 19, 2022 at 2:05 pm #11046507 | |
Christopher Amirian Supporter
Languages: English (English ) Timezone: Asia/Yerevan (GMT+04:00) |
Hi there, Thank you. Now please go to String Translation and enable the Auto Register option and the Track option. (you will deactivate this options later) After that, please go to WPML > Theme and plugins localization. Re-scan the theme or plugin that you added the custom post type code in. Then go back to string translation and you should see the menu name for translation. Thanks. |