7

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 Answers 2

0

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

1
  • as i wrote in my question post. this is my workaround isn't it? because i had to copy language files out of the theme directory into WP's language folder. But yes this is how it works currently. Commented Aug 8, 2018 at 13:39
-1

Putting files in wp-content/languages/themes/ is not a good idea because on the next update, the file will be overwritten.

The best way to correct that is to put the .mo file in the child theme with the name de_DE.mo.
Then, if e.g. you put the file in the directory wp-content/themes/rookie-child/languages, put this code in wp-content/themes/rookie-child/functions.php :

add_action("after_setup_theme", function () {

    load_theme_textdomain( 'rookie', get_stylesheet_directory() . '/languages' );


}, 5);
4
  • "on the next update, the file will be overwritten." are you sure? will these files get deleted? because they weren't existing before.. i just tried it and moved the rookie-de_DE.po and rookie-de_DE.mo files from wp-content/languages/themes/ into wp-content/themes/rookie-child/languages, added the part into child themes functions.php but without success. :-/ Commented Jul 21, 2018 at 9:25
  • all files in the child theme are not concerned by updates then they will remain in place.
    – mmm
    Commented Jul 21, 2018 at 9:27
  • The child theme directory is safe, but you should not load parent theme translations from the child. Child theme should use its own text domain if extra source strings are required, and the parent should be left to handle the strings it defines. Parent and child are separate namespaces and translations do not inherit.
    – Tim
    Commented Aug 7, 2018 at 12:10
  • I believe this is not true. Adding translation in wp-content/languages/themes/ will not be overridden when theme updates, since these are outside of the theme directory.
    – Rao Abid
    Commented May 7, 2021 at 19:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.