Internationalize / translate custom post types & taxonomies

Since you have already figured out what the text domain is – the last parameter of __() – I want to add something most people forget when custom post types or taxonomies are made translatable: slugs.

Your post type or taxonomy name can mean something very different or even embarrassing in another language. Or it can contain letters that are not available (like the famous i in Turkish) and therefore hard to type.

See untranslatable slugs as bugs in your code.

The rewrite argument for register_taxonomy() and register_post_type() accepts an array. One of the array keys is slug. Use it, make it translatable too:

register_post_type( 
    'post_type_name', 
    array (
        'rewrite' => array (
            'slug' => _x( 'post_type_name', 'URL slug', 'your_text_domain' )
        )
    )
);
register_taxonomy( 
    'taxonomy_name',
    array ( 'post', 'post_type_name' ), 
    array (
        'rewrite' => array (
            'slug' => _x( 'taxonomy_name', 'URL slug', 'your_text_domain' )
        )
    )
);

The function _x() uses a context parameter. This will help translators to see where the string will be used.

Leave a Comment