/**
  * Uses the API provided in \WPML_Terms_Translations to create missing term translations.
  * These arise when a term, previously having been untranslated, is set to be translated
  * and assigned to posts in more than one language.
  *
  * @param $trid        int The trid value for which term translations are missing.
  * @param $source_lang string The source language of this trid.
  * @param $langs       array The languages' codes for which term translations are missing.
  */
 private function prepare_missing_translations($trid, $source_lang, $langs)
 {
     $existing_translations = $this->sitepress->term_translations()->get_element_translations(false, $trid);
     foreach ($langs as $lang) {
         if (!isset($existing_translations[$lang])) {
             $this->term_utils->create_automatic_translation(array('lang_code' => $lang, 'source_language' => $source_lang, 'trid' => $trid, 'taxonomy' => $this->taxonomy));
         }
     }
 }
 private function get_translated_term_ids($terms, $lang, $taxonomy, $duplicate)
 {
     /** @var WPML_Term_Translation $wpml_term_translations */
     global $wpml_term_translations;
     $wpml_term_translations->reload();
     $translated_terms = array();
     foreach ($terms as $orig_term) {
         $translated_id = (int) $wpml_term_translations->term_id_in($orig_term->term_id, $lang);
         if (!$translated_id && $duplicate) {
             $translation = WPML_Terms_Translations::create_automatic_translation(array('lang_code' => $lang, 'taxonomy' => $taxonomy, 'trid' => $wpml_term_translations->get_element_trid($orig_term->term_taxonomy_id), 'source_language' => $wpml_term_translations->get_element_lang_code($orig_term->term_taxonomy_id)));
             $translated_id = isset($translation['term_id']) ? $translation['term_id'] : false;
         }
         if ($translated_id) {
             $translated_terms[] = $translated_id;
         }
     }
     return $translated_terms;
 }
 /**
  * Uses the API provided in \WPML_Terms_Translations to create missing term translations.
  * These arise when a term, previously having been untranslated, is set to be translated
  * and assigned to posts in more than one language.
  *
  * @param $trid int The trid value for which term translations are missing.
  * @param $source_lang string The source language of this trid.
  * @param $langs array The languages' codes for which term translations are missing.
  */
 private function prepare_missing_translations($trid, $source_lang, $langs)
 {
     foreach ($langs as $lang) {
         WPML_Terms_Translations::create_automatic_translation(array('lang_code' => $lang, 'source_language' => $source_lang, 'trid' => $trid, 'taxonomy' => $this->taxonomy));
     }
 }