This is the technical support forum for WPML - the multilingual WordPress plugin.

Everyone can read, but only WPML clients can post here. WPML team is replying on the forum 6 days per week, 22 hours per day.

Tagged: 

This topic contains 5 replies, has 2 voices.

Last updated by Victor Santacreu 3 days, 6 hours ago.

Assigned support staff: Bruno Kos.

Author Posts
September 18, 2019 at 11:35 am #4595853

Victor Santacreu

Hi,
I'm developing a large site with a lot of content. The site have 6 languages. The site have a people profiles created as a custom type and a copywriter of the company make all the translations for de around 800 profiles.

But someone now just think that we could add data from profile to the postmeta to do some accurate search. I was imported all data to the postmeta of English Translation (master language) and now i need a process to insert data into translations. But I don't know how to do this process.

I just reading WPML documentation about Hooks but i don't figure out how add data to translations.

I was wrote code to do that: (this code was inside plugin):

// we get all profiles from database
$query = new WP_Query( array(
        'post_type' => 'portfolio', 
        'post_status' => 'publish',
        'posts_per_page'=>-1,
        'nopaging' => true,

    ) );

    $posts = $query->posts;

    global $sitepress;

    foreach ($posts as $p) {

        $raw = get_post_meta($p->ID, '_OldData', true ); // load data we need

        $trid = $sitepress->get_element_trid($p->ID, 'post_' . $p->post_type); // get trid
        $translations = $sitepress->get_element_translations($trid, 'post_' . $p->post_type); // get translations

        if ($raw) {
            $data = json_decode($raw, TRUE);

            // update English
            update_post_meta($p->ID, 'ebavs_name', $data['first_name']);
            update_post_meta($p->ID, 'ebavs_lastname', $data['last_name']);
            update_post_meta($p->ID, 'ebavs_city', $data['location']);
            update_post_meta($p->ID, 'ebavs_nationality', $data['nationality']);

            foreach ($translations as $lang => $tpost) {
                  if ($data['title-' . $lang] !== '') {
                          // Here need insert data in translated string post
                  }
            }
        }
    }


    wp_reset_query();

The code is working fine. Only I need te create the translation.

Thank You

September 19, 2019 at 10:44 am #4603747

Bruno Kos
Supporter

Languages: English (English )

Timezone: Europe/Zagreb (GMT+02:00)

Hi,

Thank you for contacting WPML support!

I don't think it is possible - and even if it is, it may require custom work and testing from our contractors (https://wpml.org/contractors/), because I see no hooks that are responsible for inserting the content - translations to be specific:
https://wpml.org/documentation/support/wpml-coding-api/wpml-hooks-reference/#inserting-content

I also wasn't able to find any working example in our archives, that could potentially help you with this.

Regards,
Bruno Kos

September 19, 2019 at 4:02 pm #4607093

Victor Santacreu

Hi, I'm a web developer with more than 10 years working with wordpress. I don't need a contractor, worse things I have faced.

I was read the link before you post here. For me the problem is that documentation is oriented to allow developers to make and register fields and duplicate posts to allow translators to fill later. I was did this step. I have registered fields and i was developed metabox to allow translators and copywriters to fill it in posts. But isn't the problem, the problem is to fill with data via php.

Inside Documentation not exist any function or action or filter that allow me to save a translation value. Is the reason i'm asking here.

I need something like:

wpml_save_translation_value_postmeta($trid || $post_id, $lang, $field, $value);

Thanks

September 20, 2019 at 6:22 am #4609951

Bruno Kos
Supporter

Languages: English (English )

Timezone: Europe/Zagreb (GMT+02:00)

Hi,

If there was a hook of this kind in our API, then we would already find it :). However I don't see anything and that documentation contains all the hooks implemented into WPML.

I'm not sure where something like this brings anything to this discussion:
https://wpml.org/forums/topic/how-can-i-programmatically-add-wp_user-to-translators/#post-1399993
https://wpml.org/forums/topic/add-a-taxonomy-to-three-languages-programmatically/#post-146584

Also, maybe this would be useful in your scenario:
https://wpml.org/wpml-hook/wpml_set_element_language_details/

"Apart from its straightforward implied usage, the hook can prove to be useful when one needs to connect two elements with one as the “Translation of” the other. Refer to the “Hook Example Usage” section below for an example of this."

So perhaps using your code to create another set of fields and then use the above hook to connect original and translation.

Regards,
Bruno Kos

September 20, 2019 at 8:36 am #4610641

Bruno Kos
Supporter

Languages: English (English )

Timezone: Europe/Zagreb (GMT+02:00)

Hi,

I got some confirmation from our 2nd tier support about what I suggested in my reply above, that being:

"Actually, WPML just holds the relationship, not the actual content. So you need to insert the content using WP methods and then connect them using this hook https://wpml.org/wpml-hook/wpml_set_element_language_details/"

Regards,
Bruno Kos

October 18, 2019 at 8:21 am #4779317

Victor Santacreu

Hi,

sorry for long days without a response. I was resolved on my own.
The links provided by support staff NOT resolve the problem i was asked originally.

I was resolved deeply hard in code and finally writing a complex php solution in my functions.php.

If anyone needs a solution about this, contact me directly.

Regards