Skip Navigation

[Resolved] Cant translate realtionship buttons

This support ticket is created 2 years, 7 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.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9: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/Karachi (GMT+05:00)

This topic contains 5 replies, has 2 voices.

Last updated by Waqar 2 years, 7 months ago.

Assisted by: Waqar.

Author
Posts
#2358713
Screenshot 2022-05-09 at 08-31-53 Pridať nový Inzerát ‹ Doležel Reality — WordPress.png

I am trying to: translate relationship buttons in backend. I have only one language - SLovak language.

Link to a page where the issue can be seen:

I expected to see:

I try translate it with loco translate, but strings dont show up in loco editor. I try some php snippets found in you support forum (gettext thing) but its dont works. thanks for help
How to translate it without wpml?
Instead, I got:

#2359483

Hi,

Thank you for contacting us and I'd be happy to assist.

On my test website, I was able to use the filter "gettext" ( https://developer.wordpress.org/reference/hooks/gettext/ ) to change the text of that relationship button:


add_filter( 'gettext', 'custom_relationship_button_label', 20, 3 );
function custom_relationship_button_label( $translated_text, $text, $domain ) { 
    switch ( $translated_text ) {
        case 'Connect existing %s' :
            $translated_text = __( 'New Text %s', 'wpcf' );
        break;
    }
    return $translated_text;
}

Please feel free to change the text "New Text" as needed.

Note: The above code snippet can be included through either Toolset's custom code feature ( ref: https://toolset.com/documentation/adding-custom-code/using-toolset-to-add-custom-code/ ) or through the active theme's "functions.php" file.

regards,
Waqar

#2359539
Screenshot 2022-05-10 at 09-04-26 Settings ‹ Doležel Reality — WordPress.png

Thank you, works great. I just forgot on "%s".
BTW its possible to write translations in one snippet? Because for now I must created separated snippets for every single button.
Thank you.

#2359915

Thanks for the update and glad that it worked.

Yes, you can include multiple functions or code snippets within a single custom code snippet item, when using the Toolset's custom code feature.

#2360027

Great, so you have php code to achieved that?

#2360629

I'm sorry, I thought you were referring to adding general code snippets and not the snippet for the "Connect existing" buttons for each post type.

The way that the button's output is generated, a common output uses a fixed text string "Connect existing" with the "%s" part controlling the dynamic singular post type name. You should be aiming to translate the fixed string part in a way that, it looks good with the dynamic part.

If you have some different requirement in mind, please share more specific details, and I'll be in a better position to guide you accordingly.