/**
  *
  * Add language name to custom field (only if is set to translate)
  *
  * @param $string
  * @param $lang
  * @param $context
  *
  * @return string
  */
 private function add_language_name_to_custom_field($string, $lang, $context)
 {
     //get settings - $this->settings is not set when creating duplicate (not updating)
     global $sitepress_settings;
     $settings =& $sitepress_settings['translation-management'];
     //check for custom fields to translate
     if (isset($settings['custom_fields_translation'])) {
         //get information about custom fields to translate
         $custom_fields_translation = $settings['custom_fields_translation'];
         if (isset($custom_fields_translation[$context['key']])) {
             //if custom field is set to translate (id = 2)
             if ($custom_fields_translation[$context['key']] == 2) {
                 //add language information
                 return wpml_ctt_prepare_string($this->template, $string, $lang);
             }
         }
     }
     return $string;
 }
 /**
  * Auto translate strings with given context
  *
  * @param $context
  * @param $languages
  * @param $template
  */
 private function translate_strings($context, $languages, $template)
 {
     global $wpdb;
     //get all not translated strings (status <> 1)
     if (0 === strcmp($context, 'all_contexts')) {
         $strings = $wpdb->get_results("SELECT id, language, context, value FROM {$wpdb->prefix}icl_strings");
     } else {
         $strings = $wpdb->get_results($wpdb->prepare("SELECT id, language, context, value FROM {$wpdb->prefix}icl_strings WHERE context=%s", $context));
     }
     //for each string add information
     foreach ($strings as $v) {
         foreach ($languages as $lang) {
             icl_add_string_translation($v->id, $lang, wpml_ctt_prepare_string($template, $v->value, $lang), TRUE);
             icl_update_string_status($v->id);
         }
     }
 }