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

added translations filter to filter by available base translations

parent 516dae50
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 ByBaseTranslations extends FilterAbstract
{
/**
* Filter the given translations
*
* @param array $translations
*
* @return array filtered translations
*
*/
public function filter($translations)
{
$cleanedTranslations = array();
// filter out all translations that don't exist in english translations
foreach ($translations AS $pluginName => $pluginTranslations) {
if (empty($this->_baseTranslations[$pluginName])) {
$this->_filteredData[$pluginName] = $pluginTranslations;
continue;
}
foreach ($pluginTranslations as $key => $translation) {
if (isset($this->_baseTranslations[$pluginName][$key])) {
$cleanedTranslations[$pluginName][$key] = $translation;
}
}
if (!empty($cleanedTranslations[$pluginName])) {
$diff = array_diff($translations[$pluginName], $cleanedTranslations[$pluginName]);
} else {
$diff = $translations[$pluginName];
}
if (!empty($diff)) $this->_filteredData[$pluginName] = $diff;
}
return $cleanedTranslations;
}
}
\ No newline at end of file
<?php
use Piwik\Translate\Filter\ByBaseTranslations;
/**
* Piwik - Open source web analytics
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*/
class ByBaseTranslationsTest extends PHPUnit_Framework_TestCase
{
public function getFilterTestData()
{
return array(
// empty stays empty
array(
array(),
array(),
array(),
array()
),
// empty plugin is removed
array(
array(
'test' => array()
),
array(),
array(),
array(
'test' => array()
),
),
// empty values/plugins are removed
array(
array(
'test' => array(
'key' => 'value',
'test' => 'test'
)
),
array(
'test' => array(
'key' => 'value',
'x' => 'y'
)
),
array(
'test' => array(
'key' => 'value',
)
),
array(
'test' => array(
'test' => 'test',
)
),
),
// no change if no empty value
array(
array(
'test' => array(
'test' => 'test'
)
),
array(
'test' => array(
'test' => 'test'
)
),
array(
'test' => array(
'test' => 'test'
)
),
array()
),
// empty values are removed, others stay
array(
array(
'empty' => array(
'test' => 'test'
),
'test' => array(
'test' => 'test',
'empty' => ' ',
)
),
array(
'empty' => array(
'test' => 'test'
),
'test' => array(
'test' => 'test',
)
),
array(
'empty' => array(
'test' => 'test'
),
'test' => array(
'test' => 'test'
)
),
array(
'test' => array(
'empty' => ' ',
)
)
),
);
}
/**
* @dataProvider getFilterTestData
* @group Core
* @group Translate
*/
public function testFilter($translations, $baseTranslations, $expected, $filteredData)
{
$filter = new ByBaseTranslations($baseTranslations);
$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.
Veuillez vous inscrire ou vous pour commenter