我正在构建一个本地化的小部件the translation works everywhere but in the language string in the constructor. 我have read 那个
整个插件初始化必须绑定到init挂钩
为了避免这个问题,但我不知道该怎么做,因为如果我尝试用init而不是widgets\\u init注册小部件,则根本没有初始化。
如何解决这个问题?
我的代码:
  class Pinboard_Linkroll_Widget extends WP_Widget {
    // Constants & Properties go here...
    protected $widget_slug = \'pinboard-linkroll-widget\';
    /*--------------------------------------------------*/
    /* Constructor
    /*--------------------------------------------------*/
    /**
    * Includes pinboard API class, 
    * Specifies the classname and description, instantiates the widget,
    * loads localization files, and includes necessary stylesheets and JavaScript.
    */
    public function __construct() {
      // include pinboard api class
      // https://github.com/kijin/pinboard-api
      include_once( dirname(__FILE__). \'/lib/pinboard-api.php\' );
      // load plugin text domain
      add_action( \'init\', array( &$this, \'widget_textdomain\' ) );
      // actual widget constructor
      parent::__construct(
        $this->get_widget_slug(),
        __( \'Pinboard Linkroll Widget\', $this->get_widget_slug() ),
        array(
          \'classname\'  => $this->get_widget_slug().\'-class\',
          \'description\' => __( \'Returns a list of recent Pinboard Links.\', $this->get_widget_slug() )
        )
      );
      // handle token errors in admin area (check for valid token and display errors)
      add_action( \'sidebar_admin_setup\', array( &$this, \'handle_token_errors\' ) );
      // delete transients when last widget instance is deleted
      // http://wordpress.stackexchange.com/questions/95091/how-to-delete-cached-transients-from-a-widget-instance-properly
      add_action( \'sidebar_admin_setup\', array( &$this, \'delete_transient\' ) );
    } // end constructor
    /**
     * Returns widget slug
     *
     * @since   0.7.0
     * @return  Plugin slug variable.
     */
    public function get_widget_slug() {
      return $this->widget_slug;
    }
    /**
     * Loads the Widget\'s text domain for localization and translation.
     *
     * @since   0.7.0
     */
    public function widget_textdomain() {
      load_plugin_textdomain( $this->get_widget_slug(), false, $this->get_widget_slug() . \'/lang\' );
    } // end widget_textdomain
    // WP Widget API functions & other stuff goes here...
  }
  // register widget
  add_action( \'widgets_init\', create_function(\'\', \'return register_widget("Pinboard_Linkroll_Widget");\') );
}