Support

Account

Home Forums Add-ons Flexible Content Field Layouts label translation missing

Solved

Layouts label translation missing

  • Actually it’s not possible to translate the labels that represent each block layout in a flexible content field.

    During php export theese labels are not wrapped into the __() i10n function.

    Layout labels are shown in the post edit screen both in the popover menu (that show up clicking the “add element” button) as well as the title of any layout block added.

    Using the filter acf/fields/flexible_content/layout_title could be useful to partially resolve the problem, but this filter does not apply to the popover menu.

    I’ve attached two screenshots to better explain the issue.

  • Hi @virgodesign

    You should be able to fix it by using this code:

    function my_acf_fix_layout_translate( $field ) {
        
        if( $field['type'] == 'flexible_content' ){
            foreach( $field['layouts'] as $k => $layout ){
                $field['layouts'][$k]['label'] = acf_translate( $field['layouts'][$k]['label'] );
            }
        }
        
        return $field;
    
    }
    
    add_filter('acf/translate_field', 'my_acf_fix_layout_translate');

    I hope this helps 🙂

  • Hi @acf-support

    thank you very much, this code snippet solve the problem.
    I did not know about the existance of it.

    But I wish to say that, however, any label that are exposed to the public such as layout label and button label (in flexible content) as well as button label (in repeater field) should be all wrapped into the __() function by default.

    Really, The snippet solve the problem perfectly, but Elliot should consider the suggestion to include even this labels into the acf translation process.

    Anyway I’ve improved the snippet code including other labels that needs translations:

    function my_acf_fix_layout_translate( $field ) {
        
    	//flexible content
        if( $field['type'] == 'flexible_content' ){
    		//layout labels
    		foreach( $field['layouts'] as $k => $layout ){
                $field['layouts'][$k]['label'] = acf_translate( $field['layouts'][$k]['label'] );
            }
    		//button label
    		$field['button_label'] = acf_translate( $field['button_label'] );
        }
    	
    	//repeater
    	if( $field['type'] == 'repeater' ){
    		//button label
    		$field['button_label'] = acf_translate( $field['button_label'] );
        }
        
        return $field;
    
    }
    
    add_filter('acf/translate_field', 'my_acf_fix_layout_translate');

    Thank you very much again.

Viewing 3 posts - 1 through 3 (of 3 total)

The topic ‘Layouts label translation missing’ is closed to new replies.