why is translation not working on theme?

Background

I am using the theme Rookie from Sportpress.

I created a child theme.

Translation files are existing, especially german in my case.

WordPress is set to german language.

The Problem

Translation is working fine everywhere except on themes provided templates like the search results page content or pagination.

Affected are the SRP title, nothing found page title and nothing found page content. They just stay in default english language.
Pagination is affected too.

The search form in the content of a nothing found page is translated fine. I guess because it’s WordPress default template.

Code

here some affected code lines from the parent theme.

Search Title

<h1 class="page-title entry-title"><?php printf( __( 'Search Results for: %s', 'rookie' ), '<span>' . get_search_query() . '</span>' ); ?></h1>

Nothing Found title:

<h1 class="page-title"><?php _e( 'Nothing Found', 'rookie' ); ?></h1>

Nothing found text:

<p><?php _e( 'Sorry, but nothing matched your search terms. Please try again with some different keywords.', 'rookie' ); ?></p>

Pagination:

<?php if ( get_next_posts_link() ) : ?>
            <div class="nav-previous"><?php next_posts_link( __( '<span class="meta-nav">&larr;</span> Older posts', 'rookie' ) ); ?></div>
            <?php endif; ?>

            <?php if ( get_previous_posts_link() ) : ?>
            <div class="nav-next"><?php previous_posts_link( __( 'Newer posts <span class="meta-nav">&rarr;</span>', 'rookie' ) ); ?></div>
            <?php endif; ?>

Findings

I checked that the .mo entry for german is existing with the Loco translate plugin.

I replaced the Search Result Title Search Results for: %s with the Category Title Category: %s, which gets translated on a category page (because category archive title is provided from WordPress), but also not on the SRP!

What could be a reason for this behaviour?

Workaround

the parent theme is loading the domain via
load_theme_textdomain( 'rookie', get_template_directory() . '/languages' ); and points to right location where all translation files (.pot, de_DE.po and de_DE.mo) are existing.

I copied the relevant .po and .mo files over to wp-content/languages/themes/ directory and things are working now.

But is this the real best solution?

2 s
2

I downloaded the free Rookie parent theme and have no problem displaying translations of “Search Results for: %s” on a successful search results screen.

This works in the WordPress languages folder at wp-content/languages/themes/rookie-de_DE.mo as well as Loco Translate’s custom directory. It works there if the files are named correctly because the parent theme correctly loads the “rookie” text domain using “load_theme_textdomain”.

Are your files named correctly under the WordPress languages directory? Unlike the de_DE.mo file inside the theme folder, the system location requires the prefix so files should be named rookie-de_DE.mo

Leave a Comment