Translations in Custom Post Type don't get captured

Hi,

i have a few custom post types in which I use i18n-functions provided from wordpress.

Now i want to translate the labels of the custom post types. I have done all like in your documentation (Sage 10.x: Localization | Roots Documentation) but i can’t find any label of the custom post types in the sage.pot.

How i can capture this labels to translate them?

How have you registered those custom post types? By a plugin (e.g. Custom Post Type UI)?

I have registered the custom post types by code. Here is an example:

<?php

function add_custom_post_type_events() {

	$labels = array(
		'name'                  => _x( 'Events', 'Post Type General Name', 'sage' ),
		'singular_name'         => _x( 'Event', 'Post Type Singular Name', 'sage' ),
		'menu_name'             => __( 'Events', 'sage' ),
		'name_admin_bar'        => __( 'Event', 'sage' ),
		'all_items'             => __( 'All Events', 'sage' ),
		'add_new_item'          => __( 'Add New Event', 'sage' ),
		'add_new'               => __( 'Add Event', 'sage' ),
		'new_item'              => __( 'New Event', 'sage' ),
		'edit_item'             => __( 'Edit Event', 'sage' ),
		'update_item'           => __( 'Update Event', 'sage' ),
		'view_item'             => __( 'View Event', 'sage' ),
		'view_items'            => __( 'View Events', 'sage' ),
		'search_items'          => __( 'Search Events', 'sage' ),
		'not_found'             => __( 'No events found', 'sage' ),
		'not_found_in_trash'    => __( 'No events found in Trash', 'sage' ),
		'featured_image'        => __( 'Event Cover Image', 'sage' ),
		'set_featured_image'    => __( 'Set cover image', 'sage' ),
		'remove_featured_image' => __( 'Remove cover image', 'sage' ),
		'use_featured_image'    => __( 'Use as cover image', 'sage' ),
		'insert_into_item'      => __( 'Insert into event', 'sage' ),
		'uploaded_to_this_item' => __( 'Uploaded to this event', 'sage' ),
		'items_list'            => __( 'Events list', 'sage' ),
		'items_list_navigation' => __( 'Events list navigation', 'sage' ),
		'filter_items_list'     => __( 'Filter events list', 'sage' ),
	);
    
	$args = array(
		'labels'                => $labels,
		'public'                => true,
		'show_ui'               => true,
		'show_in_menu'          => true,
		'menu_position'         => null,
        'menu_icon'             => 'dashicons-media-interactive',
        'query_var'             => true,
		'has_archive'           => true,
        'hierachical'           => false,
        'capability_type'       => 'post',
		'rewrite'               => array( 'slug' => 'event' ),
        'show_in_rest'          => true,
        'supports'              => array( 'title', 'editor', 'thumbnail' )
	);
   
	register_post_type( 'event', $args );
}


What npm script/command are you using for generating the POT?
The current one in Sage 10 master (sage/package.json at c7d5324d894d5c595b182805d24a37096c03cf74 · roots/sage · GitHub)?

Also note that not all directories are scanned by that command (app/ and resources/), so where your custom post type code is important. - Or you need to modify that path so the directory or that file is also included.

1 Like

Thank you strarsis. This was the reason why the translations didn’t get captured.