/** * Translate a single communication before it is saved to DB. * * @since 1.0.1.0 * * @param array $obj The serialized data collection. * @param string $class The class name of the object. * @param MS_Model_Communication $model The source object. * @return array The serialized data collection. */ public function serialize_communication($data, $class, $model) { if ($this->current_lang == $this->default_lang) { return $data; } if (0 !== strpos($class, 'MS_Model_Communication')) { return $data; } // Save the translated values before resetting the model. $tr_subject = $data['subject']; $tr_message = $data['description']; // Reset the values to Default language. $data['subject'] = $model->reset_field('subject'); $data['description'] = $model->reset_field('description'); $data['message'] = $data['description']; // Store translations via WPML. if (function_exists('icl_add_string_translation')) { // 1. Subject. $string_name = 'ms-com-subject-' . $model->id; do_action('wpml_register_single_string', self::CONTEXT, $string_name, $data['subject']); $string_id = icl_get_string_id($data['subject'], self::CONTEXT, $string_name); if ($string_id) { icl_add_string_translation($string_id, $this->current_lang, $tr_subject, ICL_TM_COMPLETE); } // 1. Message Body. $string_name = 'ms-com-message-' . $model->id; do_action('wpml_register_single_string', self::CONTEXT, $string_name, $data['message']); $string_id = icl_get_string_id($data['message'], self::CONTEXT, $string_name); if ($string_id) { icl_add_string_translation($string_id, $this->current_lang, $tr_message, ICL_TM_COMPLETE); } } return $data; }