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

moved clean method to Translate instead of TranslationWriter

parent 838ca1b9
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
......@@ -33,6 +33,17 @@ class Translate
return self::$instance;
}
/**
* Clean a string that may contain HTML special chars, single/double quotes, HTML entities, leading/trailing whitespace
*
* @param string $s
* @return string
*/
static public function clean($s)
{
return html_entity_decode(trim($s), ENT_QUOTES, 'UTF-8');
}
public function loadEnglishTranslation()
{
$this->loadCoreTranslationFile('en');
......
......@@ -12,7 +12,7 @@
namespace Piwik\Translate\Filter;
use Piwik\Translate\Filter\FilterAbstract;
use Piwik\TranslationWriter;
use Piwik\Translate;
/**
* @package Piwik
......@@ -34,7 +34,7 @@ class EncodedEntities extends FilterAbstract
foreach ($pluginTranslations AS $key => $translation) {
// remove encoded entities
$decoded = TranslationWriter::clean($translation);
$decoded = Translate::clean($translation);
if ($translation != $decoded) {
$this->_filteredData[$pluginName][$key] = $translation;
$translations[$pluginName][$key] = $decoded;
......
......@@ -16,7 +16,7 @@ use Piwik\Common;
use Piwik\Plugins\Goals\API;
use Piwik\Plugins\Goals\Archiver;
use Piwik\Tracker\GoalManager;
use Piwik\TranslationWriter;
use Piwik\Translate;
use Piwik\Site;
use Piwik\WidgetsList;
use Piwik\Db;
......@@ -471,7 +471,7 @@ class Goals extends \Piwik\Plugin
}
Piwik_AddMenu($mainGoalMenu, 'Goals_GoalsOverview', array('module' => 'Goals', 'action' => 'index'), true, 2);
foreach ($goals as $goal) {
Piwik_AddMenu($mainGoalMenu, str_replace('%', '%%', TranslationWriter::clean($goal['name'])), array('module' => 'Goals', 'action' => 'goalReport', 'idGoal' => $goal['idgoal']));
Piwik_AddMenu($mainGoalMenu, str_replace('%', '%%', Translate::clean($goal['name'])), array('module' => 'Goals', 'action' => 'goalReport', 'idGoal' => $goal['idgoal']));
}
}
}
......
<?php
use Piwik\Common;
use Piwik\Translate;
/**
* Piwik - Open source web analytics
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*/
class TranslateTest extends PHPUnit_Framework_TestCase
{
/**
* Dataprovider for testClean
*/
public function getCleanTestData()
{
return array(
// empty string
array("", ''),
// newline
array("\n", ''),
// leading and trailing whitespace
array(" a \n", 'a'),
// single / double quotes
array(" &quot;it&#039;s&quot; ", '"it\'s"'),
// html special characters
array("&lt;tag&gt;", '<tag>'),
// other html entities
array("&hellip;", '…'),
);
}
/**
* @group Core
* @group Translate
* @dataProvider getCleanTestData
*/
public function testClean($data, $expected)
{
$this->assertEquals($expected, Translate::clean($data));
}
}
\ No newline at end of file
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