From 62046b3acde01f9f66e1d5d52e03fea4c5bbfc8d Mon Sep 17 00:00:00 2001 From: Daniel Weipert Date: Fri, 18 Dec 2020 00:56:32 +0100 Subject: Initial commit --- src/PostType.php | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 src/PostType.php (limited to 'src/PostType.php') diff --git a/src/PostType.php b/src/PostType.php new file mode 100644 index 0000000..67f4fd2 --- /dev/null +++ b/src/PostType.php @@ -0,0 +1,54 @@ +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); + } +} -- cgit v1.2.3