Open bartkleinreesink opened 2 months ago
Thanks @bartkleinreesink
Translations should be supported after the changes made in 2.0.
Can you provide more details on how you are registering your PostTypes and translations?
The register
method handles all the hooks needed to register post types, taxonomies, columns to WordPress so any of the PostType code should not be wrapped in any actions/filters otherwise this could lead to unexpected results. For example:
// This would lead to the `register` method not working correctly and any init actions would be registered too late.
add_action( 'init', function() {
$books = new PostType( [
'name' => 'book',
'singular' => __( 'Book', 'YOUR_TEXTDOMAIN' ),
'plural' => __( 'Books', 'YOUR_TEXTDOMAIN' ),
'slug' => 'books',
] );
$books->register();
});
I'm wary of adding a did_action
check as, although it may solve this use case, it may have other side effects.
Thanks
I like the package, but it lacks one very important feature for me to start using it: translation support.
I am not a native English speaker and my clients mostly aren't, either. So when I create a website, I want to make it at least bilingual.
Of course, I could extend the classes and move my way around the current limitations, but that is very cumbersome if it needs to be done for every project.
The biggest problem is that there is no check if the
init
hook has been fired already. My suggestion would be to calldid_action('init')
. If true, call the methods directly, otherwise, register them to theinit
hook.This is a problem because I'm not able to choose when the post type is registered in the hook chain. So when I have translated strings in the declaration of the post type, they are not available at the time when the post type gets registered, because they are loaded too early. I want to decorate the class after the init hook has been fired.