Skip to content
Extraits de code Groupes Projets
Valider 516dae50 rédigé par sgiehl's avatar sgiehl
Parcourir les fichiers

added translations filter for empty translations

parent 3d68097b
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
<?php
/**
* Piwik - Open source web analytics
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*
* @category Piwik
* @package Piwik
*/
namespace Piwik\Translate\Filter;
use Piwik\Translate\Filter\FilterAbstract;
/**
* @package Piwik
* @subpackage Piwik_Translate
*/
class EmptyTranslations extends FilterAbstract
{
/**
* Filter the given translations
*
* @param array $translations
*
* @return array filtered translations
*
*/
public function filter($translations)
{
$translationsBefore = $translations;
foreach ($translations AS $plugin => &$pluginTranslations) {
$pluginTranslations = array_filter($pluginTranslations, function($value) {
return !empty($value) && '' != trim($value);
});
$diff = array_diff($translationsBefore[$plugin], $pluginTranslations);
if (!empty($diff)) $this->_filteredData[$plugin] = $diff;
}
// remove plugins without translations
$translations = array_filter($translations, function($value) {
return !empty($value) && count($value);
});
return $translations;
}
}
\ No newline at end of file
<?php
/**
* Piwik - Open source web analytics
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*
* @category Piwik
* @package Piwik
*/
namespace Piwik\Translate\Filter;
/**
* @package Piwik
* @subpackage Piwik_Db
*/
abstract class FilterAbstract
{
protected $_filteredData = array();
protected $_baseTranslations = array();
/**
* Sets base translations
*
* @param array $baseTranslations
*/
public function __construct($baseTranslations=array())
{
$this->_baseTranslations = $baseTranslations;
}
/**
* Filter the given translations
*
* @param array $translations
*
* @return array filtered translations
*
*/
abstract public function filter($translations);
/**
* Returnes the data filtered out by the filter
*
* @return array
*/
public function getFilteredData()
{
return $this->_filteredData;
}
}
\ No newline at end of file
<?php
use Piwik\Translate\Filter\EmptyTranslations;
/**
* Piwik - Open source web analytics
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*/
class EmptyTranslationsTest extends PHPUnit_Framework_TestCase
{
public function getFilterTestData()
{
return array(
// empty stays empty
array(
array(),
array(),
array()
),
// empty plugin is removed
array(
array(
'test' => array()
),
array(),
array(),
),
// empty values/plugins are removed
array(
array(
'test' => array(
'empty' => '',
'whitespace' => ' '
)
),
array(),
array(
'test' => array(
'empty' => '',
'whitespace' => ' '
)
),
),
// no change if no empty value
array(
array(
'test' => array(
'test' => 'test'
)
),
array(
'test' => array(
'test' => 'test'
)
),
array()
),
// empty values are removed, others stay
array(
array(
'empty' => array(),
'test' => array(
'test' => 'test',
'empty' => ' ',
)
),
array(
'test' => array(
'test' => 'test'
)
),
array(
'test' => array(
'empty' => ' ',
)
)
),
);
}
/**
* @dataProvider getFilterTestData
* @group Core
* @group Translate
*/
public function testFilter($translations, $expected, $filteredData)
{
$filter = new EmptyTranslations();
$result = $filter->filter($translations);
$this->assertEquals($expected, $result);
$this->assertEquals($filteredData, $filter->getFilteredData());
}
}
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter