Translation Theme Doesn't work

Hi there. I have a problem with translating my theme. I translated based on your documentation. in the past 3 months it worked correctly. but with later updates of theme and woocommerce it doesn’t. My comment section under posts translated perfectly but my Comment section under products page is still in english.

Be the First to Review
Your Comment
Your Name
Your Email
Submit Review
I translated above strings in my .po file. I’m confused now!!! I read many articles related to translation topic here but none of them couldn’t help me.
My site is in Kurdi Sorani language BTW.

My Website Address

Hi Soran,

Thanks for writing in! I see that some of the strings (Be the First to Review, Submit Review) is not included in the latest version of X theme’s x.pot file.

For those specific strings, you can setup a child theme (https://theme.co/apex/forum/t/setup-how-to-setup-child-themes/57), activate it, then use the following method to translate your strings (https://theme.co/apex/forum/t/pro-translation-doesnt-work-at-all/41929/6?u=mldarshana) and add it into your child theme’s functions.php file.

Thanks!

1 Like

Yes you’re right. They aren’t in new x pot file. but they are in woocommerce .po file. I translated them but they down’t show in comment section under products!
I could fix some strings in functions.php file. but I still can’t translate 2 strings with code you mentioned in second link.
** review for **
** Add a Review **

these 2 strings don’t work.

Hi Soran,

Can you share the code that you have added in your functions.php file.

Please try this code instead.

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

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

        switch ( $translated_text ) {

            case 'Review For' :

                $translated_text = 'Your translation here';

                break;

            case 'Add a Review' :

                $translated_text = 'Your translation here';
                
                break;
        }


    return $translated_text;
}

Please change Your translation here accordingly

Thanks

Hi Paul. Thanks for your reply. I added below code to my functions.php file. the last 2 strings are still in english. But the first 5 strings translated well in front end.

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

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

        switch ( $translated_text ) {

            case 'Be the First to Review' :

                $translated_text = 'ببە یەکەم کەس کە تێبینی خۆی دەنووسێت دەربارەی';

                break;

            case 'Your Comment *' :

                $translated_text = 'تێبینی ئێوە *';
                
                break;
		    case 'Your Name *' :

                $translated_text = 'ناو *';
                
                break;
			case 'Your Email *' :

                $translated_text = 'ئیمەیل *';
                
                break;
			case 'Submit Review' :

                $translated_text = 'ناردنی تێبینی';
                
                break;
			case 'review for' :

                $translated_text = 'تێبینی نووسراوە بۆ ';
                
                break;
			case 'Add a Review' :

                $translated_text = 'تێبینی خۆتان زیاد بکەن';
                
                break;
        }


    return $translated_text;
}

Hi There,

Please update your code into this:

add_filter( 'gettext', 'change_language_string', 20, 3 );
add_filter( 'ngettext', 'change_language_string', 20, 3 );
function change_language_string( $translated_text, $text, $domain ) {

        switch ( $translated_text ) {

            case 'Be the First to Review' :

                $translated_text = 'ببە یەکەم کەس کە تێبینی خۆی دەنووسێت دەربارەی';

                break;

            case 'Your Comment *' :

                $translated_text = 'تێبینی ئێوە *';
                
                break;
		    case 'Your Name *' :

                $translated_text = 'ناو *';
                
                break;
			case 'Your Email *' :

                $translated_text = 'ئیمەیل *';
                
                break;
			case 'Submit Review' :

                $translated_text = 'ناردنی تێبینی';
                
                break;
			case '%s review for %s' :

                $translated_text = '%s تێبینی نووسراوە بۆ %s';
                
                break;
			case '<span>Add a Review</span>' :

                $translated_text = 'تێبینی خۆتان زیاد بکەن';
                
                break;
        }


    return $translated_text;
}

The %s review for %s string is using the _n function, so we have to hook to the ngettext filter instead. For more information, please take a look at this:

https://developer.wordpress.org/reference/functions/_n/

Regards!

1 Like

Hi Thai
Thanks for your answer. You’re my hero man. It worked.
My theme translated very well.
Thank you soooooooooo much again.
best wishes.

1 Like

You’re welcome. Glad we’re able to help.

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