1

I am experiencing a small problem and I have tried several solutions, but none of them has worked unfortunately. Perhaps somebody has a clue why :-)

I am using the Syntax theme from Automattic which has its own language file, but it also uses the default Wordpress core language file to display some words in the frontend of my theme.

I have set the language to Dutch (nl_NL) and one word is not translated properly, namely the word 'Aside' which is translated in 'Aside' as well. However, this is not a Dutch word and I'd like to change it into 'Notities'.

I have tried these three solutions, but they all did not work :-( Perhaps it has something to do with the fact that the original word 'Aside' is translated in 'Aside' as well in the Wordpress core language file? I am just guessing :-)

  1. Option 1 that did not work
  2. Option 2 idem.
  3. Option 3 by using the plugin 'Quick Localization'

This is the script that resides in wp-includes/post-formats.php that relates to the display of the word 'Aside' in the frontend of my website:

    function get_post_format_strings() {
        $strings = array(
            'aside'    => _x( 'Aside',    'Post format' ),
        );
        return $strings;
    }

I hope someone has a bright idea. I would appreciate it very much.

Thank you and regards, Bark

1

Correcting the answer given by Max. To use this approach, the filter you need is gettext_with_context because your string is translated via _x() not __().

Note that the filtered argument passed is the translation, so you should check the source string ($text and $context) to ensure you're filtering the correct item.

add_filter( 'gettext_with_context', 'added_translation', 20, 4 );

function added_translation( $translation, $text, $context, $domain )
{
  if( 'Aside' === $text && 'Post format' === $context ){
    $translation = 'Aan de kant';
  }
  return $translation;
}

Up to you exactly how you detect the string and whether you also check to see if Dutch is the current locale. However this filter does work and should work regardless if the theme you're using.

If you're making a lot of string improvements I recommend using a translation file loaded in addition to the installed translations. Example guide here using Loco Translate to add your own custom file. (Disclosure: my plugin)

  • Hi Tim, Well, your script contains the solution partly. The script is applied in single 'aside' posts and 'aside' post formats archives, but is not applied on my homepage, which displays an overview of my last 10 posts. In additon, in the backend your script is also applied perfectly, as I can see when I create a new post. However, your script has the side effect of displaying these words in English instead of Dutch in the backend menu: - Posts, Posts --> Add new, Posts --> Categories. - Pages, Pages --> Add new. - Media --> Add new. Very strange, haha. Any suggestions? Thanks – Bark Berendsen Sep 11 '18 at 12:57
  • Sorry, regarding side effect - I returned the wrong value. The filter should return first argument which is $translation. Fixed in my answer. – Tim Sep 11 '18 at 14:56
  • Regarding overview on your home page. Perhaps this uses a different string (from your theme perhaps). I'd need to see the code. My answer is for your example code only – Tim Sep 11 '18 at 14:58
  • Awesome Tim! Your adjustment of your script works on all ends :-) So the backend side effects are gone as well as the wrong displayal of the translation on the homepage. I am sincerely grateful to you. – Bark Berendsen Sep 12 '18 at 11:43
-1

This will help:

<?php
add_filter( 'gettext', 'added_translation', 20, 3 );

function added_translation( $text )
{
    // Search for the string and replace it with translation
    $text = str_replace( 'Aside', 'Aan de kant', $text );

    return $text;
}

More about gettext filter.

  • Hi Max, thank you for your input. Unfortunately, just like the other options it does not work. I have added the script first to my functions.php of my Child Theme and afterwards to my Parent Theme, just to rule that out. I have changed the translation in the default Wordpress language file (in the folder /wp-content/languages) and that results in the immediately display of the new translation in the front and back end without clearing cache. Any idea what the reason might be your script does not work? Thanks and regards, Bark – Bark Berendsen Sep 11 '18 at 9:44
  • It doesn't work because it's the wrong filter for strings with context. Plus, the $text argument would contain the translation (if found) and not the source text. – Tim Sep 11 '18 at 10:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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