Skip Navigation

[Resolved] Translate -Not set- in a post form

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 timv-8 2 weeks, 2 days ago.

Assisted by: Minesh.

Author
Posts
#2819868
Toolset translation 2.png
Toolset translation.png

Tell us what you are trying to do?
I am trying to translate the text -not set- and ''Add new'' to the local language of the website which is Dutch.

Is there any documentation that you are following?
No, I could only find ways to use WPML to do this, but I only need to translate this specific word. I am not trying to create a multilingual website.

Is there a similar example that we can see?
Not really, I was able to translate all other items with the build in options of Toolset, but these items I was not able to find any way to translate them.

What is the link to your site?
You can see it live here: hidden link

#2819943

Minesh
Supporter

Languages: English (English )

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

Hello. Thank you for contacting the Toolset support.

You will have to use the gettext filter in order to translate the "not set" text.

Normally, you can add the following code to "Custom Code" section offered by Toolset:
=> https://toolset.com/documentation/programmer-reference/adding-custom-code/using-toolset-to-add-custom-code/

add_filter('gettext', function($res, $text, $domain ){
    if( $res == '--- not set ---' && $domain = 'wpv-views' ){
        $res = 'custom text not set';
    }

     if($text == 'Add new' && ($domain == 'wp-cred' or $domain = 'wpv-views')){
      $translated_text = "Aggiungi";
    }
      
     
    return $res;
}, 10, 3);
#2819957
Toolset translation 3.png

Hi Minesh,

The first part of the snippet works to translate the text -not set- but the second part doesn't seem to work for some reason. I have pasted the code I used below:
------------------------------
<?php
/**
* To translate -not set- and add new text on forms.
*/

toolset_snippet_security_check() or die( 'Direct access is not allowed' );

// Put the code of your snippet below this comment.

add_filter('gettext', function($res, $text, $domain ){
if( $res == '--- not set ---' && $domain = 'wpv-views' ){
$res = 'Maak een keuze';
}

if($text == 'Add new' && ($domain == 'wp-cred' or $domain = 'wpv-views')){
$translated_text = "Toevoegen";
}

return $res;
}, 10, 3);
-----------------------------
In the second part of the code I only changed ''Aggiungi'' to "Toevoegen". Could you let me know what is going wrong here?

#2819966

Minesh
Supporter

Languages: English (English )

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

Can you please try to use the following code and check if that help you to resolve your issue.

add_filter('gettext', function($res, $text, $domain ){
if( $res == '--- not set ---' && $domain = 'wpv-views' ){
$translated_text = 'Maak een keuze';
}

if($text == 'Add new' && ($domain == 'wp-cred' or $domain = 'wpv-views')){
$translated_text = "Toevoegen";
}

return $translated_text;
}, 10, 3);
#2819969
Toolset translation 4.png

Hi Minesh,

I changed it exactly as you mentioned, but now I get an error message if I visit the page

#2819974

Just for your information, I changed it back to the previous code. It did not only break that specific page, but the entire front-end of the website. It had the same error on all pages.

#2819975

Sorry for sending it in 3 different messages, but I have seen that you changed the first part of the code that changes the translation of -not set- but this part of the code was already working properly.

It's the second part of the code to change the translation of ''Add new'' that doesn't work.

#2819976

Minesh
Supporter

Languages: English (English )

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

What if you try to use the following code:

add_filter('gettext', function($res, $text, $domain ){
if( $res == '--- not set ---' && $domain = 'wpv-views' ){
$res= 'Maak een keuze';
}
 
if($text == 'Add new' && ($domain == 'wp-cred' or $domain = 'wpv-views')){
$res= "Toevoegen";
}
 
return $res;
}, 10, 3);
#2819977

Great, thank you, that resolved the issue!