From d9e1ec3006efc50dad8fc9998b17b09a4ef83054 Mon Sep 17 00:00:00 2001 From: Teppo Koivula Date: Fri, 3 Feb 2023 15:11:37 -0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=A7=91=E2=80=8D=F0=9F=92=BB=20Translate?= =?UTF-8?q?=20template=20name=20if=20theme=20text=20domain=20can=20be=20lo?= =?UTF-8?q?aded=20(#163)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Roots/Acorn/Sage/Concerns/FiltersTemplates.php | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/Roots/Acorn/Sage/Concerns/FiltersTemplates.php b/src/Roots/Acorn/Sage/Concerns/FiltersTemplates.php index 2d44e8df..75f9ef4b 100644 --- a/src/Roots/Acorn/Sage/Concerns/FiltersTemplates.php +++ b/src/Roots/Acorn/Sage/Concerns/FiltersTemplates.php @@ -55,7 +55,7 @@ public function filterTemplateInclude($file) public function filterThemeTemplates($_templates, $_theme, $_post, $post_type) { return collect($_templates) - ->merge($this->getTemplates($post_type)) + ->merge($this->getTemplates($post_type, $_theme->load_textdomain() ? $_theme->get('TextDomain') : '')) ->unique() ->toArray(); } @@ -69,9 +69,10 @@ public function filterThemeTemplates($_templates, $_theme, $_post, $post_type) * @link https://github.com/WordPress/WordPress/blob/5.8.1/wp-includes/class-wp-theme.php#L1203-L1221 * * @param string $post_type + * @param string $text_domain * @return string[] */ - protected function getTemplates($post_type = '') + protected function getTemplates($post_type = '', $text_domain = '') { if ($templates = wp_cache_get('acorn/post_templates', 'themes')) { return $templates[$post_type] ?? []; @@ -109,6 +110,14 @@ protected function getTemplates($post_type = '') } } + if ($text_domain) { + foreach ($templates as $type => $files) { + foreach ($files as $file => $name) { + $templates[$type][$file] = translate($name, $text_domain); + } + } + } + wp_cache_add('acorn/post_templates', $templates, 'themes'); return $templates[$post_type] ?? [];