diff options
Diffstat (limited to 'src/PostType.php')
-rw-r--r-- | src/PostType.php | 54 |
1 files changed, 54 insertions, 0 deletions
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 @@ +<?php + +namespace BasicFullCalendar; + +class PostType extends \PostTypes\PostType +{ + public string $textdomain = ''; + public string $textdomainDir; + public string $textdomainFile; + public static $defaultTextdomain = 'PostTypes/PostType'; + + public function textdomain($textdomain, $textdomainDir, $textdomainFile = '') + { + $this->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); + } +} |