wpml-st-translations-file-mo.php
1.08 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
<?php
class WPML_ST_Translations_File_MO implements IWPML_ST_Translations_File {
/** @var string $filepath */
private $filepath;
/**
* @param string $filepath
*/
public function __construct( $filepath ) {
$this->filepath = $filepath;
}
/**
* @return WPML_ST_Translations_File_Translation[]
*/
public function get_translations() {
$translations = array();
$mo = new MO();
$pomo_reader = new POMO_CachedFileReader( $this->filepath );
// @see wpmldev-1856
/** @phpstan-ignore-next-line */
$mo->import_from_reader( $pomo_reader );
foreach ( $mo->entries as $str => $v ) {
$str = str_replace( "\n", '\n', $v->singular );
$translations[] = new WPML_ST_Translations_File_Translation( $str, $v->translations[0], $v->context );
if ( $v->is_plural ) {
$str = str_replace( "\n", '\n', $v->plural );
$translation = ! empty( $v->translations[1] ) ? $v->translations[1] : $v->translations[0];
$translations[] = new WPML_ST_Translations_File_Translation( $str, $translation, $v->context );
}
}
return $translations;
}
}