Skip Navigation

[Resuelto] Repeatable fields are not translated in custom cells

Este hilo está resuelto. Aquí tiene una descripción del problema y la solución.

Problem: I am unable to display translated fields in Layouts custom cells with WPML. The fields are saved with translation in the back-end, but the default language is shown on the front-end.

Solution: Update to Layouts 2.4.2

This support ticket is created hace 6 años, 9 meses. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Hoy no hay técnicos de soporte disponibles en el foro Juego de herramientas. Siéntase libre de enviar sus tiques y les daremos trámite tan pronto como estemos disponibles en línea. Gracias por su comprensión.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

Este tema contiene 14 respuestas, tiene 2 mensajes.

Última actualización por Christian Cox hace 6 años, 1 mes.

Asistido por: Christian Cox.

Autor
Mensajes
#619755

I am trying to translate repeatable fields in custom cells placed in layout. I am using WPML translation management. It seems in backend, that fields are saved with translation, but on front-end, there is default language. Custom cell is done exactly like in this tutorial: https://toolset.com/documentation/programmer-reference/layouts-cells-api/.
Thanks in advance.

#619798

I'll be glad to take a look. Can you share the complete contents of your custom cell's PHP file?

#619803

This is custom cell content:

<?php

function register_section_content_init() {

	register_dd_layout_cell_type ('section-content',
		array (
			'name' => __('Sekce obsah', 'abra_software'),
                        'cell-image-url' => get_template_directory_uri().'/dd-layouts-cells/images/section-content.png',
			'description' => __('Buňka pro Sekci obsah', 'abra_software'),
			'category' => __('ABRA buňky', 'abra_software'),
			'button-text' => __('Vložit Sekci obsah', 'abra_software'),
			'dialog-title-create' => __('Vytvořit novou buňku Sekce obsah', 'abra_software'),
			'dialog-title-edit' => __('Upravit buňku Sekce obsah', 'abra_software'),
			'dialog-template-callback' => 'section_content_dialog_template_callback',
			'cell-content-callback' => 'section_content_content_callback',
			'cell-template-callback' => 'section_content_template_callback',
			'cell-class' => 'abcell',
                        'translatable_fields'      => array(
                            'title_content' => array('title' => 'Nadpis obsahu', 'type' => 'LINE'),
                            'content_items[link_text]' => array('title' => 'Text odkazu', 'type' => 'LINE'),
                            'content_items[link_url]' => array('title' => 'URL odkazu', 'type' => 'LINE')
                        )
		)
	);
}
add_action( 'init', 'register_section_content_init' );
 
function section_content_dialog_template_callback() {
        ob_start();
	?>
        <h3>
            <?php _e('Sekce obsah', 'abra_software' ); ?>
        </h3>

        <div class="ddl-form">
            <p>
                <label for="<?php the_ddl_name_attr('title_content'); ?>"><?php _e( 'Nadpis obsahu', 'abra_software' ) ?>:</label>
                <input type="text" name="<?php the_ddl_name_attr('title_content'); ?>">
            </p>

            <h3 class="center">Obsah</h3>
            
            <?php ddl_repeat_start( 'content_items', __( 'Přidat další položku obsahu', 'abra_software' ), 10 ); ?>
            
            <p>
                <label for="<?php the_ddl_name_attr('link_text'); ?>"><?php _e( 'Text odkazu', 'abra_software' ) ?>:</label>
                <input type="text" name="<?php the_ddl_name_attr('link_text'); ?>">
            </p>
            <p>
                <label for="<?php the_ddl_name_attr('link_url'); ?>"><?php _e( 'URL odkazu', 'abra_software' ) ?>:</label>
                <input type="text" name="<?php the_ddl_name_attr('link_url'); ?>">
            </p>
            
            <?php ddl_repeat_end( array( 'additional_wrap_class' => ' ') ); ?>
            
        </div>

	<?php
	return ob_get_clean();
       
}

// Callback function for displaying the cell in the editor.
function section_content_template_callback() {
ob_start();?> 

     <div class="cell-content">
        <p class="cell-name">{{ name }}</p>
     </div>
       <?php
    return ob_get_clean();

}

// Callback function for display the cell in the front end.
function section_content_content_callback($cell_settings) {
	ob_start();
	?>
    
    <section class="section">

            <div class="grid-text medium-up">
                <div class="grid-text__column grid-text__column--top grid-text__column--wide">

                    <div class="content-list content-list--wide">
                        <div class="content-list__title"><?php the_ddl_field('title_content');?></div>
                        <ol>
                            <?php while ( has_ddl_repeater('content_items') ) : the_ddl_repeater('content_items');?>
                            
                            <li><a href="<?php the_ddl_sub_field('link_url');?>"><?php the_ddl_sub_field('link_text');?></a></li>
                            
                            <?php endwhile; ?>
                        </ol>
                    </div>

                </div>
            </div>

    </section>
        
	<?php
	return ob_get_clean();
}

#619815
cc-cell-editor.png
cc-string-trans.png
cc-trans-orig.png
cc-trans-fr.png

The code looks pretty good to me. Try adding a priority parameter to your registration init hook:

add_action( 'init', 'register_section_content_init', 199 );

I copied this code into new custom cell file in my own custom theme, added the priority parameter, and I am able to see translated cell values on the front-end of my site. Please see the attached screenshots.

- cc-cell-editor.png: This shows the cell editor dialog for the custom cell.
- cc-string-trans.png: This shows the cell fields registered for string translation, and translations for different languages.
- cc-trans-orig.png: This shows the original post on the front-end.
- cc-trans-fr.png: This shows the French translations on the front-end. You can see that the T2 value is properly translated as T2 FR.

Please let me know if the priority parameter does not help, and I can take a closer look.

#619825

Unfortunately, it did not help.
Fields, which are not repeatable are translated without problem...

#619830

The exact same code works for me, so there must be something else going on. Please disable all plugins except Toolset and WPML, then test again. If the problem is not resolved, I need to log in to your wp-admin area and see what the problem could be. If I need to make changes or run tests, I will install the Duplicator plugin to create a clone of your site. I can install that locally and run tests without modifying your live site. If you approve, please provide login credentials for me in the private reply fields here.

#619939

We are using WPML Translation management not String translations. Layout is placed in page = content layout. So the procedure is:
- create new blank page
- switch to Content Layout Editor
- place some cells to layout and save
- on list of pages Add translation wia "plus"
- in translation management translate content fields only.
Save and repeatable fields are not translated...

#620181

It is recommended to use String Translation to translate Layouts. There is a warning that appears if you attempt to use Layouts and WPML together without String Translation:

To easily translate Toolset Layouts, you need to add the following WPML components:<br />
- WPML Translation Management<br />
- WPML String Translation

If you ignore this warning, you may not be able to completely translate your Layout in the Translation Editor. I will check to see if there is any workaround to easily translate these fields without String Translation active. Please stand by and I will update you when I have some information to share.

#620188

We have String Translation active, but more practical for translators is do it via Translation managament like other cells in layout. Hope, there is a way how to translate repeatable fields, because it seems to be a bug.

#620198

Okay thank you, I understand better now. The repeated field translations provided in the Translation Editor are not displaying on the front-end. I will pass this information along to the team for more clarification.

#620300

Our lead Layouts developer took a quick look and agrees that this looks like a bug - it seems like the Translation Editor should work for repeating fields just like it works for single fields. I will file an internal ticket for the Layouts team to do a more thorough investigation, and we will update you here when we have something new to share.

#948376

Still not working, is there anything new about translating repeatable fields? This is really urgent! Thanks.

#948500

Hi, I'll check in with the developers but I don't see any news to report just yet. I'll let them know you're following up.

#1088388

I found solution of this problem:
In file /wp-content/plugins/layouts/classes-auto/cells/wpddl.registered_cell.class.php on line 315
remove

$unique_id . '_' . $field_name . '_' . $item['ddl-repeat-id'],

and paste

$unique_id . '_' . $group . '-'. $name.'-_' . $item['ddl-repeat-id'],

Can you include this FIX in next version of Layouts plugin, please?

#1119896

Hi, I wanted to provide a quick update to let you know our developers will include a permanent fix for this issue in Layouts 2.4.2, which is scheduled for release in the next few days.