wpml-st-translations-file-scan.php
1.25 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
<?php
class WPML_ST_Translations_File_Scan {
/**
* @var WPML_ST_Translations_File_Scan_Db_Charset_Filter_Factory
*/
private $charset_filter_factory;
/**
* @param WPML_ST_Translations_File_Scan_Db_Charset_Filter_Factory $charset_filter_factory
*/
public function __construct( WPML_ST_Translations_File_Scan_Db_Charset_Filter_Factory $charset_filter_factory ) {
$this->charset_filter_factory = $charset_filter_factory;
}
/**
* @param string $file
*
* @return WPML_ST_Translations_File_Translation[]
*/
public function load_translations( $file ) {
if ( ! file_exists( $file ) ) {
return array();
}
$translations = array();
$file_type = pathinfo( $file, PATHINFO_EXTENSION );
switch ( $file_type ) {
case 'mo':
$translations_file = new WPML_ST_Translations_File_MO( $file );
$translations = $translations_file->get_translations();
break;
case 'json':
$translations_file = new WPML_ST_Translations_File_JED( $file );
$translations = $translations_file->get_translations();
break;
}
$unicode_characters_filter = $this->charset_filter_factory->create();
if ( $unicode_characters_filter ) {
$translations = $unicode_characters_filter->filter( $translations );
}
return $translations;
}
}