示例#1
0
 public function create_translation($locale)
 {
     $client = new Lingotek_API();
     if (false === ($translation = $client->get_translation($this->document_id, $locale, $this->source))) {
         return;
     }
     self::$creating_translation = true;
     $translation = json_decode($translation, true);
     // wp_insert_post expects array
     $args = $translation['args'];
     // update existing translation
     if ($tr_id = $this->pllm->get_term($this->source, $locale)) {
         $args['name'] = $translation['name'];
         wp_update_term($tr_id, $this->type, $args);
         $this->safe_translation_status_update($locale, 'current');
     } else {
         $tr_lang = $this->pllm->get_language($locale);
         // translate parent
         $term = get_term($this->source, $this->type);
         $args['parent'] = $term->parent && ($tr_parent = $this->pllm->get_translation('term', $term->parent, $locale)) ? $tr_parent : 0;
         // attempt to get a unique slug in case it already exists in another language
         if (isset($args['slug']) && term_exists($args['slug'])) {
             $args['slug'] .= '-' . $tr_lang->slug;
         }
         $tr = wp_insert_term($translation['name'], $this->type, $args);
         if (!is_wp_error($tr)) {
             $this->pllm->set_term_language($tr['term_id'], $tr_lang);
             $this->safe_translation_status_update($locale, 'current', array($tr_lang->slug => $tr['term_id']));
             wp_set_object_terms($tr['term_id'], $this->term_id, 'term_translations');
         }
     }
     self::$creating_translation = false;
 }
示例#2
0
 public function upload_term($term_id, $taxonomy)
 {
     $term = get_term($term_id, $taxonomy);
     $language = $this->pllm->get_term_language($term_id);
     if (empty($term) || empty($language)) {
         return;
     }
     $profile = self::get_profile($taxonomy, $language);
     if ('disabled' == $profile['profile']) {
         return;
     }
     $client = new Lingotek_API();
     $params = array('title' => $term->name, 'content' => Lingotek_Group_Term::get_content($term), 'locale_code' => $language->lingotek_locale, 'project_id' => self::get_profile_option('project_id', $taxonomy, $language), 'workflow_id' => self::get_profile_option('workflow_id', $taxonomy, $language));
     $filter_ids = array();
     if (self::get_profile_option('primary_filter_id', $taxonomy, $language)) {
         $filter_ids['fprm_id'] = self::get_profile_option('primary_filter_id', $taxonomy, $language);
     }
     if (self::get_profile_option('secondary_filter_id', $taxonomy, $language)) {
         $filter_ids['fprm_subfilter_id'] = self::get_profile_option('secondary_filter_id', $taxonomy, $language);
     }
     $params = array_merge($params, $filter_ids);
     if (($document = $this->get_group('term', $term_id)) && 'edited' == $document->status) {
         $document->patch($term->name, $term, '', $filter_ids);
     } elseif (!Lingotek_Group::$creating_translation && !self::$copying_term) {
         $document_id = $client->upload_document($params, $term_id);
         if ($document_id) {
             Lingotek_Group_Term::create($term_id, $taxonomy, $language, $document_id);
             // If a translation profile has targets set to copy then copy them
             $targets_to_copy = $this->targets_to_be_copied($profile);
             if (!empty($targets_to_copy)) {
                 foreach ($targets_to_copy as $target) {
                     $this->copy_term($term, $target, $taxonomy);
                 }
             }
         }
     }
 }
示例#3
0
 public function edited_term($term_id, $tt_id, $taxonomy)
 {
     if (pll_is_translated_taxonomy($taxonomy)) {
         $document = $this->lgtm->get_group('term', $term_id);
         if ($document && $term_id == $document->source && md5(Lingotek_Group_Term::get_content(get_term($term_id, $taxonomy))) != $this->old_term) {
             $document->source_edited();
             if ($document->is_automatic_upload()) {
                 $this->lgtm->upload_term($term_id, $taxonomy);
             }
         }
     }
 }
示例#4
0
<?php

global $polylang;
foreach ($polylang->model->get_translated_post_types() as $post_type) {
    $post_type_object = get_post_type_object($post_type);
    $data[$post_type] = array('type' => $post_type, 'name' => $post_type_object->labels->name, 'fields' => array('label' => Lingotek_Group_Post::get_content_type_fields($post_type)));
}
foreach ($polylang->model->get_translated_taxonomies() as $tax) {
    $taxonomy = get_taxonomy($tax);
    $data[$tax] = array('type' => $tax, 'name' => $taxonomy->labels->name, 'fields' => array('label' => Lingotek_Group_Term::get_content_type_fields($tax)));
}
$data['string'] = array('type' => 'string', 'name' => __('Strings', 'wp-lingotek'));
if (empty($_POST)) {
    $content_types = get_option('lingotek_content_type');
} else {
    check_admin_referer('lingotek-content-types', '_wpnonce_lingotek-content-types');
    $profiles = array_keys(get_option('lingotek_profiles'));
    foreach ($data as $key => $item) {
        if (isset($data[$key]['name'])) {
            if (in_array($_POST[$key]['profile'], $profiles)) {
                $content_types[$key]['profile'] = $_POST[$key]['profile'];
            }
            foreach ($polylang->model->get_languages_list() as $language) {
                if (isset($_POST[$key]['sources'][$language->slug]) && in_array($_POST[$key]['sources'][$language->slug], $profiles)) {
                    $content_types[$key]['sources'][$language->slug] = $_POST[$key]['sources'][$language->slug];
                }
            }
        }
        if (isset($data[$key]['fields'])) {
            foreach ($data[$key]['fields']['label'] as $key1 => $arr) {
                if (is_array($arr)) {