wpml-tm-count.php
1.32 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
<?php
class WPML_TM_Count implements IWPML_TM_Count {
/** @var int $total */
private $total = 0;
/** @var array $to_translate */
private $to_translate;
/**
* @param string|null $json_data
*/
public function __construct( $json_data = null ) {
if ( $json_data ) {
$this->set_properties_from_json( $json_data );
}
}
/** @param string $json_data */
public function set_properties_from_json( $json_data ) {
$data = json_decode( $json_data, true );
if ( isset( $data['total'] ) ) {
$this->total = (int) $data['total'];
}
if ( isset( $data['to_translate'] ) ) {
$this->to_translate = $data['to_translate'];
}
}
/** @return int */
public function get_total_words() {
return $this->total;
}
/** @param int $total */
public function set_total_words( $total ) {
$this->total = $total;
}
/**
* @param string $lang
*
* @return int|null
*/
public function get_words_to_translate( $lang ) {
if ( isset( $this->to_translate[ $lang ] ) ) {
return (int) $this->to_translate[ $lang ];
}
return null;
}
/** @return string */
public function to_string() {
return json_encode(
array(
'total' => $this->total,
'to_translate' => $this->to_translate,
)
);
}
public function set_words_to_translate( $lang, $quantity ) {
$this->to_translate[ $lang ] = $quantity;
}
}