Skip Navigation

[Resolved] Custom cells and WPML Translation management

This thread is resolved. Here is a description of the problem and solution.

Problem:

The issue here is that the user wanted to translate their custom cells but the translations were not working with WPML

Solution:

In a case like this we would recommend that you contact our WPML forum for translation issues.

http://wpml.org/

This support ticket is created 6 years, 4 months ago. 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.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

This topic contains 16 replies, has 3 voices.

Last updated by Shane 6 years, 3 months ago.

Assisted by: Shane.

Author
Posts
#953891

I am trying to: translate custom cells via WPML Translation management. Cells are made exactly according to the instructions, but it has problem with translations. Content is saved and translated fully in tr. management, but when we switch languages on frontend, some parts are not translated. In backend are fields 100% completed.

Please see this WPML thread: https://wpml.org/forums/topic/different-content-in-layouts-and-management-urgent/

We spent much time with developing custom cells and translating content. Now it seems it doesnt work. Can you confirm please, that Custom cells are FULLY supported in Toolset / WPML?
We found many bugs in Custom cells, e.g.
https://toolset.com/forums/topic/html-tags-disappear-in-textarea-fields-in-custom-cells/
https://toolset.com/forums/topic/reapeatable-fields-are-not-translated-in-custom-cells/

Can you ensure us, that we can use Custom cells in future? This is really URGENT, we must make decision in next day.

#954503

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Abra,

Thank you for contacting our support forum.

You are referring to the Layouts Cells correct ? If so then yes this is fully compatible also is it text within the cells that are not translated?

Because you can workaround this by using the wpml shortcode.
https://toolset.com/documentation/user-guides/views-shortcodes/#vf-464327

Please let me know if this helps.

Thanks,
Shane

#954520

Hi Shane,
we are using Layouts Cells API, so in register_dd_layout_cell_type function we define fields to translation, for example:

'translatable_fields'      => array(
                            'title' => array('title' => 'Nadpis', 'type' => 'LINE'),
                            'perex' => array('title' => 'Perex', 'type' => 'VISUAL'),
                            'alt' => array('title' => 'Alt obrázku', 'type' => 'LINE'),
                            'buttext' => array('title' => 'Text tlačítka', 'type' => 'LINE'),
                            'url' => array('title' => 'URL', 'type' => 'LINE'),
                            'image' => array('title' => 'Obrázek', 'type' => 'LINE')
                        )

It works fine, WPML Translation Management offers these fields to translation. After 100% finishing of translation, we save it, on backend it seems to be fine. But on frontend is new translation not visible.

#954522

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Abra,

Could you send me a link to the page where this cell is so I can see what it looks like on the frontend. Normally I know that we use the gettext() calls as well as the text domain to send items for translation. Its the first i'm seeing it done this way.

Also send a screenshot of the cell area.

Thanks,
Shane

#954641
toolset_layouts_cell.PNG

Please, look at this page: hidden link
Our cells are made according to this instructions https://toolset.com/documentation/programmer-reference/layouts-cells-api/
This paragraph speaks about translations: https://toolset.com/documentation/programmer-reference/layouts-cells-api/#translating-cell-fields

This is code of the cell. Situation is similar with all our cells.

<?php
function register_section_intro_init() {

	register_dd_layout_cell_type ('section-intro',
		array (
			'name' => __('Sekce intro', 'abra_software'),
                        'cell-image-url' => get_template_directory_uri().'/dd-layouts-cells/images/section-intro.png',
			'description' => __('Buňka pro Sekci intro', 'abra_software'),
			'category' => __('ABRA buňky', 'abra_software'),
			'button-text' => __('Vložit Sekci intro', 'abra_software'),
			'dialog-title-create' => __('Vytvořit novou buňku Sekce intro', 'abra_software'),
			'dialog-title-edit' => __('Upravit buňku Sekce intro', 'abra_software'),
			'dialog-template-callback' => 'section_intro_dialog_template_callback',
			'cell-content-callback' => 'section_intro_content_callback',
			'cell-template-callback' => 'section_intro_template_callback',
			'cell-class' => 'abcell',
                        'translatable_fields'      => array(
                            'title' => array('title' => 'Nadpis', 'type' => 'LINE'),
                            'perex' => array('title' => 'Perex', 'type' => 'VISUAL'),
                            'alt' => array('title' => 'Alt obrázku', 'type' => 'LINE'),
                            'buttext' => array('title' => 'Text tlačítka', 'type' => 'LINE'),
                            'url' => array('title' => 'URL', 'type' => 'LINE'),
                            'image' => array('title' => 'Obrázek', 'type' => 'LINE')
                        )
		)
	);
}
add_action( 'init', 'register_section_intro_init' );
 
function section_intro_dialog_template_callback() {
        ob_start();       
        ?>
        
        <h3>
            <?php _e('Sekce intro', 'abra_software' ); ?>
        </h3>

        <div class="ddl-form">
            <p>
                <label for="<?php the_ddl_name_attr('title'); ?>"><?php _e( 'Nadpis', 'abra_software' ) ?>:</label>
                <input type="text" name="<?php the_ddl_name_attr('title'); ?>">
            </p>
            <p>
                <label for="<?php the_ddl_name_attr('perex'); ?>"><?php _e('Perex', 'abra_software' ); ?></label>                
                <textarea name="<?php the_ddl_name_attr('perex'); ?>" rows="3"></textarea>
            </p>
            <p>
                <label for="<?php the_ddl_name_attr('rhombimage'); ?>"><?php _e( 'Šikmý obrázek?', 'abra_software' ) ?></label>
                <span class="ddl-input-wrap">
                    <input type="checkbox" name="<?php the_ddl_name_attr('rhombimage'); ?>" id="<?php the_ddl_name_attr('rhombimage'); ?>" value="true">
                </span>
            </p>
            <p class="js-ddl-media-field">
                <label for="<?php the_ddl_name_attr('image'); ?>" class="ddl-manual-width-201"><?php _e( 'Obrázek', 'abra_software' ) ?>:</label>
                <span class="ddl-input-wrap"><input type="text" class="js-ddl-media-url ddl-input-two-thirds-width" name="<?php the_ddl_name_attr('image'); ?>" />
                    <span class="ddl-form-button-wrap ddl-input-two-thirds-width-span">
                            <button class="button js-ddl-add-media"
                                            data-uploader-title="<?php _e( 'Vybrat obrázek', 'abra_software' ) ?>"
                                            data-uploader-button-text="Vložit URL obrázku"><?php _e( 'Vybrat obrázek', 'abra_software' ) ?>
                            </button>
                    </span>
                </span>
            </p>
            <p>
                <label for="<?php the_ddl_name_attr('alt'); ?>"><?php _e( 'Alt obrázku', 'abra_software' ) ?>:</label>
                <input type="text" name="<?php the_ddl_name_attr('alt'); ?>">
                <span class="desc"><?php _e('Toto pole má přednost před altem mediálního souboru.', 'abra_software' ); ?></span>
            </p>
            <p>
                <label for="<?php the_ddl_name_attr('butvisible'); ?>"><?php _e( 'Zobrazit tlačítko?', 'abra_software' ) ?></label>
                <span class="ddl-input-wrap">
                    <input type="checkbox" name="<?php the_ddl_name_attr('butvisible'); ?>" id="<?php the_ddl_name_attr('butvisible'); ?>" value="true" checked="checked">
                </span>
            </p>
            <p>
                <label for="<?php the_ddl_name_attr('buttext'); ?>"><?php _e( 'Text tlačítka', 'abra_software' ) ?>:</label>
                <input type="text" name="<?php the_ddl_name_attr('buttext'); ?>">
            </p>
            <p>
                <label for="<?php the_ddl_name_attr('externallink'); ?>"><?php _e( 'Směřuje odkaz na jinou stránku?', 'abra_software' ) ?></label>
                <span class="ddl-input-wrap">
                    <input type="hidden" name="<?php the_ddl_name_attr('externallink'); ?>" value="0">
                    <input type="checkbox" name="<?php the_ddl_name_attr('externallink'); ?>" id="<?php the_ddl_name_attr('externallink'); ?>" value="1">
                </span>
            </p>
            <p>
                <label for="<?php the_ddl_name_attr('url'); ?>"><?php _e( 'URL', 'abra_software' ) ?>:</label>
                <input type="text" name="<?php the_ddl_name_attr('url'); ?>">
            </p>

        </div>

	<?php
	return ob_get_clean();
       
}

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

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

}

if (!function_exists('get_img_id')) {
    function get_img_id($url) {
        global $wpdb;    
        $attachment = $wpdb->get_col($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE guid='".$url."';", $image_url ));
        return $attachment[0];
    } 
}


// Callback function for display the cell in the front end.
function section_intro_content_callback($cell_settings) {
	ob_start();
	?>

    <div class="section section-intro">
        <div class="container">
                       
            <div class="section-intro__content">

                <h1 class="h1"><?php the_ddl_field('title');?></h1>
                <p><?php the_ddl_field('perex');?></p>
                <?php if(get_ddl_field('butvisible')) { ?>
                    <?php if(!get_ddl_field('externallink')) { ?>
                        <a href="<?php the_ddl_field('url');?>" class="button button--pink" data-component="ScrollTo"><span><?php the_ddl_field('buttext');?></span></a>
                    <?php } ?>
                    <?php if(get_ddl_field('externallink')) { ?>
                        <a href="<?php the_ddl_field('url');?>" class="button button--pink"><span><?php the_ddl_field('buttext');?></span></a>
                    <?php } ?>
                <?php } ?>

            </div>

            <div class="section-intro__image">
                <div class="rhomb">
                    <?php 
                    $img_url = get_ddl_field('image');
                    $img_id = get_img_id($img_url);
                    $img_alt = get_post_meta( $img_id, '_wp_attachment_image_alt', true); 
                    ?>
                    <?php if(get_ddl_field('rhombimage')) { ?>
                    <div class="rhomb__image"><img src="<?php the_ddl_field('image');?>" alt="<?php if(get_ddl_field('alt')) { the_ddl_field('alt'); } else echo $img_alt; ?>"></div>
                    <?php } ?>
                    <div class="rhomb__gradient"></div>
                </div>
                <?php if(!get_ddl_field('rhombimage')) { ?>
                <img src="<?php the_ddl_field('image');?>" alt="<?php if(get_ddl_field('alt')) { the_ddl_field('alt'); } else echo $img_alt; ?>">
                <?php } ?>
            </div>

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

#954703

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Abra,

Yes thanks I see.

The content that is within the cell isn't translated, but the cell itself is translated.

Could you try wrapping the content in this shortcode as a workaround ?

I will test this locally and see what I can find.
https://toolset.com/documentation/user-guides/views-shortcodes/#vf-464327

Thanks,
Shane

#955411

Hi Shane,
I think we don't need [wpml-string] shortcodes, because the translations are automatically included in WPML > String translations. When I select in filter domain for concrete Layout, all cell fields are available for translations.
Thanks in advance

#955566

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Screen Shot 2018-07-25 at 9.15.26 AM.png

Hi Abra,

Take a look at the screenshot

I tested your exact cell and it works when I translate it from English to French on the frontend.

So your cell works fine. Did you select the "Translation Completed" checkbox in string translation ?

Also could you delete the text and re-translate it ?

Thanks,
Shane

#956494

Hi Shane,
let me split the problem into 2:

1. If we insert code of custom cell to standrard editor, now it works - also translations. It works thanks to yesterday´s update of WPML.

2. Using our custom cells are still problematic. Please see this video: hidden link.
- related unsloved posts:
https://wpml.org/forums/topic/different-content-in-layouts-and-management-urgent/
https://toolset.com/forums/topic/reapeatable-fields-are-not-translated-in-custom-cells/

Thanks

#956688

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Abra,

Thank you for the video.

Could you go to WPML -> String translations and see if the text show up there along with the translations that you have created?

This is how I translated the custom cell that you sent to me.

Thanks,
Shane

#957186

Hi Shane,
in WPML strings there is "layout-2047" translated to slovak - there is "Link CZ 1" translated to "Link SK 1" and so on.
The same in WPML management.
But on the front-end, there are still untranslated items "Link CZ 1" and "Link CZ 2".

#957355

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Abra,

I'm not experiencing this issue on my end as it works fine.

The WPML team would be better able to assist you with this. I would recommend opening a ticket with them for this issue if you have not already done so.

However one method you can try is to delete the strings from string translations and re-translate it.

I would highly recommend contacting them.

Thanks,
Shane

#1069303

Hi Shane,
I have tried the method deleting strings from the string translations and re-translate it. Deleted items are not available anymore in the translation management. What would be the next step to reiniciate translations of these items?

There´s been already WPML ticket: https://wpml.org/forums/topic/different-content-in-layouts-and-management-urgent/.

#1070255

Hi, Shane is on public holiday today and will return tomorrow to assist you.

#1071491

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Abra,

There isn't much we can do here since it is a translation issue and i'm able to translate it on my end without any issue.

Should any escalation is needed then the WPML team is better able to assist you.

Thanks,
Shane