Skip to content

Commit d9e1ec3

Browse files
authored
πŸ§‘β€πŸ’» Translate template name if theme text domain can be loaded (#163)
1 parent 4b56941 commit d9e1ec3

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

β€Žsrc/Roots/Acorn/Sage/Concerns/FiltersTemplates.phpβ€Ž

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public function filterTemplateInclude($file)
5555
public function filterThemeTemplates($_templates, $_theme, $_post, $post_type)
5656
{
5757
return collect($_templates)
58-
->merge($this->getTemplates($post_type))
58+
->merge($this->getTemplates($post_type, $_theme->load_textdomain() ? $_theme->get('TextDomain') : ''))
5959
->unique()
6060
->toArray();
6161
}
@@ -69,9 +69,10 @@ public function filterThemeTemplates($_templates, $_theme, $_post, $post_type)
6969
* @link https://github.com/WordPress/WordPress/blob/5.8.1/wp-includes/class-wp-theme.php#L1203-L1221
7070
*
7171
* @param string $post_type
72+
* @param string $text_domain
7273
* @return string[]
7374
*/
74-
protected function getTemplates($post_type = '')
75+
protected function getTemplates($post_type = '', $text_domain = '')
7576
{
7677
if ($templates = wp_cache_get('acorn/post_templates', 'themes')) {
7778
return $templates[$post_type] ?? [];
@@ -109,6 +110,14 @@ protected function getTemplates($post_type = '')
109110
}
110111
}
111112

113+
if ($text_domain) {
114+
foreach ($templates as $type => $files) {
115+
foreach ($files as $file => $name) {
116+
$templates[$type][$file] = translate($name, $text_domain);
117+
}
118+
}
119+
}
120+
112121
wp_cache_add('acorn/post_templates', $templates, 'themes');
113122

114123
return $templates[$post_type] ?? [];

0 commit comments

Comments
Β (0)