Skip Navigation

[Resolved] Toolset translations deleted in functions-php after WP update

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

This topic contains 7 replies, has 1 voice.

Last updated by nicolaS-3 1 day, 18 hours ago.

Assisted by: Minesh.

Author
Posts
#2783060

Hi
I have noticed that after updating WP the functions.php is often reset and I loose all Toolset translations I've added. I have tried moving them to the functions.php in the Kadence theme, but they don't seem to work.
I've also tried to create a plugin for this as explained here
https://stackoverflow.com/questions/64754090/wordpress-code-added-to-functions-php-disappears-after-update
but it doesn't seem to work either.
Any suggestion about where to best place them so that are not deleted at every WP update ? thanks
Best regards
Nicola

<?php /*
   Plugin Name: Toolset translations
   Description: Translates some Toolset labels
   Author: Nik
   Version: 1.0
   */
   
add_filter( 'gettext', function( $translated_text, $text, $domain ) {
    if($text == 'Search for a post' && $domain == 'wp-cred'){
      $translated_text = "Cerca un post";
    }
:
---------- other translations ---------
:
    return $translated_text;
}, 10, 3 );
#2783076

I found out that actually adding the code to the Kadence theme works, but what happens when the theme is updated ? same issue ?

#2783077

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

Well - what if you try to add the "gettext" hook to custom code section offered by Toolset:

Please check the following doc:
- https://toolset.com/documentation/programmer-reference/adding-custom-code/using-toolset-to-add-custom-code/#benefits-of-adding-custom-code-using-toolset

#2783092

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Yes - when you update the theme it may override the functions.php file of the theme.

As shared:
- what if you try to add the "gettext" hook to custom code section offered by Toolset:

Please check the following doc:
- https://toolset.com/documentation/programmer-reference/adding-custom-code/using-toolset-to-add-custom-code/#benefits-of-adding-custom-code-using-toolset

#2783552

Hello Minesh,
I moved the translation filter to the Custom Code section and it works BUT one translation that is not implemented:

if($text == 'Show/Hide coordinates' && ($domain == 'wp-cred' or $domain == 'wpv-views' or $domain == 'toolset-maps')){
$translated_text = "My translation";

previously it was. Any clue ?
Thanks
Regards
Nicola

#2783905

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

I'm not sure why is that.

What if you move that translation to it's original place, do you see it working?

#2784042
address2.jpg

Hi,
yes, it works! As stated in my other ticket, I restored the site to the previous version where transltations were in the functions.php, see attachment. Weird, isn'it ?

#2784262

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

As you can see with the following related ticket:
- https://toolset.com/forums/topic/cant-translate-labels-in-english/page/2/#post-2551493

To translate few strings, you will have to add the gettext filter to your theme's functions.php file due to its priority as Toolset custom code will be added early as stated with our Doc:
- https://toolset.com/documentation/programmer-reference/adding-custom-code/using-toolset-to-add-custom-code/#snippet-execution-timing

What you should do is, you should create a child theme and add the gettext filter to child theme's functions.php file. So, when parent theme is updated with any possible future updates, your code will stay intact with child theme's functions.php file.

More info:
- hidden link

#2784744

Thank you Minesh, I have created the child theme and it works fine now
thanks
Regards
Nicola