wpml-st-translations-file-dictionary.php
2.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
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
<?php
use WPML\ST\TranslationFile\EntryQueries;
class WPML_ST_Translations_File_Dictionary {
/** @var WPML_ST_Translations_File_Dictionary_Storage */
private $storage;
/**
* @param WPML_ST_Translations_File_Dictionary_Storage $storage
*/
public function __construct( WPML_ST_Translations_File_Dictionary_Storage $storage ) {
$this->storage = $storage;
}
/**
* @param string $file_path
*
* @return WPML_ST_Translations_File_Entry|null
*/
public function find_file_info_by_path( $file_path ) {
$result = $this->storage->find( $file_path );
if ( $result ) {
return current( $result );
}
return null;
}
/**
* @param WPML_ST_Translations_File_Entry $file
*/
public function save( WPML_ST_Translations_File_Entry $file ) {
$this->storage->save( $file );
}
/**
* @return WPML_ST_Translations_File_Entry[]
*/
public function get_not_imported_files() {
return $this->storage->find(
null,
[
WPML_ST_Translations_File_Entry::NOT_IMPORTED,
WPML_ST_Translations_File_Entry::PARTLY_IMPORTED,
]
);
}
public function clear_skipped() {
$skipped = wpml_collect( $this->storage->find( null, [ WPML_ST_Translations_File_Entry::SKIPPED ] ) );
$skipped->each(
function ( WPML_ST_Translations_File_Entry $entry ) {
$entry->set_status( WPML_ST_Translations_File_Entry::NOT_IMPORTED );
$this->storage->save( $entry );
}
);
}
/**
* @return WPML_ST_Translations_File_Entry[]
*/
public function get_imported_files() {
return $this->storage->find( null, WPML_ST_Translations_File_Entry::IMPORTED );
}
/**
* @param null|string $extension
* @param null|string $locale
*
* @return array
*/
public function get_domains( $extension = null, $locale = null ) {
$files = wpml_collect( $this->storage->find() );
if ( $extension ) {
$files = $files->filter( EntryQueries::isExtension( $extension ) );
}
if ( $locale ) {
$files = $files->filter(
function ( WPML_ST_Translations_File_Entry $file ) use ( $locale ) {
return $file->get_file_locale() === $locale;
}
);
}
return $files->map( EntryQueries::getDomain() )
->unique()
->values()
->toArray();
}
}