Can't translate

Hi
I’m trying to translate the theme, but I’m having problems, thanks for your help.

1: .mo and .po files are not recognized. I folowed the instructions (https://theme.co/docs/theme-translations), my files are here /wp-content/themes/pro-child/languages. I put the string via Code Snippet:

function load_child_language() {
load_child_theme_textdomain( ‘x’, get_stylesheet_directory() . ‘/languages’ );
}
add_action( ‘after_setup_theme’, ‘load_child_language’ );

But nothing changes.

  1. I tried to translate with functions. I worked sometime, but not for all strings. For ex:

// Traduire Commentaires
add_filter( ‘gettext’, ‘x_translate_comments’, 9999, 3 );
function x_translate_comments( $translated, $text, $domain ) {
if($text==‘Comments’) return ‘Commentaires’;
else return $translated;
}

Thanks for your help!

Hi @Cormoran42,

Thanks for reaching out.
Please find the answer to your queries below.

  1. Can you please add the .po and .mo into the framework > lang folder of your Child Theme and check if that works?

  2. To change the Comments text, you can use the following code

     function custom_gettext( $translated_text, $untranslated_text, $domain )
     {       
         if( FALSE !== stripos( $untranslated_text, 'Comments' ) )
         {
                 $translated_text = str_ireplace( 'Comments', 'Commentaires', $untranslated_text ) ;
         }
         return $translated_text;
     }
     add_filter( 'gettext', 'custom_gettext', 99, 3 );
    

Please remember that the above code will work if copied as it is and doesn’t conflict with any existing style.
Please note that the code provided serves only as a guide to help you get started custom coding on your own if there’s no option offered in our theme or the products we bundle.
We really do not provide support for custom codes which means we can’t fix it in case it conflicts with something on your site nor will we enhance it. Further customization should be directed to a third-party developer or you can avail of One, where we answer the questions beyond normal theme support.

Thanks

Hi
thanks for your help, unfotunatelly both method still don’t work.
thanks for your help

Hello @Cormoran42,

To better assist you with your issue, please provide us access to your site so that we can investigate further. You can create a secure note in your next reply with the following info:
– Link to your site
– WP login URL
– WP username
– WP password
– WP Administrator Role
– Confirmation that we can access and make changes to your site

To know how to create a secure note, please check this out: How The Forum Works

image

Best Regards.

Hi, Here you can access my staging site. You can check if the translation are correcly loaded by clicking on the search button (top right), it should show “Recherche” insted of “search”.

Hello @Cormoran42,

I have checked your child theme and I do not see the languages folder or the code related to it.

And by the way, you may need to check out this old threads for a bulletproof translation:

Kindly let us know how it goes.

Hi
I put the files in the framework > lang as you requested.

Capture d’écran 2022-11-09 à 13.12.31

and the code is added via code snippet plugin:

Hi @Cormoran42,

There are two different textdomains used here, one is x and another one is cornerstone. So you need to add the code for both and it would look like the following.

function load_child_language() 
{
    load_child_theme_textdomain( '__x__', get_stylesheet_directory() . '/languages' );
    load_child_theme_textdomain( 'cornerstone', get_stylesheet_directory() . '/languages' );
}
add_action( ‘after_setup_theme’, ‘load_child_language’ );

And the following language files need to be added to the pro-child/languages path, not to the pro-child/framework/lang path you added.

__x__-fr.mo
__x__-fr.po
cornerstone-fr.mo
cornerstone-fr.po

Hope it helps.
Thanks

ok but I can’t find the original cornerstone file, where is it please?

Hello @Cormoran42,

You can find the pro.pot file in wp-content/themes/pro/framework/lang if you are using the Pro theme.
You can find the x.pot file in wp-content/themes/x/framework/lang if you are using the X theme.
And then you can find the cornerstone.pot file in wp-content/plugins/cornerstone/lang if you are using the Cornerstone as a stand alone plugin.

Best Regards.

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