blob: 0a918f47ff51045e61b5e4f38586cca1b883dc14 (
plain)
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
|
<?php
/**
* Contains class which offers functionality for statistics reporting.
*
* @file
* @author Niklas Laxström
* @author Siebrand Mazeland
* @copyright Copyright © 2010-2013, Niklas Laxström, Siebrand Mazeland
* @license GPL-2.0+
*/
/**
* Contains methods that provide statistics for message groups.
*
* @ingroup Stats
*/
class TranslationStats {
/**
* Returns translated percentage for message group in given
* languages
*
* @param $group \string Unique key identifying the group
* @param $languages \array List of language codes
* @param bool|int $threshold \int Minimum required percentage translated to
* return. Other given language codes will not be returned.
* @param $simple \bool Return only codes or code/pecentage pairs
*
* @return \array Array of key value pairs code (string)/percentage
* (float) or array of codes, depending on $simple
*/
public static function getPercentageTranslated( $group, $languages, $threshold = false,
$simple = false
) {
$stats = array();
$g = MessageGroups::singleton()->getGroup( $group );
$collection = $g->initCollection( 'en' );
foreach ( $languages as $code ) {
$collection->resetForNewLanguage( $code );
// Initialise messages
$collection->filter( 'ignored' );
$collection->filter( 'optional' );
// Store the count of real messages for later calculation.
$total = count( $collection );
$collection->filter( 'translated', false );
$translated = count( $collection );
$translatedPercentage = ( $translated * 100 ) / $total;
if ( $translatedPercentage >= $threshold ) {
if ( $simple ) {
$stats[] = $code;
} else {
$stats[$code] = $translatedPercentage;
}
}
}
return $stats;
}
}
|