Locale dependent actions in WordPress
Wednesday, April 2nd, 2008For some reason or other there are actions in WordPress that have translatable fields in them, so when these actions are used on other languages than English, they change. They are actions involving the $page_hook variable., e.g. admin_head-$page_hook. I ran into this problem when updating More Fields. The problem in the context of plugins is that the language is not loaded when the plugins are loaded, so that the needed translation is not available. To get around this, the actions requiring translation are called at the ‘admin_init’ action instead.
function mf_pre_queue_js () {
add_action('load-' . sanitize_title(__('Settings')) . '_page_more-fields', 'mf_queue_js');
}
add_action('admin_init', 'mf_pre_queue_js');
I got help with this on the wp-hackers mailng list - a great source for WordPress insights.
>Try adding your actions on the init hook, I think that runs after
>the translatable stuff has been loaded and setup.Correct.
Everything related to languages should be done at init or later, so that everything is loaded and any plugins that modify the content are loaded.
So, at the init/admin_init hook, we’re safe to assume that the appropriate language has been loaded.