diff options
author | Matthieu Napoli <matthieu@mnapoli.fr> | 2014-12-30 03:37:07 +0300 |
---|---|---|
committer | Matthieu Napoli <matthieu@mnapoli.fr> | 2015-01-05 05:25:13 +0300 |
commit | 0e0fc76d83fc3de130b46ebf76f22dab87a66650 (patch) | |
tree | dcc2e0be945aaa6cff19b82a7739253fc829ff79 | |
parent | 62194cf004dfdb528c3ca5b59289660634f1369f (diff) |
Fixed typo that crept in
22 files changed, 86 insertions, 58 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 75e5b5e458..79d6020320 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,9 @@ This is a changelog for Piwik platform developers. All changes for our HTTP API' ### Breaking Changes * The event `User.getLanguage` has been removed. +### Deprecations +* The `Piwik\Translate` class has been deprecated in favor of `Piwik\Translation\Translator`. + ## Piwik 2.10.0 ### Breaking Changes diff --git a/core/FrontController.php b/core/FrontController.php index 89e91b943b..28031e863b 100644 --- a/core/FrontController.php +++ b/core/FrontController.php @@ -442,7 +442,6 @@ class FrontController extends Singleton } SettingsServer::raiseMemoryLimitIfNecessary(); - Translate::reloadLanguage(); \Piwik\Plugin\Manager::getInstance()->postLoadPlugins(); /** diff --git a/core/Piwik.php b/core/Piwik.php index e3d1d5ba35..2227eca2e4 100644 --- a/core/Piwik.php +++ b/core/Piwik.php @@ -735,15 +735,16 @@ class Piwik * @param string $translationId Translation ID, eg, `'General_Date'`. * @param array|string|int $args `sprintf` arguments to be applied to the internationalized * string. + * @param string|null $language Optionally force the language. * @return string The translated string or `$translationId`. * @api */ - public static function translate($translationId, $args = array()) + public static function translate($translationId, $args = array(), $language = null) { /** @var Translator $translator */ $translator = StaticContainer::getContainer()->get('Piwik\Translation\Translator'); - return $translator->translate($translationId, $args); + return $translator->translate($translationId, $args, $language); } /** diff --git a/core/Tracker/ScheduledTasksRunner.php b/core/Tracker/ScheduledTasksRunner.php index 3f4602ef2b..2a4683a4cb 100644 --- a/core/Tracker/ScheduledTasksRunner.php +++ b/core/Tracker/ScheduledTasksRunner.php @@ -78,10 +78,6 @@ class ScheduledTasksRunner // Scheduled tasks assume Super User is running Piwik::setUserHasSuperUserAccess(); - // While each plugins should ensure that necessary languages are loaded, - // we ensure English translations at least are loaded - Translate::loadEnglishTranslation(); - ob_start(); CronArchive::$url = SettingsPiwik::getPiwikUrl(); $cronArchive = new CronArchive(); diff --git a/core/Translate.php b/core/Translate.php index c828ed3d1d..eb7f19f21d 100644 --- a/core/Translate.php +++ b/core/Translate.php @@ -10,6 +10,7 @@ namespace Piwik; use Exception; use Piwik\Container\StaticContainer; +use Piwik\Plugin\Manager; use Piwik\Translation\Translator; /** @@ -29,16 +30,25 @@ class Translate return html_entity_decode(trim($s), ENT_QUOTES, 'UTF-8'); } + /** + * @deprecated + */ public static function loadEnglishTranslation() { - self::loadCoreTranslation(); + self::loadAllTranslations(); } + /** + * @deprecated + */ public static function unloadEnglishTranslation() { - self::getTranslator()->reset(); + self::reset(); } + /** + * @deprecated + */ public static function reloadLanguage($language = false) { } @@ -54,6 +64,9 @@ class Translate self::getTranslator()->addDirectory(PIWIK_INCLUDE_PATH . '/lang'); } + /** + * @deprecated + */ public static function mergeTranslationArray($translation) { } @@ -107,4 +120,10 @@ class Translate { return StaticContainer::getContainer()->get('Piwik\Translation\Translator'); } + + public static function loadAllTranslations() + { + self::loadCoreTranslation(); + Manager::getInstance()->loadPluginTranslations(); + } } diff --git a/core/Translation/Translator.php b/core/Translation/Translator.php index 9d256b6940..a9099e2971 100644 --- a/core/Translation/Translator.php +++ b/core/Translation/Translator.php @@ -68,16 +68,19 @@ class Translator * @param string $translationId Translation ID, eg, `General_Date`. * @param array|string|int $args `sprintf` arguments to be applied to the internationalized * string. + * @param string|null $language Optionally force the language. * @return string The translated string or `$translationId`. * @api */ - public function translate($translationId, $args = array()) + public function translate($translationId, $args = array(), $language = null) { $args = is_array($args) ? $args : array($args); if (strpos($translationId, "_") !== false) { list($plugin, $key) = explode("_", $translationId, 2); - $translationId = $this->getTranslation($translationId, $this->currentLanguage, $plugin, $key); + $language = is_string($language) ? $language : $this->currentLanguage; + + $translationId = $this->getTranslation($translationId, $language, $plugin, $key); } if (count($args) == 0) { diff --git a/plugins/API/API.php b/plugins/API/API.php index 8e87532367..be03396f68 100644 --- a/plugins/API/API.php +++ b/plugins/API/API.php @@ -12,6 +12,7 @@ use Piwik\API\Proxy; use Piwik\API\Request; use Piwik\Columns\Dimension; use Piwik\Config; +use Piwik\Container\StaticContainer; use Piwik\DataTable; use Piwik\DataTable\Filter\ColumnDelete; use Piwik\DataTable\Row; @@ -25,6 +26,7 @@ use Piwik\Plugin\Dimension\VisitDimension; use Piwik\Plugins\CoreAdminHome\CustomLogo; use Piwik\Segment\SegmentExpression; use Piwik\Translate; +use Piwik\Translation\Translator; use Piwik\Version; require_once PIWIK_INCLUDE_PATH . '/core/Config.php'; @@ -321,7 +323,10 @@ class API extends \Piwik\Plugin\API public function getMetadata($idSite, $apiModule, $apiAction, $apiParameters = array(), $language = false, $period = false, $date = false, $hideMetricsDoc = false, $showSubtableReports = false) { - Translate::reloadLanguage($language); + /** @var Translator $translator */ + $translator = StaticContainer::getContainer()->get('Piwik\Translation\Translator'); + $translator->setCurrentLanguage($language); + $reporter = new ProcessedReport(); $metadata = $reporter->getMetadata($idSite, $apiModule, $apiAction, $apiParameters, $language, $period, $date, $hideMetricsDoc, $showSubtableReports); return $metadata; diff --git a/plugins/Actions/tests/Unit/ArchiverTest.php b/plugins/Actions/tests/Unit/ArchiverTest.php index a3ba57511a..ee1fe940ee 100644 --- a/plugins/Actions/tests/Unit/ArchiverTest.php +++ b/plugins/Actions/tests/Unit/ArchiverTest.php @@ -23,12 +23,12 @@ class ArchiverTests extends \PHPUnit_Framework_TestCase { public function setUp() { - Translate::reloadLanguage('en'); + Translate::loadAllTranslations(); } public function tearDown() { - Translate::unloadEnglishTranslation(); + Translate::reset(); } public function getActionNameTestData() diff --git a/plugins/Contents/tests/System/ContentsTest.php b/plugins/Contents/tests/System/ContentsTest.php index b555cf7962..ccb7a69086 100644 --- a/plugins/Contents/tests/System/ContentsTest.php +++ b/plugins/Contents/tests/System/ContentsTest.php @@ -47,12 +47,13 @@ class ContentsTest extends SystemTestCase protected function setup() { parent::setup(); - Translate::reloadLanguage('en'); + Translate::loadAllTranslations(); } protected function tearDown() { parent::tearDown(); + Translate::reset(); } public function getApiForTesting() diff --git a/plugins/Feedback/API.php b/plugins/Feedback/API.php index ce6acdce20..70ba272d4d 100644 --- a/plugins/Feedback/API.php +++ b/plugins/Feedback/API.php @@ -80,22 +80,12 @@ class API extends \Piwik\Plugin\API private function getEnglishTranslationForFeatureName($featureName) { - $loadedLanguage = Translate::getLanguageLoaded(); - - if ($loadedLanguage == 'en') { + if (Translate::getLanguageLoaded() == 'en') { return $featureName; } $translationKeyForFeature = Translate::findTranslationKeyForTranslation($featureName); - if (!empty($translationKeyForFeature)) { - Translate::reloadLanguage('en'); - - $featureName = Piwik::translate($translationKeyForFeature); - Translate::reloadLanguage($loadedLanguage); - return $featureName; - } - - return $featureName; + return Piwik::translate($translationKeyForFeature, array(), 'en'); } } diff --git a/plugins/Insights/tests/Integration/ApiTest.php b/plugins/Insights/tests/Integration/ApiTest.php index 6eeac84700..56d51add2d 100644 --- a/plugins/Insights/tests/Integration/ApiTest.php +++ b/plugins/Insights/tests/Integration/ApiTest.php @@ -41,10 +41,17 @@ class ApiTest extends SystemTestCase PiwikCache::flushAll(); - Translate::reloadLanguage('en'); + Translate::loadAllTranslations(); $this->api = API::getInstance(); } + public function tearDown() + { + parent::tearDown(); + + Translate::reset(); + } + /** * '/Mover1' => 2, +8 // 400% * '/Old1' => 9, -9 // -100% diff --git a/plugins/Installation/Installation.php b/plugins/Installation/Installation.php index 427d3d502e..3d501c2627 100644 --- a/plugins/Installation/Installation.php +++ b/plugins/Installation/Installation.php @@ -91,8 +91,6 @@ class Installation extends \Piwik\Plugin $message = ''; } - Translate::reloadLanguage(); - $action = Common::getRequestVar('action', 'welcome', 'string'); if ($this->isAllowedAction($action)) { diff --git a/plugins/ScheduledReports/API.php b/plugins/ScheduledReports/API.php index 1eade02df0..d93e252793 100644 --- a/plugins/ScheduledReports/API.php +++ b/plugins/ScheduledReports/API.php @@ -11,6 +11,7 @@ namespace Piwik\Plugins\ScheduledReports; use Exception; use Piwik\Common; use Piwik\Config; +use Piwik\Container\StaticContainer; use Piwik\Date; use Piwik\Db; use Piwik\Log; @@ -23,6 +24,7 @@ use Piwik\ReportRenderer; use Piwik\Site; use Piwik\Tracker; use Piwik\Translate; +use Piwik\Translation\Translator; /** * The ScheduledReports API lets you manage Scheduled Email reports, as well as generate, download or email any existing report. @@ -270,7 +272,9 @@ class API extends \Piwik\Plugin\API $language = Translate::getLanguageDefault(); } - Translate::reloadLanguage($language); + /** @var Translator $translator */ + $translator = StaticContainer::getContainer()->get('Piwik\Translation\Translator'); + $translator->setCurrentLanguage($language); $reports = $this->getReports($idSite = false, $_period = false, $idReport); $report = reset($reports); diff --git a/tests/PHPUnit/Framework/Fixture.php b/tests/PHPUnit/Framework/Fixture.php index 5cf7c1d597..751c4ce1ab 100644 --- a/tests/PHPUnit/Framework/Fixture.php +++ b/tests/PHPUnit/Framework/Fixture.php @@ -217,7 +217,7 @@ class Fixture extends \PHPUnit_Framework_Assert // Make sure translations are loaded to check messages in English if ($this->loadTranslations) { - Translate::reloadLanguage('en'); + Translate::loadAllTranslations(); APILanguageManager::getInstance()->setLanguageForUser('superUserLogin', 'en'); } @@ -314,7 +314,7 @@ class Fixture extends \PHPUnit_Framework_Assert EventDispatcher::getInstance()->clearAllObservers(); $_GET = $_REQUEST = array(); - Translate::unloadEnglishTranslation(); + Translate::reset(); Config::unsetInstance(); diff --git a/tests/PHPUnit/Framework/TestCase/SystemTestCase.php b/tests/PHPUnit/Framework/TestCase/SystemTestCase.php index 6429f5cf4f..8e63da92b8 100755 --- a/tests/PHPUnit/Framework/TestCase/SystemTestCase.php +++ b/tests/PHPUnit/Framework/TestCase/SystemTestCase.php @@ -12,7 +12,7 @@ use Exception; use Piwik\ArchiveProcessor\Rules; use Piwik\Common; use Piwik\Config; -use Piwik\DataAccess\ArchiveTableCreator; +use Piwik\Container\StaticContainer; use Piwik\Db; use Piwik\DbHelper; use Piwik\ReportRenderer; @@ -24,6 +24,7 @@ use Piwik\Translate; use Piwik\Log; use PHPUnit_Framework_TestCase; use Piwik\Tests\Framework\Fixture; +use Piwik\Translation\Translator; require_once PIWIK_INCLUDE_PATH . '/libs/PiwikTracker/PiwikTracker.php'; @@ -492,8 +493,9 @@ abstract class SystemTestCase extends PHPUnit_Framework_TestCase { if ($this->lastLanguage != $langId) { $_GET['language'] = $langId; - Translate::reset(); - Translate::reloadLanguage($langId); + /** @var Translator $translator */ + $translator = StaticContainer::getContainer()->get('Piwik\Translation\Translator'); + $translator->setCurrentLanguage($langId); } $this->lastLanguage = $langId; diff --git a/tests/PHPUnit/Integration/CacheIdTest.php b/tests/PHPUnit/Integration/CacheIdTest.php index 01d39d7e49..b549bc9668 100644 --- a/tests/PHPUnit/Integration/CacheIdTest.php +++ b/tests/PHPUnit/Integration/CacheIdTest.php @@ -20,12 +20,12 @@ class CacheIdTest extends IntegrationTestCase { public function setUp() { - Translate::loadEnglishTranslation(); + Translate::loadAllTranslations(); } public function tearDown() { - Translate::unloadEnglishTranslation(); + Translate::reset(); } public function test_languageAware_shouldAppendTheLoadedLanguage() diff --git a/tests/PHPUnit/Integration/ReportTest.php b/tests/PHPUnit/Integration/ReportTest.php index 1e141db383..21e8a52542 100644 --- a/tests/PHPUnit/Integration/ReportTest.php +++ b/tests/PHPUnit/Integration/ReportTest.php @@ -116,7 +116,6 @@ class ReportTest extends IntegrationTestCase { WidgetsList::getInstance()->_reset(); MenuReporting::getInstance()->unsetInstance(); - Translate::unloadEnglishTranslation(); unset($_GET['idSite']); parent::tearDown(); } @@ -157,14 +156,16 @@ class ReportTest extends IntegrationTestCase public function test_getWidgetTitle_shouldReturnTranslatedTitleIfSet() { - $this->loadEnglishTranslation(); + Translate::loadAllTranslations(); $this->assertEquals('Page Titles Following a Site Search', $this->advancedReport->getWidgetTitle()); + Translate::reset(); } public function test_getCategory_shouldReturnTranslatedCategory() { - $this->loadEnglishTranslation(); + Translate::loadAllTranslations(); $this->assertEquals('Goals', $this->advancedReport->getCategory()); + Translate::reset(); } public function test_configureWidget_shouldNotAddAWidgetIfNoWidgetTitleIsSet() @@ -539,9 +540,4 @@ class ReportTest extends IntegrationTestCase { PluginManager::getInstance()->unloadPlugins(); } - - private function loadEnglishTranslation() - { - Translate::reloadLanguage('en'); - } } diff --git a/tests/PHPUnit/Integration/Tracker/ActionTest.php b/tests/PHPUnit/Integration/Tracker/ActionTest.php index 1ca87f9678..a00ea4c9b3 100644 --- a/tests/PHPUnit/Integration/Tracker/ActionTest.php +++ b/tests/PHPUnit/Integration/Tracker/ActionTest.php @@ -40,7 +40,14 @@ class ActionTest extends IntegrationTestCase PluginManager::getInstance()->loadPlugins(array('SitesManager')); - Translate::loadEnglishTranslation(); + Translate::loadAllTranslations(); + } + + public function tearDown() + { + parent::tearDown(); + + Translate::reset(); } protected function setUpRootAccess() diff --git a/tests/PHPUnit/Integration/WidgetsListTest.php b/tests/PHPUnit/Integration/WidgetsListTest.php index fc00be7799..22967a9d2d 100644 --- a/tests/PHPUnit/Integration/WidgetsListTest.php +++ b/tests/PHPUnit/Integration/WidgetsListTest.php @@ -164,7 +164,7 @@ class WidgetsListTest extends IntegrationTestCase FakeAccess::$superUser = true; Access::setSingletonInstance($pseudoMockAccess); - Translate::loadEnglishTranslation(); + Translate::loadAllTranslations(); Fixture::createWebsite('2009-01-04 00:11:42', true); @@ -175,5 +175,7 @@ class WidgetsListTest extends IntegrationTestCase $this->assertTrue(WidgetsList::isDefined('Actions', 'getPageUrls')); $this->assertFalse(WidgetsList::isDefined('Actions', 'inValiD')); + + Translate::reset(); } } diff --git a/tests/PHPUnit/Unit/Metrics/Formatter/HtmlTest.php b/tests/PHPUnit/Unit/Metrics/Formatter/HtmlTest.php index 6d7d18def3..dd0c0a106b 100644 --- a/tests/PHPUnit/Unit/Metrics/Formatter/HtmlTest.php +++ b/tests/PHPUnit/Unit/Metrics/Formatter/HtmlTest.php @@ -35,13 +35,13 @@ class HtmlTest extends \PHPUnit_Framework_TestCase $this->formatter = new Html(); - Translate::loadEnglishTranslation(); + Translate::loadAllTranslations(); $this->setSiteManagerApiMock(); } public function tearDown() { - Translate::unloadEnglishTranslation(); + Translate::reset(); $this->unsetSiteManagerApiMock(); } diff --git a/tests/PHPUnit/Unit/Metrics/FormatterTest.php b/tests/PHPUnit/Unit/Metrics/FormatterTest.php index 6cf3a8e502..36def63bb1 100644 --- a/tests/PHPUnit/Unit/Metrics/FormatterTest.php +++ b/tests/PHPUnit/Unit/Metrics/FormatterTest.php @@ -51,13 +51,13 @@ class FormatterTest extends \PHPUnit_Framework_TestCase $this->formatter = new Formatter(); - Translate::loadEnglishTranslation(); + Translate::loadAllTranslations(); $this->setSiteManagerApiMock(); } public function tearDown() { - Translate::unloadEnglishTranslation(); + Translate::reset(); $this->unsetSiteManagerApiMock(); } diff --git a/tests/PHPUnit/Unit/Period/BasePeriodTest.php b/tests/PHPUnit/Unit/Period/BasePeriodTest.php index e6713b5f3d..a534b1bb2e 100644 --- a/tests/PHPUnit/Unit/Period/BasePeriodTest.php +++ b/tests/PHPUnit/Unit/Period/BasePeriodTest.php @@ -8,9 +8,7 @@ namespace Piwik\Tests\Unit\Period; -use Piwik\Container\StaticContainer; use Piwik\Translate; -use Piwik\Translation\Translator; abstract class BasePeriodTest extends \PHPUnit_Framework_TestCase { @@ -18,10 +16,7 @@ abstract class BasePeriodTest extends \PHPUnit_Framework_TestCase { parent::setUp(); - Translate::loadCoreTranslation(); - /** @var Translator $translator */ - $translator = StaticContainer::getContainer()->get('Piwik\Translation\Translator'); - $translator->addDirectory(PIWIK_INCLUDE_PATH . '/plugins/CoreHome/lang'); + Translate::loadAllTranslations(); } public function tearDown() |