wpml-tf-document-information.php
2.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
<?php
/**
* Class WPML_TF_Document_Information
*
* @author OnTheGoSystems
*/
class WPML_TF_Document_Information {
/** @var SitePress $sitepress */
protected $sitepress;
/** @var int $id */
protected $id;
/** @var string $type */
protected $type;
/** @var stdClass $language_details */
protected $language_details;
/** @var null|int|stdClass */
private $translation_job;
/**
* WPML_TF_Document_Information constructor.
*
* @param SitePress $sitepress
*/
public function __construct( SitePress $sitepress ) {
$this->sitepress = $sitepress;
}
/**
* @param int $id
* @param string $type
*/
public function init( $id, $type ) {
$this->id = $id;
$this->type = $type;
$this->language_details = $this->sitepress->get_element_language_details( $this->id, $this->type );
}
/**
* @return string|null
*/
public function get_source_language() {
return isset( $this->language_details->source_language_code )
? $this->language_details->source_language_code
: null;
}
/**
* @return string
*/
public function get_language() {
return isset( $this->language_details->language_code )
? $this->language_details->language_code
: null;
}
/**
* @return null|int
*/
public function get_job_id() {
$args = array(
'trid' => $this->get_trid(),
'language_code' => $this->get_language(),
);
$job_id = apply_filters( 'wpml_translation_job_id', false, $args );
return $job_id ? $job_id : null;
}
/**
* @return null|int
*/
protected function get_trid() {
$trid = null;
if ( isset( $this->language_details->trid ) ) {
$trid = $this->language_details->trid;
}
return $trid;
}
/**
* @param int $job_id
*
* @return bool
*/
public function is_local_translation( $job_id ) {
$is_local = true;
$translation_job = $this->get_translation_job( $job_id );
if ( isset( $translation_job->translation_service ) && 'local' !== $translation_job->translation_service ) {
$is_local = false;
}
return $is_local;
}
/**
* @param int $job_id
*
* @return int|stdClass
*/
protected function get_translation_job( $job_id ) {
if ( ! $this->translation_job ) {
$this->translation_job = apply_filters( 'wpml_get_translation_job', $job_id );
}
return $this->translation_job;
}
}