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: Exception
Author | Posts |
---|---|
June 4, 2025 at 8:52 am #17105388 | |
ghledisC |
Background of the issue: Symptoms: Questions: |
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. 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: or you can also do it programmatically via wp-config.xml file:
<wpml-config> <custom-types> <custom-type translate="1" automatic="0">contact_form</custom-type> </custom-types> </wpml-config> Best Regards, |
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) { 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,
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.
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.
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.
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: 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, |
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. |