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: enlace oculto

Minesh
Colaborador
Idiomas:
Inglés (English )
Zona horaria:
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);
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?
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);
Hi Minesh,
I changed it exactly as you mentioned, but now I get an error message if I visit the page
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.
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.
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);
Great, thank you, that resolved the issue!