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.
I'll be glad to take a look. Can you share the complete contents of your custom cell's PHP file?
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();
}
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.
Unfortunately, it did not help.
Fields, which are not repeatable are translated without problem...
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.
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...
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.
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.
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.
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.
Still not working, is there anything new about translating repeatable fields? This is really urgent! Thanks.
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.
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?
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.