wpml-tm-word-count-set-package.php
1.14 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
<?php
class WPML_TM_Word_Count_Set_Package {
/** @var WPML_ST_Package_Factory $package_factory */
private $package_factory;
/** @var WPML_TM_Word_Count_Records $records */
private $records;
/** @var array $active_langs */
private $active_langs;
public function __construct(
WPML_ST_Package_Factory $package_factory,
WPML_TM_Word_Count_Records $records,
array $active_langs
) {
$this->package_factory = $package_factory;
$this->records = $records;
$this->active_langs = $active_langs;
}
/** @param int $package_id */
public function process( $package_id ) {
$package = $this->package_factory->create( $package_id );
$word_counts = new WPML_TM_Count();
foreach ( $this->active_langs as $lang ) {
if ( $package->get_package_language() === $lang ) {
$word_counts->set_total_words(
$this->records->get_string_words_to_translate_per_lang( null, $package_id )
);
} else {
$word_counts->set_words_to_translate(
$lang,
$this->records->get_string_words_to_translate_per_lang( $lang, $package_id )
);
}
}
$this->records->set_package_word_count( $package_id, $word_counts );
}
}