Skip Navigation

[Resolved] Cred translation secondary languages content issue

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

Problem:

When i edit the main language AR all translation content of secondary languages i have made get deleted and the original language show instead. This way all the content of secondary languages will need to be edited again which is not ok.

See details here:

https://toolset.com/forums/topic/cred-translation-secondary-languages-content-issue/#post-1173247

Solution:

It is a custom PHP codes problem, see the solution here:

https://toolset.com/forums/topic/cred-translation-secondary-languages-content-issue/#post-1175790

Relevant Documentation:

This support ticket is created 5 years, 11 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.

Our next available supporter will start replying to tickets in about 0.04 hours from now. Thank you for your understanding.

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

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

This topic contains 4 replies, has 2 voices.

Last updated by Nashaat 5 years, 10 months ago.

Assisted by: Luo Yang.

Author
Posts
#1173247

Hi,

I have following scenario:

1- i create main Recipe language in arabic
2- with two different embed cred form buttons i can create secondary languages RU or EN
3-once one secondary language get created after button Submission i edit it and translate the cintent.

The issue is when i edit the main language AR all translation content of secondary languages i have made get deleted and the original language show instead. This way all the content of secondary languages will need to be edited again which is not ok.

I am using following snippets to manage the process described above.

<?php
toolset_snippet_security_check() or die( 'Direct access is not allowed' );
/**
 * New custom code snippet.
 */

function wpml_make_post_duplicate_language( $master_post_id, $lang_to ) {
 
    global $sitepress;
 
    $master_post = get_post( $master_post_id );
 
    if ( 'auto-draft' === $master_post->post_status || 'revision' === $master_post->post_type ) {
        return;
    }
 
    $active_langs = $sitepress->get_active_languages();
 
    if (array_key_exists($lang_to, $active_langs)) {
 
        $trid      = $sitepress->get_element_trid( $master_post->ID, 'post_' . $master_post->post_type );
        $lang_from = $sitepress->get_source_language_by_trid( $trid );
 
        if ( $lang_from == $lang_to ) {
            return;
        }
 
        $sitepress->make_duplicate( $master_post_id, $lang_to );
    }
}
 
add_action( 'wpml_make_post_duplicate_lang', 'wpml_make_post_duplicate_language', 10, 2 );

<?php
toolset_snippet_security_check() or die( 'Direct access is not allowed' );
/**
 * New custom code snippet.
 */

function quick_duplicate_save_data_action( $post_id, $form_data ){
  $form_langs = array(
    383 => 'en',
    404 => 'ru',
  );
  if( isset( $form_langs[$form_data['id']] ) ) {
    global $sitepress;
    $lang_to = $form_langs[$form_data['id']];
    do_action( 'wpml_make_post_duplicate_lang', $post_id, $lang_to );
  }
}
add_action( 'cred_save_data', 'quick_duplicate_save_data_action', 10, 2 );


You can login to the site and try modify one of the posts to secondary languages and after that try to edit the main AR language.. The secondary languages will have cintent from original again.

Here you can see the Recipes
hidden link

Here you can find the snippets: 11 + 12

hidden link

A ticket from before connected to this topic : https://toolset.com/forums/topic/duplicate-translation-for-specific-language-with-cred-form/

#1173305

Hello,

Please check this, edit post in secondary languages, for example:
hidden link

In section "Language", you are using option:
This document is a duplicate of المكرونة بالجبنة and it is maintained by WPML.

So it conduct the problem as you mentioned above:
edit the main AR language.. The secondary languages will have cintent from original again

So you can edit each post in secondary languages, click button "Translate independently", and test again.

If you want to setup the new secondary languages as "Translate independently" by PHP codes, you can remove the custom field "_icl_lang_duplicate_of" from secondary languages posts, for example this thread:
https://toolset.com/forums/topic/toolset-and-wpml-front-end-translation/#post-1096891

#1175753

I am not sure how to add following code in the code i have sent before?

// translate versions independently
            foreach ( $translations as $tr ) {
                delete_post_meta( $tr->element_id, '_icl_lang_duplicate_of' );
            }
#1175790

For example, you can replace this line from:

$sitepress->make_duplicate( $master_post_id, $lang_to );

To:

$new_post_id = $sitepress->make_duplicate( $master_post_id, $lang_to );
delete_post_meta( $new_post_id , '_icl_lang_duplicate_of' );
#1178490

My issue is resolved now. Thank you!