Im looking for the best way to translate Custom Fields labels. Im not looking for translating their values inserted by the user, just the labels and backend instructions.
Is there a recommended approach to this?
Hi @lmartins
I don’t think you can do it with field created with the admin interface. However if you register your fields with php: http://www.advancedcustomfields.com/resources/register-fields-via-php/
You could probably wrap the label values in __(‘yourlabel’, ‘yourlangaugelocale’)
Hi, sorry to bump this slightly old thread but I thought it better than creating a new one.
I am currently trying to solve the same problem that @lmartins had. I have taken your advice, and exported the fields to PHP then modified so that the label values are wrapped in the translate function __(). I then created a .mo file and included this into my theme. The translation is working if I call the label directly from my theme, but not in ACF either in admin or frontend using acf_form().
I’ve tried a few things such as bundling ACF into the theme, changing the order of includes, etc but no success. What is confusing is that some of the labels are being translated by, I guess, the core. So perhaps this is related to this issue: http://support.advancedcustomfields.com/forums/topic/acf-automatically-translate-some-field-name/
Any help/hints would be greatly appreciated. Thanks.
Hi @jonathan
Yes, that has worked. Thank you. It does mean overwriting acf-ja.mo/.po though, or is there a way to safely append translation files? (Sorry, realise that question is slightly out of scope).
Hi @davewardle
Okay that’s good.. What are you using to do the translation?
as you say it’s not really future-proof since your file will be overwritten next time you update.
Hi @jonathan
I have the same issue then @davewardle, except I am not using forms. I managed to set up the field labels and WPML is seeing the strings and I am able to translate the labels. My question is what can get lost when updating acf? If I keep my ields saved as php plus the translation mo and po files it would be a matter of reuploading these, or what are the risks?
Sorry, still new at WordPress development.
I stumbled upon this topic when trying to translate field label & instructions myself, I registered my fields using the PHP acf_add_local_field_group();
functionality but just as the others in this topic the strings translated using __('yourlabel', 'yourlangaugelocale')
weren’t outputted in the locale lang set.
I couldn’t find any other post about it so for any others having the same issue I managed to resolve the issue by adding a field filter where I utilize the __('yourlabel', 'yourlangaugelocale')
functionality again, see example below:
add_filter('acf/load_field', 'translate_acf_fields');
function translate_acf_fields( $field ) {
// Don't run on acf-field-group page
if( get_post_type( get_the_ID() ) == 'acf-field-group' ) {
return $field;
}
// Translate backend labels/titles/instuctions
$field['label'] = __( $field['label'], 'Weblenn' );
$field['instructions'] = __( $field['instructions'], 'Weblenn' );
return $field;
}
Note: You still need to register the strings in acf_add_local_field_group()
to be able to use a tool to create your mo/po files.
The topic ‘Best way to translate field labels’ is closed to new replies.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.