I'm building a wordpress plugin, that will register a post type. Im trying to set up a simple test case where all it does is registering a post type with get text functions and translating it with poedit. I have successfully created the .po and .mo files, and loaded them with the following code:
add_action('init', 'client_functions_textdomain');
function client_functions_textdomain(){
load_plugin_textdomain( 'client-functions', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
}
If i test a gettextcall right after loading this, everything translates fine. And the load_plugin_textdomain() returns true.
But when i afterwards try to register a post type with the following code (taken from the codex), its doesn't translate:
add_action( 'init', 'codex_book_init' );
/**
* Register a book post type.
*
* @link http://codex.wordpress.org/Function_Reference/register_post_type
*/
function codex_book_init() {
$labels = array(
'name' => _x( 'Books', 'post type general name', 'client-functions' ),
'singular_name' => _x( 'Book', 'post type singular name', 'client-functions' ),
'menu_name' => _x( 'Books', 'admin menu', 'client-functions' ),
'name_admin_bar' => _x( 'Book', 'add new on admin bar', 'client-functions' ),
'add_new' => _x( 'Add New', 'book', 'client-functions' ),
'add_new_item' => __( 'Add New Book', 'client-functions' ),
'new_item' => __( 'New Book', 'client-functions' ),
'edit_item' => __( 'Edit Book', 'client-functions' ),
'view_item' => __( 'View Book', 'client-functions' ),
'all_items' => __( 'All Books', 'client-functions' ),
'search_items' => __( 'Search Books', 'client-functions' ),
'parent_item_colon' => __( 'Parent Books:', 'client-functions' ),
'not_found' => __( 'No books found.', 'client-functions' ),
'not_found_in_trash' => __( 'No books found in Trash.', 'client-functions' )
);
$args = array(
'labels' => $labels,
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'show_in_menu' => true,
'query_var' => true,
'rewrite' => array( 'slug' => _x( 'book', 'URL slug', 'client-functions' ) ),
'capability_type' => 'post',
'has_archive' => true,
'hierarchical' => false,
'menu_position' => null,
'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'comments' )
);
register_post_type( 'book', $args );
}
I suspect that this has to do with the fact that both are hooked into the 'init' action, and the registering happens before the text domain is loaded? I have tried the following with no success:
- added priority 0 to the textdoamin action, and priority 20 to book_init function
- i have loaded the text domain in the 'plugins_loaded' action
Any help would be greatly appreciated!
Thanks Malthe