Translation pb

Hello,

I did not manage to translate two words:

I am using the following code which works fine for other translation but not those one - no idea why:

    add_filter( 'gettext', 'translate_x_strings', 20, 3 );

    function translate_x_strings( $translated_text, $text, $domain ) {

            switch ( $translated_text ) {

                case 'Search' :

                    $translated_text = __( 'Recherche', '__x__' );
                    break;
    				
    			case 'Read More' :

                    $translated_text = __( 'Lire la suite', '__x__' );
                    break;
    				
    			case 'Reply' :

                    $translated_text = __( 'Repondre', '__x__' );
                    break;
    				
    			
    			case 'at' :

                    $translated_text = __( 'a', '__x__' );
                    break;
    				
            }

        return $translated_text;
    }

URL: https://modele-site-restaurant.neowebsite.io/1/2018/12/17/hello-moi-cest-louise-la-redactrice-pour-bamboo/

Hello @Lecoqdigital,

Thanks for writing in!

To resolve your issue, please update your code into this:

    add_filter( 'gettext', 'translate_x_strings', 20, 3 );

    function translate_x_strings( $translated_text, $text, $domain ) {

            switch ( $translated_text ) {

                case 'Search' :

                    $translated_text = __( 'Recherche', '__x__' );
                    break;
    				
    			case 'Read More' :

                    $translated_text = __( 'Lire la suite', '__x__' );
                    break;
    				
    			case 'Reply <span class="comment-reply-link-after"><i class="x-icon-reply" data-x-icon-s="&#xf3e5;"></i></span>' :

                    $translated_text = __( 'Repondre <span class="comment-reply-link-after"><i class="x-icon-reply" data-x-icon-s="&#xf3e5;"></i></span>', '__x__' );
                    break;
    				
    			
    			case '%1$s at %2$s' :

                    $translated_text = __( '%1$s a %2$s', '__x__' );
                    break;
    				
            }

        return $translated_text;
    }

You should be able to find this if you have translated x.pot file. For more details on how you can properly translate the theme, you might need to check out this article:

Hope this helps.

Thank you!

You are most welcome!

I notices that the code you’ve provide in order to translate “reply” does not work on every website. Please see here: https://modele-site-loisir-passion.neowebsite.io/1/hello-world/#respond

Note that it works on all other websites I used it. Could you please explain me how to make it work on the URL above?

Moreover, I tried to translate “comments” and “on” using the same code structure and it did not work:

case ‘Comment’ :

            $translated_text = __( 'Commentaire', '__x__' );
            break;
			
		case 'Comments' :

            $translated_text = __( 'Commentaires', '__x__' );
            break;
			
		case 'on' :

            $translated_text = __( 'pour', '__x__' );
            break;

Thanks,
Antoine

Hey Antoine,

You need to use the actual translatable text in the theme.

For the comments title, the cases are:

case 'One Comment on %2$s' :
case '%1$s Comments on %2$s' :

For the Reply text under the avatar, it’s:

case 'Reply <span class="comment-reply-link-after"><i class="x-icon-reply" data-x-icon-s="&#xf3e5;"></i></span>' :

All the translatable text can be found in the .pot file in the theme’s *\framework\lang* folder.

Thanks.

Thank you for the explanation, I used the following code and it’s unfortunately not working though:

case 'One Comment on %2$s' :

            $translated_text = __( 'Commentaire', '__x__' );
            break;
			
		case '%1$s Comments on %2$s' :

            $translated_text = __( 'Commentaires', '__x__' );
            break;

Sorry for the confusion. For the comment texts, it uses _n() so they can’t be translated with gettext. ngettext should be used instead.

add_filter(  'ngettext',  'translate_plurals'  );

function translate_plurals( $translated ) {
 
     $strings = array(
            'One Comment on %2$s' => 'Uno Commento on %2$s',
            '%1$s Comments on %2$s' => '%1$s Commento on %2$s',
            );
 
     $translated = str_ireplace(  array_keys($strings),  $strings,  $translated );
  
     return $translated;
}

The methods we’ve shown you here would be enough for you to translate other strings. Please just note that those methods of translation are not recommended as you could easily introduce an error when custom coding and fixing custom code is not a part of our support service.

For ease of translation, I’d strongly recommend that you use the standard / recommended translation method in our Translation Guide at https://theme.co/apex/forum/t/setup-translation/61. Or, use a third party translation plugin.

Thanks.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.