Home › Forums › ACF PRO › Best way to translate field labels › Reply To: Best way to translate field labels
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.
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!
Accordions are a great way to group related information while allowing users to interactively show and hide content. In this video, Damon Cook goes in-depth on how to create an accessible accordion block using ACF PRO’s Repeater field.https://t.co/RXT0g25akN
— Advanced Custom Fields (@wp_acf) March 2, 2023
© 2023 Advanced Custom Fields.
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.