I found an issue while trying to translate my option page: The fields and tabs did not use the proper language strings, although my plugin language was loading fine. After trying something out, I came up with the solution:
$this->registered_settings = plugin_name_Settings_Definition::get_settings();
and
$this->options_tabs = sixtyseven_admin_Settings_Definition::get_tabs();
are called in the constructor of it's classes. By hooking these into init, all works well. This is what I came up with. First, in class-plugin-name-settings.php:
// Run this on init, so the translations are used
public function set_settings(){
$this->registered_settings = plugin_name_Settings_Definition::get_settings();
}
Second, in class-plugin-name-meta-box.php:
// Run this on init, so the translations are used
public function set_tabs(){
$this->options_tabs = sixtyseven_admin_Settings_Definition::get_tabs();
}
After that, you can call these on init in the method define_admin_hooks of class-plugin-name.php:
// Built the option page
$settings_callback = new plugin_name_Callback_Helper( $this->plugin_name );
$settings_sanitization = new plugin_name_Sanitization_Helper( $this->plugin_name );
$plugin_settings = new plugin_name_Settings( $this->get_plugin_name(), $settings_callback, $settings_sanitization);
$this->loader->add_action( 'admin_init' , $plugin_settings, 'register_settings' );
// This one is new
$this->loader->add_action( 'init' , $plugin_settings, 'set_settings' );
$plugin_meta_box = new plugin_name_Meta_Box( $this->get_plugin_name() );
// this one is new
$this->loader->add_action( 'init' , $plugin_meta_box, 'set_tabs' );
$this->loader->add_action( 'load-toplevel_page_' . $this->get_plugin_name() , $plugin_meta_box, 'add_meta_boxes' );
After that, the translations are working fine, see pictures ;-)
Before the changes:

After the changes:

I found an issue while trying to translate my option page: The fields and tabs did not use the proper language strings, although my plugin language was loading fine. After trying something out, I came up with the solution:
and
are called in the constructor of it's classes. By hooking these into init, all works well. This is what I came up with. First, in class-plugin-name-settings.php:
Second, in class-plugin-name-meta-box.php:
After that, you can call these on init in the method define_admin_hooks of class-plugin-name.php:
After that, the translations are working fine, see pictures ;-)
Before the changes:

After the changes:
