/** * Ajax handler for saving label translations from the WPML Taxonomy Translations menu. */ public function save_label_translations() { if (!wpml_is_action_authenticated('wpml_tt_save_labels_translation')) { wp_send_json_error('Wrong Nonce'); } $general = isset($_POST['plural']) ? sanitize_text_field($_POST['plural']) : false; $singular = isset($_POST['singular']) ? sanitize_text_field($_POST['singular']) : false; $taxonomy = isset($_POST['taxonomy']) ? sanitize_text_field($_POST['taxonomy']) : false; $language = isset($_POST['taxonomy_language_code']) ? sanitize_text_field($_POST['taxonomy_language_code']) : false; if ($singular && $general && $taxonomy && $language) { $tax_label_data = $this->get_label_translations(false, $taxonomy); if (isset($tax_label_data['id_singular']) && $tax_label_data['id_singular'] && isset($tax_label_data['id_general']) && $tax_label_data['id_general']) { $original_id_singular = $tax_label_data['id_singular']; $original_id_plural = $tax_label_data['id_general']; icl_add_string_translation($original_id_singular, $language, $singular, ICL_TM_COMPLETE); $singular_result = (string) icl_get_string_by_id($original_id_singular, $language); icl_add_string_translation($original_id_plural, $language, $general, ICL_TM_COMPLETE); $plural_result = (string) icl_get_string_by_id($original_id_plural, $language); if ($singular_result && $plural_result) { $result = array('singular' => $singular_result, 'general' => $plural_result, 'lang' => $language); wp_send_json_success($result); } } } wp_send_json_error(); }
/** * @param $item_type_name * @param $item_type * @param $strings_basket_items * @param $translators * @param $basket_name */ public static function send_strings_jobs($item_type_name, $item_type, $strings_basket_items, $translators, $basket_name) { /** @var $iclTranslationManagement TranslationManagement */ global $iclTranslationManagement, $wpdb, $wpml_translation_job_factory; $strings_local = array(); if (!empty($strings_basket_items)) { // for every string in cart // collect strings for local translation // collect string for remote translation $strings_remote = array(); foreach ($strings_basket_items as $basket_item_id => $basket_item) { foreach ($basket_item['to_langs'] as $language_code => $action) { if (is_numeric($translators[$language_code])) { $strings_local[$language_code][] = $basket_item_id; } else { $strings_remote[$language_code][] = $basket_item_id; } } } if ($strings_remote) { foreach ($strings_remote as $target => $string_ids) { $basket = new WPML_Translation_Basket($wpdb); $st_tp_job = new WPML_TP_String_Job($wpdb, $basket, $wpml_translation_job_factory); $result = $st_tp_job->send_strings_to_translation_service($string_ids, $target, $translators[$target]); if (isset($result['errors']) && count($result['errors'])) { foreach ($result['errors'] as $error) { $error_message = array('type' => 'error', 'text' => $error); $iclTranslationManagement->add_message($error_message); } } if (!$result) { foreach ($string_ids as $string_id) { $default_string_language = $basket->get_source_language(); $string = icl_get_string_by_id($string_id, $default_string_language); $message = array('type' => 'error', 'text' => sprintf(__('String "%s" has not been sent.', 'wpml-translation-management'), $string)); $iclTranslationManagement->add_message($message); } break; } } } foreach ($strings_local as $target => $string_ids) { self::translation_send_strings_local($string_ids, $target, $translators[$target], $basket_name); } } }
/** * Incorporates strings in cart data * * @param array $strings * @param bool|string $source_language * * @return boolean | array */ function get_translation_jobs_basket_strings($strings, $source_language = false) { $final_strings = array(); if (class_exists('WPML_String_Translation')) { global $sitepress; $source_language = $source_language ? $source_language : TranslationProxy_Basket::get_source_language(); foreach ($strings as $string_id => $data) { if ($source_language) { // set post_id $final_strings[$string_id] = false; // set post_title $final_strings[$string_id]['post_title'] = icl_get_string_by_id($string_id); // set post_type $final_strings[$string_id]['post_type'] = 'string'; // set from_lang $final_strings[$string_id]['from_lang'] = $source_language; $final_strings[$string_id]['from_lang_string'] = ucfirst($sitepress->get_display_language_name($source_language, $sitepress->get_admin_language())); // set to_langs $final_strings[$string_id]['to_langs'] = $data['to_langs']; // set comma separated to_langs -> to_langs_string // set comma separated to_langs -> to_langs_string $language_names = array(); foreach ($final_strings[$string_id]['to_langs'] as $language_code => $value) { $language_names[] = ucfirst($sitepress->get_display_language_name($language_code, $sitepress->get_admin_language())); } $final_strings[$string_id]['to_langs_string'] = implode(", ", $language_names); } } } return $final_strings; }
/** * Ajax handler for saving label translations from the WPML Taxonomy Translations menu. */ public static function save_labels_translation() { $general = isset($_POST['plural']) ? $_POST['plural'] : false; $singular = isset($_POST['singular']) ? $_POST['singular'] : false; $taxonomy = isset($_POST['taxonomy']) ? $_POST['taxonomy'] : false; $language = isset($_POST['taxonomy_language_code']) ? $_POST['taxonomy_language_code'] : false; if ($singular && $general && $taxonomy && $language) { $tax_label_data = WPML_Taxonomy_Translation_Table_Display::get_label_translations($taxonomy); if (isset($tax_label_data['id_singular']) && $tax_label_data['id_singular'] && isset($tax_label_data['id_general']) && $tax_label_data['id_general']) { $original_id_singular = $tax_label_data['id_singular']; $original_id_plural = $tax_label_data['id_general']; icl_add_string_translation($original_id_singular, $language, $singular, ICL_STRING_TRANSLATION_COMPLETE); $singular_result = (string) icl_get_string_by_id($original_id_singular, $language); icl_add_string_translation($original_id_plural, $language, $general, ICL_STRING_TRANSLATION_COMPLETE); $plural_result = (string) icl_get_string_by_id($original_id_plural, $language); if ($singular_result && $plural_result) { $result = array('singular' => $singular_result, 'general' => $plural_result, 'lang' => $language); wp_send_json_success($result); } } } wp_send_json_error(); }