Skip to content

Commit

Permalink
πŸ§‘β€πŸ’» Translate template name if theme text domain can be loaded (#163)
Browse files Browse the repository at this point in the history
  • Loading branch information
teppokoivula authored Feb 3, 2023
1 parent 4b56941 commit d9e1ec3
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/Roots/Acorn/Sage/Concerns/FiltersTemplates.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand All @@ -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] ?? [];
Expand Down Expand Up @@ -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] ?? [];
Expand Down

0 comments on commit d9e1ec3

Please sign in to comment.