本文整理汇总了PHP中TranslationManagement类的典型用法代码示例。如果您正苦于以下问题:PHP TranslationManagement类的具体用法?PHP TranslationManagement怎么用?PHP TranslationManagement使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了TranslationManagement类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: edit_translator_action
public function edit_translator_action($user, $language_pairs)
{
$user_id = $this->get_user_id($user);
if (is_numeric($user_id)) {
$this->TranslationManagement->edit_translator($user_id, $language_pairs);
}
}
示例2: translation_send_strings_local
public static function translation_send_strings_local($string_ids, $target, $translator = null, $basket_name = null)
{
global $wpdb;
static $site_translators;
if (!isset($site_translators)) {
$site_translators = TranslationManagement::get_blog_translators();
}
$mkey = $wpdb->prefix . 'strings_notification';
$lkey = $wpdb->prefix . 'language_pairs';
$slang = TranslationProxy_Basket::get_source_language();
foreach ($string_ids as $string_id) {
$batch_id = TranslationProxy_Batch::update_translation_batch($basket_name);
$added = icl_add_string_translation($string_id, $target, null, ICL_TM_WAITING_FOR_TRANSLATOR, $translator, 'local', $batch_id);
if ($added) {
foreach ($site_translators as $key => $st) {
$ulangs = isset($st->{$lkey}) ? $st->{$lkey} : false;
if (!empty($ulangs) && !empty($ulangs[$slang][$target])) {
$enot = isset($st->{$mkey}) ? $st->{$mkey} : false;
if (empty($enot[$slang][$target])) {
self::translator_notification($st, $slang, $target);
$enot[$slang][$target] = 1;
$site_translators[$key]->{$mkey} = $enot;
update_option($wpdb->prefix . 'icl_translators_cached', $site_translators);
}
}
}
}
}
return 1;
}
示例3: new_job_any
function new_job_any($job_id)
{
global $iclTranslationManagement, $sitepress, $wpdb;
$job = $iclTranslationManagement->get_translation_job($job_id);
$translators = TranslationManagement::get_blog_translators(array('to' => $job->language_code));
$edit_url = apply_filters('icl_job_edit_url', admin_url('admin.php?page=' . WPML_TM_FOLDER . '/menu/translations-queue.php&job_id=' . $job_id), $job_id);
foreach ($translators as $t) {
if ($job->manager_id == $t->ID) {
continue;
}
// get current user admin language
$user_language = $sitepress->get_user_admin_language($t->ID);
// override locale
$sitepress->switch_locale($user_language);
$lang_from = $wpdb->get_var($wpdb->prepare("SELECT name FROM {$wpdb->prefix}icl_languages_translations WHERE language_code='%s' AND display_language_code='%s'", $job->source_language_code, $user_language));
$lang_to = $wpdb->get_var($wpdb->prepare("SELECT name FROM {$wpdb->prefix}icl_languages_translations WHERE language_code='%s' AND display_language_code='%s'", $job->language_code, $user_language));
$post_link = $iclTranslationManagement->tm_post_permalink($job->original_doc_id);
if ($post_link != "") {
$post_link = sprintf(__("\nView the original document in %s here: %s\n", 'sitepress'), $lang_from, $post_link);
}
$mail['to'] = $t->display_name . ' <' . $t->user_email . '>';
//$mail['to'] = $t->user_email;
$mail['subject'] = sprintf(__('New translation job from %s', 'sitepress'), get_bloginfo('name'));
$mail['body'] = sprintf(__("New job available from %s to %s.\n%s\nStart editing: %s", 'sitepress'), $lang_from, $lang_to, $post_link, $edit_url);
$mail['type'] = 'translator';
$this->send_mail($mail, $user_language);
//restore locale
$sitepress->switch_locale();
}
}
示例4: get_batch_name
public function get_batch_name()
{
if ($this->name == false) {
$this->name = TranslationManagement::get_batch_name($this->get_id());
}
return $this->name;
}
示例5: get_blog_translators
/**
* @param array $args
*
* @return array
*/
function get_blog_translators($args = array())
{
$translators = TranslationManagement::get_blog_translators($args);
foreach ($translators as $key => $user) {
$translators[$key] = isset($user->data) ? $user->data : $user;
}
return $translators;
}
示例6: icl_get_blog_users_not_translators
function icl_get_blog_users_not_translators()
{
$translator_drop_down_options = array();
$nonce = filter_input(INPUT_POST, 'get_users_not_trans_nonce');
if (!wp_verify_nonce($nonce, 'get_users_not_trans_nonce')) {
die('Wrong Nonce');
}
$blog_users_nt = TranslationManagement::get_blog_not_translators();
foreach ((array) $blog_users_nt as $u) {
$label = $u->display_name . ' (' . $u->user_login . ')';
$value = esc_attr($u->display_name);
$translator_drop_down_options[] = array('label' => $label, 'value' => $value, 'id' => $u->ID);
}
wp_send_json_success($translator_drop_down_options);
}
示例7: send_all_jobs
/**
* Sends all jobs from basket in batch mode to translation proxy
*
* @param string $basket_name
* @param array $batch
* @param array $translators
*
* @return bool false in case of errors (read from TranslationManagement::get_messages('error') to get errors details)
*/
private function send_all_jobs(array $batch, array $translators, $basket_name)
{
$basket_name_saved = $this->basket->get_name();
$basket_name = $basket_name_saved ? $basket_name_saved : $basket_name;
if ($basket_name) {
$this->basket->set_name($basket_name);
}
$valid_jobs = $this->get_valid_jobs_from_basket($batch);
$this->basket->set_remote_target_languages($this->generate_remote_target_langs($translators, $valid_jobs));
$basket_items_types = $this->basket->get_item_types();
foreach ($basket_items_types as $item_type_name => $item_type) {
$type_basket_items = isset($valid_jobs[$item_type_name]) ? $valid_jobs[$item_type_name] : array();
do_action('wpml_tm_send_' . $item_type_name . '_jobs', $item_type_name, $item_type, $type_basket_items, $translators, $basket_name);
}
// check if there were no errors
return !$this->tm_instance->messages_by_type('error');
}
示例8: icl_get_job_original_field_content
function icl_get_job_original_field_content()
{
global $iclTranslationManagement;
$error_msg = false;
$job_id = false;
$nonce = filter_input(INPUT_POST, 'tm_editor_copy_nonce');
if (!wp_verify_nonce($nonce, 'icl_copy_from_original_nonce')) {
die('Wrong Nonce');
}
$request_post_tm_editor_job_id = filter_input(INPUT_POST, 'tm_editor_job_id', FILTER_SANITIZE_NUMBER_INT, FILTER_NULL_ON_FAILURE);
$request_post_tm_editor_field_id = filter_input(INPUT_POST, 'tm_editor_job_field');
if ($request_post_tm_editor_job_id) {
$job_id = $request_post_tm_editor_job_id;
} else {
$error_msg = "No job id provided.";
}
if (!$error_msg && $request_post_tm_editor_job_id) {
$field = $request_post_tm_editor_field_id;
} else {
$error_msg = "No field provided.";
}
if (!$error_msg && $job_id && isset($field)) {
$job = $iclTranslationManagement->get_translation_job($job_id);
if (isset($job->elements)) {
foreach ($job->elements as $element) {
if (sanitize_title($element->field_type) === $field) {
// if we find a field by that name we need to decode its contents according to its format
$field_contents = TranslationManagement::decode_field_data($element->field_data, $element->field_format);
wp_send_json_success($field_contents);
}
}
} elseif (!$job) {
$error_msg = __("No translation job found: it might have been just cancelled.", 'wpml-translation-management');
} else {
$error_msg = __("No fields found in this translation job.", 'wpml-translation-management');
}
}
if (!$error_msg) {
$error_msg = __("No such field found in the job.", 'wpml-translation-management');
}
wp_send_json_error($error_msg);
}
示例9: icl_get_job_original_field_content
function icl_get_job_original_field_content()
{
global $iclTranslationManagement;
$error_msg = false;
$job_id = false;
if (isset($_POST['tm_editor_job_id'])) {
$job_id = $_POST['tm_editor_job_id'];
} else {
$error_msg = "No job id provided.";
}
if (!$error_msg && isset($_POST['tm_editor_job_id'])) {
$field = $_POST['tm_editor_job_field'];
} else {
$error_msg = "No field provided.";
}
if (!$error_msg && $job_id && isset($field)) {
$job = $iclTranslationManagement->get_translation_job($job_id);
if (isset($job->elements)) {
foreach ($job->elements as $element) {
if (sanitize_title($element->field_type) == $field) {
// if we find a field by that name we need to decode its contents according to its format
$field_contents = TranslationManagement::decode_field_data($element->field_data, $element->field_format);
wp_send_json_success($field_contents);
}
}
} elseif (!$job) {
$error_msg = _("No translation job found: it might have been just cancelled.", 'wpml-translation-management');
} else {
$error_msg = _("No fields found in this translation job.", 'wpml-translation-management');
}
}
if (!$error_msg) {
$error_msg = _("No such field found in the job.", 'wpml-translation-management');
}
wp_send_json_error($error_msg);
}
示例10: new_job_notification_mail
public function new_job_notification_mail($job_id)
{
global $iclTranslationManagement, $sitepress, $wpdb;
$job = $iclTranslationManagement->get_translation_job(array($job_id));
if (isset($job->language_code)) {
$translators = TranslationManagement::get_blog_translators(array('to' => $job->language_code));
} else {
$translators = array();
}
$edit_url = apply_filters('icl_job_edit_url', admin_url('admin.php?page=' . WPML_TM_FOLDER . '/menu/translations-queue.php&job_id=' . $job_id), $job_id);
foreach ($translators as $t) {
if (isset($job->manager_id) && isset($t->ID) && $job->manager_id == $t->ID) {
continue;
}
if (!isset($job->source_language_code) || !isset($job->language_code) || !isset($t->language_pairs) || !isset($t->language_pairs[$job->source_language_code][$job->language_code])) {
continue;
}
// get current user admin language
$user_language = $sitepress->get_user_admin_language($t->ID);
// override locale
$sitepress->switch_locale($user_language);
list($lang_from, $lang_to) = $this->get_lang_to_from($job, $user_language);
$post_link = $iclTranslationManagement->tm_post_permalink($job->original_doc_id);
if ($post_link != "") {
$post_link = sprintf(__("\nView the original document in %s here: %s\n", 'sitepress'), $lang_from, $post_link);
}
$mail['to'] = $t->display_name . ' <' . $t->user_email . '>';
//$mail['to'] = $t->user_email;
$mail['subject'] = sprintf(__('New translation job from %s', 'sitepress'), get_bloginfo('name'));
$mail['body'] = sprintf(__("New job available from %s to %s.\n%s\nStart editing: %s", 'sitepress'), $lang_from, $lang_to, $post_link, $edit_url);
$mail['type'] = 'translator';
$this->enqueue_mail($mail, $user_language);
//restore locale
$sitepress->switch_locale();
}
}
示例11: save_post_translation
//.........这里部分代码省略.........
global $wp_rewrite;
if (!isset($wp_rewrite)) {
$wp_rewrite = new WP_Rewrite();
}
kses_remove_filters();
$postarr = apply_filters('icl_pre_save_pro_translation', $postarr);
$new_post_id = wp_insert_post($postarr);
do_action('icl_pro_translation_saved', $new_post_id);
// associate custom taxonomies by hand
if (!empty($postarr['tax_input'])) {
foreach ($postarr['tax_input'] as $taxonomy => $tags) {
if ($wp_taxonomies[$taxonomy]->hierarchical) {
wp_set_post_terms($new_post_id, $tags, $taxonomy);
} else {
wp_set_post_terms($new_post_id, $translated_taxs[$taxonomy], $taxonomy);
}
}
}
// set stickiness
if ($is_original_sticky && $sitepress_settings['sync_sticky_flag']) {
stick_post($new_post_id);
} else {
if ($original_post_details->post_type == 'post' && $is_update) {
unstick_post($new_post_id);
//just in case - if this is an update and the original post stckiness has changed since the post was sent to translation
}
}
foreach ((array) $sitepress_settings['translation-management']['custom_fields_translation'] as $cf => $op) {
if ($op == 1) {
$sitepress->_sync_custom_field($translation['original_id'], $new_post_id, $cf);
} elseif ($op == 2 && isset($translation['field-' . $cf])) {
$field_translation = $translation['field-' . $cf];
$field_type = $translation['field-' . $cf . '-type'];
if ($field_type == 'custom_field') {
$field_translation = str_replace('�A;', "\n", $field_translation);
// always decode html entities eg decode & to &
$field_translation = html_entity_decode($field_translation);
update_post_meta($new_post_id, $cf, $field_translation);
}
}
}
// set specific custom fields
$copied_custom_fields = array('_top_nav_excluded', '_cms_nav_minihome');
foreach ($copied_custom_fields as $ccf) {
$val = get_post_meta($translation['original_id'], $ccf, true);
update_post_meta($new_post_id, $ccf, $val);
}
// sync _wp_page_template
if ($sitepress_settings['sync_page_template']) {
$_wp_page_template = get_post_meta($translation['original_id'], '_wp_page_template', true);
update_post_meta($new_post_id, '_wp_page_template', $_wp_page_template);
}
if (!$new_post_id) {
return false;
}
if (!$is_update) {
$wpdb->update($wpdb->prefix . 'icl_translations', array('element_id' => $new_post_id), array('translation_id' => $translation_id));
}
update_post_meta($new_post_id, '_icl_translation', 1);
TranslationManagement::set_page_url($new_post_id);
global $iclTranslationManagement;
$ts = array('status' => ICL_TM_COMPLETE, 'needs_update' => 0, 'translation_id' => $translation_id);
$translator_id = $wpdb->get_var($wpdb->prepare("SELECT translator_id FROM {$wpdb->prefix}icl_translation_status WHERE translation_id=%d", $translation_id));
if (!$translator_id) {
foreach ($sitepress_settings['icl_lang_status'] as $lpair) {
if ($lpair['from'] == $original_post_details->language_code && $lpair['to'] == $lang_code && isset($lpair['translators'][0]['id'])) {
$ts['translator_id'] = $lpair['translators'][0]['id'];
break;
}
}
}
// update translation status
$iclTranslationManagement->update_translation_status($ts);
// add new translation job
//$translation_package = $iclTranslationManagement->create_translation_package(get_post($translation['original_id']));
//$job_id = $iclTranslationManagement->add_translation_job($tinfo->rid, $tinfo->translator_id, $translation_package);
$job_id = $iclTranslationManagement->get_translation_job_id($trid, $lang_code);
// save the translation
$iclTranslationManagement->mark_job_done($job_id);
$parts = explode('_', $translation['original_id']);
if ($parts[0] != 'external') {
$iclTranslationManagement->save_job_fields_from_post($job_id, get_post($new_post_id));
$this->_content_fix_links_to_translated_content($new_post_id, $lang_code, "post_{$original_post_details->post_type}");
if (function_exists('icl_st_fix_links_in_strings')) {
icl_st_fix_links_in_strings($new_post_id);
}
// Now try to fix links in other translated content that may link to this post.
$sql = "SELECT\r\n tr.element_id\r\n FROM\r\n {$wpdb->prefix}icl_translations tr\r\n JOIN\r\n {$wpdb->prefix}icl_translation_status ts\r\n ON\r\n tr.translation_id = ts.translation_id\r\n WHERE\r\n ts.links_fixed = 0 AND tr.element_type = 'post_{$original_post_details->post_type}' AND tr.language_code = '{$lang_code}' AND tr.element_id IS NOT NULL";
$needs_fixing = $wpdb->get_results($sql);
foreach ($needs_fixing as $id) {
if ($id->element_id != $new_post_id) {
// fix all except the new_post_id. We have already done this.
$this->_content_fix_links_to_translated_content($id->element_id, $lang_code, "post_{$original_post_details->post_type}");
}
}
// if this is a parent page then make sure it's children point to this.
$this->fix_translated_children($translation['original_id'], $new_post_id, $lang_code);
}
return true;
}
示例12: icl_makes_duplicates
/**
* Build or update duplicated posts from a master post.
*
* @param string $master_post_id The ID of the post to duplicate from. Master post doesn't need to be in the default language.
*
* @uses SitePress
* @uses TranslationManagement
*/
function icl_makes_duplicates($master_post_id)
{
$post = get_post($master_post_id);
$post_type = $post->post_type;
if ($post->post_status == 'auto-draft' || $post->post_type == 'revision') {
return;
}
global $sitepress, $iclTranslationManagement;
if (!isset($iclTranslationManagement)) {
$iclTranslationManagement = new TranslationManagement();
}
if ($sitepress->is_translated_post_type($post_type)) {
$iclTranslationManagement->make_duplicates_all($master_post_id);
}
}
示例13: icl_local_edit_translator_form
/**
* Add/edit local translator form
*
* @param string $action add|edit
* @param int|object $selected_translator
*
* @global object $sitepress
* @return mixed
*/
private function icl_local_edit_translator_form($action = 'add', $selected_translator = 0)
{
global $sitepress;
$blog_users_nt = TranslationManagement::get_blog_not_translators();
$output = '';
$return['name'] = __('Local', 'wpml-translation-management');
$return['description'] = __('Your own translators', 'wpml-translation-management');
if ($action == 'add' && empty($blog_users_nt)) {
$alert_message = '<p>';
$alert_message .= __('All WordPress users are already translators. To add more translators, first create accounts for them.', 'wpml-translation-management');
$alert_message .= '</p>';
$return['content'] = '';
$return['messages'] = ICL_AdminNotifier::display_instant_message($alert_message, 'information', false, true);
return $return;
}
$output .= '<div id="icl_tm_add_user_errors">
<span class="icl_tm_no_to">' . __('Select user.', 'wpml-translation-management') . '</span>
</div>
<input type="hidden" name="icl_tm_action" value="' . $action . '_translator" />' . wp_nonce_field($action . '_translator', $action . '_translator_nonce', true, false);
if (!$selected_translator) {
$output .= '<input type="hidden" id="icl_tm_selected_user" name="user_id" />';
$output .= '<input type="text" id="icl_quick_src_users" placeholder="' . esc_attr__('search', 'wpml-translation-management') . '" />';
$output .= ' <span id="icl_user_src_nf"></span>';
$output .= '<img style="display:none;margin-left:3px;" src="' . esc_url(admin_url('images/wpspin_light.gif')) . '" class="waiting" alt="" />';
$output .= '<p>' . __('To add translators, they must first have accounts in WordPress. Translators can have any editing privileges, including subscriber.') . '</p>';
} else {
$output .= '<span class="updated fade" style="padding:4px">' . sprintf(__('Editing language pairs for <strong>%s</strong>', 'wpml-translation-management'), esc_html($selected_translator->display_name) . ' (' . $selected_translator->user_login . ')') . '</span>';
$output .= '<input type="hidden" name="user_id" value="' . $selected_translator->ID . '" />';
}
if ($selected_translator) {
$output .= '<br />
<div class="icl_tm_lang_pairs"';
if ($selected_translator) {
$output .= ' style="display:block"';
}
$output .= '>
<ul>';
$languages = $sitepress->get_active_languages();
foreach ($languages as $from_lang) {
$lang_from_selected = false;
if ($selected_translator && 0 < @count($selected_translator->language_pairs[$from_lang['code']])) {
$lang_from_selected = true;
}
$output .= '<li class="js-icl-tm-lang-from';
if ($lang_from_selected) {
$output .= ' js-lang-from-selected';
}
$output .= '">';
$output .= '<label><input class="icl_tm_from_lang" type="checkbox"';
if ($lang_from_selected) {
$output .= ' checked="checked"';
}
$output .= ' /> ';
$output .= sprintf(__('From %s', 'wpml-translation-management'), $from_lang['display_name']) . '</label>
<div class="icl_tm_lang_pairs_to"';
if ($selected_translator && 0 < @count($selected_translator->language_pairs[$from_lang['code']])) {
$output .= ' style="display:block"';
}
$output .= '>
<small>' . __('to', 'wpml-translation-management') . '</small>
<ul>';
foreach ($sitepress->get_active_languages() as $to_lang) {
if ($from_lang['code'] == $to_lang['code']) {
continue;
}
$lang_selected = false;
if ($selected_translator->ID && isset($selected_translator->language_pairs[$from_lang['code']][$to_lang['code']])) {
$lang_selected = true;
}
$output .= '<li class="js-icl-tm-lang-pair';
if ($lang_selected) {
$output .= ' js-lang-pair-selected';
}
$output .= '">
<label><input class="icl_tm_to_lang" type="checkbox" name="lang_pairs[' . $from_lang['code'] . '][' . $to_lang['code'] . ']" value="1"';
if ($lang_selected) {
$output .= ' checked="checked"';
}
$output .= ' /> ';
$output .= $to_lang['display_name'] . '</label>
</li>';
}
$output .= '</ul>
</div>
</li>';
}
$output .= '</ul>';
$output .= '
<input class="button-primary" type="submit" value="';
$output .= $selected_translator ? esc_attr(__('Update', 'wpml-translation-management')) : esc_attr(__('Add as translator', 'wpml-translation-management'));
//.........这里部分代码省略.........
示例14: _icl_translation_send_strings_local
function _icl_translation_send_strings_local($string_ids, $target)
{
global $wpdb, $sitepress_settings;
static $site_translators;
$site_translators = TranslationManagement::get_blog_translators();
$mkey = $wpdb->prefix . 'strings_notification';
$lkey = $wpdb->prefix . 'language_pairs';
$slang =& $sitepress_settings['st']['strings_language'];
foreach ($string_ids as $string_id) {
$added = icl_add_string_translation($string_id, $target, NULL, ICL_STRING_TRANSLATION_WAITING_FOR_TRANSLATOR);
if ($added) {
foreach ($site_translators as $key => $st) {
$ulangs = isset($st->{$lkey}) ? $st->{$lkey} : false;
if (!empty($ulangs) && !empty($ulangs[$slang][$target])) {
$enot = isset($st->{$mkey}) ? $st->{$mkey} : false;
if (empty($enot[$sitepress_settings['st']['strings_language']][$target])) {
_icl_st_translator_notification($st, $sitepress_settings['st']['strings_language'], $target);
$enot[$sitepress_settings['st']['strings_language']][$target] = 1;
$site_translators[$key]->{$mkey} = $enot;
update_option($wpdb->prefix . 'icl_translators_cached', $site_translators);
//printf("Notify %d for %s -> %s <br />", $st->ID, $sitepress_settings['st']['strings_language'], $target);
} else {
//printf("Already notified %d for %s -> %s <br />", $st->ID, $sitepress_settings['st']['strings_language'], $target);
}
}
}
}
}
return 1;
}
示例15: foreach
?>
" />
<?php
if (!$element->field_finished && !empty($job->prev_version)) {
?>
<?php
$prev_value = '';
foreach ($job->prev_version->elements as $pel) {
if ($element->field_type == $pel->field_type) {
$prev_value = TranslationManagement::decode_field_data($pel->field_data, $pel->field_format);
}
}
if ($element->field_format != 'csv_base64') {
$diff = wp_text_diff($prev_value, TranslationManagement::decode_field_data($element->field_data, $element->field_format));
}
if (!empty($diff)) {
?>
<p><a href="#" onclick="jQuery(this).parent().next().slideToggle();return false;"><?php
_e('Show Changes', 'sitepress');
?>
</a></p>
<div class="icl_tm_diff">
<?php
echo $diff;
?>
</div>
<?php
}
?>