Translation Portfolio

Hello,

I’d like to change some word which are in English, as my website is in French. Could you please explain me how to do it?

  1. URL: https://modeles.neowebsite.io/site-internet-agence/portfolio-item/projet-6/

  2. URL: https://modeles.neowebsite.io/site-internet-agence/nos-realisations/

Thanks,
Antoine

Hi @Lecoqdigital,

Thanks for reaching out.

You can’t translate the post type slug, but, if it’s just a single language site then you can just edit it in Theme Options > Portfolio > CUSTOM URL SLUG . Then go to Admin > Settings > Permalinks and re-save it to make sure the new permalink for portfolio is applied. Then, you can change the labels there too

Then for the filter by category, assuming you’re only changing the wording and not actually translating it then add this code to your child theme’s functions.php

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

function x_change_text( $translated_text, $untranslated_text, $domain ) {

    if ( $untranslated_text == 'Filter by Category') return 'YOUR TEXT HERE';

    return $translated_text;

}

Just make sure to change the YOUR TEXT HERE with your preferred word.

Thanks!

Thanks for the explanation.

What do you mean by “”? I simply need something that works for all the translation I need to do. I tried to apply the same code in order to do other changes but it’s not working. No idea if my code is wrong or if it can’t be used in thoses cases. If the solution is to use a translation plugin such a Loco Translat, I will then do it. All I need is to understand how it works and what the best practice is.

Here is the code I used which is only working for “filter by category”:
add_filter(‘gettext’, ‘x_change_text’, 20, 3);

function x_change_text( $translated_text, $untranslated_text, $domain ) {

if ( $untranslated_text == 'Filter by Category') return 'Filtrer par catégorie';
	if ( $untranslated_text == 'Launch Project) return 'Lancer Projet';
	if ( $untranslated_text == 'See it Live!') return 'Le voir en ligne !';

return $translated_text;

}

Hi there,

If you want to translate many texts, please try this code instead:

// Translate Strings
add_filter( 'gettext', 'translate_x_strings', 20, 3 );

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

        switch ( $translated_text ) {

            case 'Filter by Category' :

                $translated_text = __( 'Filter by Category Translation', '__x__' );
                break;

            case 'Launch Project' :

                $translated_text = __( 'Translation here.', '__x__' );
                break;

            case 'See it Live' :

                $translated_text = __( 'Translation here.', '__x__' );
                break;
        }

    return $translated_text;
}

Hope this helps.

Thank you very much!

You’re most welcome!

I did not manage to translate the text of the search using the same code. How can I change it?

Hi there,

Please try:

// Translate Strings
add_filter( 'gettext', 'translate_x_strings', 20, 3 );

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

        switch ( $translated_text ) {

            case 'Filter by Category' :

                $translated_text = __( 'Filter by Category Translation', '__x__' );
                break;

            case 'Launch Project' :

                $translated_text = __( 'Translation here.', '__x__' );
                break;

            case 'See it Live' :

                $translated_text = __( 'Translation here.', '__x__' );
                break;

            case 'Type and Press “enter” to Search' :

                $translated_text = __( 'Translation here.', '__x__' );
                break;

        }

    return $translated_text;
}

Hope this helps.

It works. Thank you.

You are most welcome. :slight_smile:

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