Skip Navigation

[Resolved] How to translate CRED button without using WPML

This thread is resolved. Here is a description of the problem and solution.

Problem:
A CRED form that includes a repeating custom field has the "Add new" button. Client is not using WPML with String Translation and is using an alternative which is unable to translate that text.

Solution:
The string is registered with the wpv-views text domain.

This simple code snippet (added to the theme's functions.php file or using a plugin such as Code Snippets) can be used to translate the text:

add_filter( 'gettext', 'tssupp_custom_translate', 20, 3 );
/**
 * @link http://codex.wordpress.org/Plugin_API/Filter_Reference/gettext
 */
function tssupp_custom_translate( $translated_text, $text, $domain ) {
 
    if ( $text == 'Add new' && $domain = 'wpv-views' ){
        $translated_text = "translation";
    }
 
    return $translated_text;
}
This support ticket is created 6 years, 9 months ago. There's a good chance that you are reading advice that it now obsolete.

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.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+00:00)

This topic contains 4 replies, has 2 voices.

Last updated by selmoK 6 years, 9 months ago.

Assisted by: Nigel.

Author
Posts
#609930

I am using some post type fields that allow multiple instances, like address and phone.
On the CRED form, it appears "add new" option and it is not translated.
I have translated the message "add new taxonomy" text but i can´s see an option for fields.

#610080

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Screen Shot 2018-01-26 at 08.45.33.png

Hi there

Are you using WPML?

The "Add new" text is registered with the text domain wpv-views, so if you go to WPML > String Translation and search the wpv-views domain for "add new" you will find the string available for translation, see my screenshot...

#610224

I am using "Loco" plugin to translate. I saw on another support question a solution to use a php function (https://toolset.com/forums/topic/how-to-translate-the-clear-button/). Can i use a hook to translate the "add new" message?

------------------
add_filter( 'gettext', 'clear_button_func', 20, 3 );
/**
* @link http://codex.wordpress.org/Plugin_API/Filter_Reference/gettext
*/
function clear_button_func( $translated_text, $text, $domain ) {
if($text == 'Clear' && $domain = 'wpv-views'){
$translated_text = "Clear Cn";
}
return $translated_text;
}
--------------------

#610614

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Yes, you can employ the same solution, adding the following to your theme's functions.php file

add_filter( 'gettext', 'tssupp_custom_translate', 20, 3 );
/**
 * @link http://codex.wordpress.org/Plugin_API/Filter_Reference/gettext
 */
function tssupp_custom_translate( $translated_text, $text, $domain ) {

    if ( $text == 'Add new' && $domain = 'wpv-views' ){
        $translated_text = "translation";
    }

    return $translated_text;
}

You should just need to edit the text you want Add new translated to.

#610925

Nigel,
It worked fine!

Thank you very much.