How to i18n slugs for templates?

some templates are chosen from WordPress based on slugs (e.g. category-{slug}.php).

Problem:
How can I use the same template for an i18n’ed slug?

Read More

Example:
I have a category-news.php and an english category with slug “news” and german category with slug “nachrichten”. But of course “nachrichten” doesn’t get category-news.php as a template. How can I i18n “nachrichten” so WordPress knows it means “news” before the template will be chosen internally?

Related posts

Leave a Reply

1 comment

  1. Filter template_include:

    add_filter( 'template_include', 'prefix_translate_template' );
    
    function prefix_translate_template( $template )
    {
        if ( 'category-' . __( 'news', 'your_textdomain' ) . '.php' === $template )
            return 'category-news.php';
    
        return $template;
    }
    

    But I think templates based on slugs are not a good idea in that case.