textdomain = $textdomain; $this->textdomainDir = $textdomainDir; $this->textdomainFile = $textdomainFile ?: get_locale() . '.mo'; return $this; } public function register() { add_action('init', [$this, 'loadTextdomain']); parent::register(); } public function loadTextdomain() { load_textdomain(self::$defaultTextdomain, dirname(__DIR__) . '/languages/' . get_locale() . '.mo'); if (! empty($this->textdomain)) { load_textdomain($this->textdomain, trailingslashit($this->textdomainDir) . $this->textdomainFile); } } public function createLabels() { return array_replace_recursive([ 'name' => __($this->plural, $this->textdomain), 'singular_name' => __($this->singular, $this->textdomain), 'menu_name' => __($this->plural, $this->textdomain), 'all_items' => __($this->plural, $this->textdomain), 'add_new' => __('Add New', self::$defaultTextdomain), 'add_new_item' => sprintf(__('Add New %s', self::$defaultTextdomain), __($this->singular, $this->textdomain)), 'edit_item' => sprintf(__('Edit %s', self::$defaultTextdomain), __($this->singular, $this->textdomain)), 'new_item' => sprintf(__('New %s', self::$defaultTextdomain), __($this->singular, $this->textdomain)), 'view_item' => sprintf(__('View %s', self::$defaultTextdomain), __($this->singular, $this->textdomain)), 'search_items' => sprintf(__('Search %s', self::$defaultTextdomain), $this->plural, $this->textdomain), 'not_found' => sprintf(__('No %s found', self::$defaultTextdomain), __($this->plural, $this->textdomain)), 'not_found_in_trash' => sprintf(__('No %s found in Trash', self::$defaultTextdomain), __($this->plural, $this->textdomain)), 'parent_item_colon' => sprintf(__('Parent %s:', self::$defaultTextdomain), __($this->singular, $this->textdomain)), ], $this->labels); } }