Tell us what you are trying to do?
Hi, how can I set this filter to work only in a specific language?
Is there any documentation that you are following?
if I use this example
add_filter('gettext', 'mycustom_func', 10, 2);
function mycustom_func($translated_text, $domain){
if($domain != 'wpv-views') return $translated_text;
if($translated_text == 'Username or Email'){
$translated_text = 'Benutzername';
}
if($translated_text == 'Get New Password'){
$translated_text = 'Passwort zurücksetzen;
}
return $translated_text;
}
I get translated_text in all language, but I want to show this only in one language
I use wpml but this is a solution for placeholder upload image button.
Thanks
Toolset does not determine or set a language
You can get the current language from pr with WPML's API:
https://wpml.org/documentation/support/wpml-coding-api/
I think then you could add a condition to fire the filter only if the current language is XY or inside your function only apply the changes if the current language is XY
Can I know what button precisely you need to translate so complicatedly?
You can translate most, if not all, Toolset generated Strings in WPML already.
But we might miss some, then we need to adjust that.
Can you help me replicating this locally by providing some steps, so I can then either escalate or help you with further ideas?
Hi Beda,
simply I need a solution for "upload or select media" cred button.
Here I can set select_label in Italian: select_label="Carica immagine" but i not find "carica immagine" in wpml string.
So I try another solution like gettext:
add_filter('gettext', function($translated_text, $untranslated_text, $domain){
if($untranslated_text == 'Upload or select image' && $domain == 'wp-cred'){
$translated_text = 'Carica o seleziona immagine';
}
return $translated_text;
}, 10, 3);
So I wish to have a solution to manage select_label in wpml or a filter to add in gettext to fire the code only in italian language.
Thanks
There is no such string in Toolset Forms "upload or select media" as mentioned in your comment above.
Can you please explain precisely what string of what button you want to translate?
For example Forms lets you add images for:
- Featured Image (the string is translated already)
- The fields or other images of the post
- other
==> There is a difference of whether you use or not the Forms setting "Use the WordPress Media Library manager for image, video, audio, or file fields"
When you have that setting active, the String will change for the Button as it's not anymore browser induced, the entire interface to upload images changes.
In this case, the string is "Upload or select image".
Is this the string you refer to? I see you mention it in the code snippet, hence that could be it.
This string is properly localized in the Forms Code and you will be able to translate it with WPML (please refer to WPML Support, for precise help about how to translate Plugin Strings with WPML).
This is the code that registers the string:
$select_label = __( 'Upload or select image', 'wp-cred' );
It is localized with __() function which means, WPML will pick it up and you can then translate it for each language in WPML.
You will find it under the domain "wp-cred"
Yes i'm using the Forms setting "Use the WordPress Media Library manager for image, video, audio, or file fields"
but no, in wp-cred wpml domain string or all domain I not find any results for 'Upload or select image'.
Very strange, ok do I have to open a ticket from the wpml site? Or have you another idea?
Please check with WPML Support why strings are not translatable, yes.
I can clearly see this string in WPML (see screenshot)
Maybe you just need to scan the strings with WPML?
I confirm, on other website I have the wpml string too..
Very strange, on this solution, do you know how can I fire the code only in italian language selection?
add_filter('gettext', function($translated_text, $untranslated_text, $domain){
if($untranslated_text == 'Upload or select image' && $domain == 'wp-cred'){
$translated_text = 'Carica o seleziona immagine';
}
return $translated_text;
}, 10, 3);
The solution is to translate this string with WPML.
If the string is not appearing after the mentioned steps please enter in contact with WPML support.
As mentioned to check what language you are currently on, in Custom PHP Code, you can use the WPML API elaborated here: https://wpml.org/documentation/support/wpml-coding-api/