Skip Navigation

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 4 replies, has 1 voice.

Last updated by ghledisC 1 month ago.

Assisted by: Otto.

Author Posts
June 4, 2025 at 8:52 am #17105388

ghledisC

Background of the issue:
I need to be able to start automatic translation for a custom post type only and only in certain languages programmatically. I want to be able to start automatic translation for a custom post type as soon as the post is published, but only in certain languages and only for that post type. I didn't manage to find any hooks / filters for this in the documentation. The site I need help with is hidden link.

Symptoms:
I didn't manage to find any hooks / filters for this in the documentation.

Questions:
How can I start automatic translation for a custom post type programmatically in WPML?
Are there specific hooks or filters in WPML for triggering automatic translation upon post publication?
How can I limit automatic translation to certain languages for a specific post type in WPML?

June 5, 2025 at 11:39 am #17110106

ghledisC

After trying to implement this functionality with the help of chatGPT, here is a more concise description of what I want to do:

Programmatically Trigger Automatic Translation for CPT Without Global "Translate Everything" Mode

I’ve developed a plugin to trigger automatic translations for a custom post type (machines) from the WordPress admin list table via AJAX. This mirrors what I normally do manually in WPML Translation Management:

Select a post,

Choose target languages (excluding Russian),

Set translation method to automatic,

Set translated posts to publish immediately without review.

I want to replicate this exact flow programmatically — not globally via “Translate Everything Automatically,” but on demand, when the editor deems the post ready.

Currently:

I’m using wpml_tm_load_job_factory()->create_local_post_job(...) to create jobs,

Then I call do_action('wpml_tm_send_jobs_to_ate', $job_ids);.

The jobs are created, but they are always sent for manual translation, not automatic.

I found no trace of the WPML_TM_Job_Origin::AUTO_TRANSLATION class in the plugin files (v4.7.6), so I can't set the job origin to automatic as documented in older sources.

How can I programmatically send specific posts for automatic translation via ATE — with the same behavior as if done manually via the Translation Management interface?

Thank you in advance.

June 6, 2025 at 12:59 pm #17114079

Otto
WPML Supporter since 09/2015

Languages: English (English ) Spanish (Español )

Timezone: America/Argentina/Buenos_Aires (GMT-03:00)

Hello,

First, I apologize for the delay in responding. I will take care of this ticket; the reply time will be shorter now.

Second, please note that we currently are not able to provide support for custom work within this forum. I will, however, try to point you to the correct direction.
If my suggestions are not enough we suggest contacting one of our 3rd party contractors that specialize in custom work with WPML: https://wpml.org/contractors/

Third, our current public APIs don’t expose a flag for AUTO_TRANSLATION jobs, so I'll suggest a workaround.

You can set your site to translate everything and exclude some type of content (in this case all the not "machines" post types) this way:
https://wpml.org/forums/topic/automatic-translation-of-posts-to-a-selected-language/#post-16376963

or you can also do it programmatically via wp-config.xml file:
https://wpml.org/documentation/support/language-configuration-files/register-custom-terms-types-taxonomies-as-translatable/

You can add the automatic attribute to the tag to exclude a post type from automatic translation when using the Translate Everything Automatically mode. If you use this attribute, your entire language configuration file will only work for WPML versions 4.5.0 and up.

<wpml-config>
  <custom-types>
    <custom-type translate="1" automatic="0">contact_form</custom-type>
  </custom-types>
</wpml-config>

Best Regards,
Otto

June 10, 2025 at 11:45 am #17121762

ghledisC

Thank you for your reply.

I have reviewed my options here and the xml file seems useful.

Just to confirm, I could set which post types get automatically translated in the xml and which not, correct?

And Automatic translation in this case means the fully automated translation, without any user intervention correct? What if I manually want to the trigger an automatic translation for a post type that has been marked as not automatically translatable in the xml file? Would the xml settings stop the automatic translation in that case as well?

I am willing to put everything on Automatic translation, with the caveat that I need to have control over which languages will be translated into automatically. Some languages prefer manual translation as based on the feedback, the automatic translation is not natural enough.

Is there a way to exclude certain languages from the completely automatic site translation?

Through a discussion through chatGPT, the 'wpml_copy_post_to_language' filter hook came up.

This is an untested filter we created:

add_filter('wpml_copy_post_to_language', function($post_id, $target_lang, $mark_as_duplicate) {
if (get_post_type($post_id) === 'machines' && $target_lang === 'ru') {
return null; // Cancel the copy/translation
}
return $post_id; // Allow all other translations
}, 20, 3);

I am missing the information of if fully automatic translation would even be subject to this filter or not. I suspect not, but please let me know.

June 10, 2025 at 1:48 pm #17122180

Otto
WPML Supporter since 09/2015

Languages: English (English ) Spanish (Español )

Timezone: America/Argentina/Buenos_Aires (GMT-03:00)

Hello,

Just to confirm, I could set which post types get automatically translated in the xml and which not, correct?

You can choose which post types to exclude. All are included in "Translate Everything" mode by default if you enable it. And with the config file, you can exclude some post types.

And Automatic translation in this case means the fully automated translation, without any user intervention correct?

Yes, each time the content changes or new content is created (and the post is not excluded in the config file) it will be automatically sent to translation, and it will be machine translated.

What if I manually want to the trigger an automatic translation for a post type that has been marked as not automatically translatable in the xml file? Would the xml settings stop the automatic translation in that case as well?

If you manually send an excluded post type to be machine translated, it will work. Translate everything mode + config file only decides what will be sent automatically to translate.

Is there a way to exclude certain languages from the completely automatic site translation?

No, there is no way to enable "Translate Everything" mode per language.

Regarding the hook, it won't work for your use case.

wpml_copy_post_to_language creates a duplicate in this sense:
https://wpml.org/documentation/translating-your-contents/displaying-untranslated-content-on-pages-in-secondary-languages/

So, it's not the real translation done by a translation engine. Just the original content duplicated. It does not send the content to be translated.

Best Regards,
Otto

June 10, 2025 at 1:59 pm #17122331

ghledisC

Thank you for your patience and explanation, I have figured out my own work around to do exactly what I need.