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:
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
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.
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.
Great, so you have php code to achieved that?
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.