diff options
Diffstat (limited to 'core')
47 files changed, 202 insertions, 183 deletions
diff --git a/core/API/Proxy.php b/core/API/Proxy.php index 80810c3c31..43d07bc25f 100644 --- a/core/API/Proxy.php +++ b/core/API/Proxy.php @@ -332,7 +332,7 @@ class Proxy } } } catch (Exception $e) { - throw new Exception(Piwik_TranslateException('General_PleaseSpecifyValue', array($name))); + throw new Exception(Piwik::translateException('General_PleaseSpecifyValue', array($name))); } $finalParameters[] = $requestValue; } @@ -398,7 +398,7 @@ class Proxy private function checkMethodExists($className, $methodName) { if (!$this->isMethodAvailable($className, $methodName)) { - throw new Exception(Piwik_TranslateException('General_ExceptionMethodNotFound', array($methodName, $className))); + throw new Exception(Piwik::translateException('General_ExceptionMethodNotFound', array($methodName, $className))); } } diff --git a/core/Access.php b/core/Access.php index 7ee7128f27..cb3568c2f7 100644 --- a/core/Access.php +++ b/core/Access.php @@ -329,7 +329,7 @@ class Access public function checkUserIsSuperUser() { if (!$this->isSuperUser()) { - throw new NoAccessException(Piwik_TranslateException('General_ExceptionPrivilege', array("'superuser'"))); + throw new NoAccessException(Piwik::translateException('General_ExceptionPrivilege', array("'superuser'"))); } } @@ -345,7 +345,7 @@ class Access } $idSitesAccessible = $this->getSitesIdWithAdminAccess(); if (count($idSitesAccessible) == 0) { - throw new NoAccessException(Piwik_TranslateException('General_ExceptionPrivilegeAtLeastOneWebsite', array('admin'))); + throw new NoAccessException(Piwik::translateException('General_ExceptionPrivilegeAtLeastOneWebsite', array('admin'))); } } @@ -361,7 +361,7 @@ class Access } $idSitesAccessible = $this->getSitesIdWithAtLeastViewAccess(); if (count($idSitesAccessible) == 0) { - throw new NoAccessException(Piwik_TranslateException('General_ExceptionPrivilegeAtLeastOneWebsite', array('view'))); + throw new NoAccessException(Piwik::translateException('General_ExceptionPrivilegeAtLeastOneWebsite', array('view'))); } } @@ -381,7 +381,7 @@ class Access $idSitesAccessible = $this->getSitesIdWithAdminAccess(); foreach ($idSites as $idsite) { if (!in_array($idsite, $idSitesAccessible)) { - throw new NoAccessException(Piwik_TranslateException('General_ExceptionPrivilegeAccessWebsite', array("'admin'", $idsite))); + throw new NoAccessException(Piwik::translateException('General_ExceptionPrivilegeAccessWebsite', array("'admin'", $idsite))); } } } @@ -402,7 +402,7 @@ class Access $idSitesAccessible = $this->getSitesIdWithAtLeastViewAccess(); foreach ($idSites as $idsite) { if (!in_array($idsite, $idSitesAccessible)) { - throw new NoAccessException(Piwik_TranslateException('General_ExceptionPrivilegeAccessWebsite', array("'view'", $idsite))); + throw new NoAccessException(Piwik::translateException('General_ExceptionPrivilegeAccessWebsite', array("'view'", $idsite))); } } } diff --git a/core/ArchiveProcessor/Rules.php b/core/ArchiveProcessor/Rules.php index 1589757187..a65cba65cf 100644 --- a/core/ArchiveProcessor/Rules.php +++ b/core/ArchiveProcessor/Rules.php @@ -175,7 +175,7 @@ class Rules { $timeToLiveSeconds = (int)$timeToLiveSeconds; if ($timeToLiveSeconds <= 0) { - throw new Exception(Piwik_TranslateException('General_ExceptionInvalidArchiveTimeToLive')); + throw new Exception(Piwik::translateException('General_ExceptionInvalidArchiveTimeToLive')); } Option::set(self::OPTION_TODAY_ARCHIVE_TTL, $timeToLiveSeconds, $autoLoad = true); } diff --git a/core/Config.php b/core/Config.php index 4926bbda30..ffc095d038 100644 --- a/core/Config.php +++ b/core/Config.php @@ -225,12 +225,12 @@ class Config // read defaults from global.ini.php if (!is_readable($this->pathGlobal) && $reportError) { - Piwik_ExitWithMessage(Piwik_TranslateException('General_ExceptionConfigurationFileNotFound', array($this->pathGlobal))); + Piwik_ExitWithMessage(Piwik::translateException('General_ExceptionConfigurationFileNotFound', array($this->pathGlobal))); } $this->configGlobal = _parse_ini_file($this->pathGlobal, true); if (empty($this->configGlobal) && $reportError) { - Piwik_ExitWithMessage(Piwik_TranslateException('General_ExceptionUnreadableFileDisabledMethod', array($this->pathGlobal, "parse_ini_file()"))); + Piwik_ExitWithMessage(Piwik::translateException('General_ExceptionUnreadableFileDisabledMethod', array($this->pathGlobal, "parse_ini_file()"))); } if ($reportError) { @@ -238,14 +238,14 @@ class Config } $this->configLocal = _parse_ini_file($this->pathLocal, true); if (empty($this->configLocal) && $reportError) { - Piwik_ExitWithMessage(Piwik_TranslateException('General_ExceptionUnreadableFileDisabledMethod', array($this->pathLocal, "parse_ini_file()"))); + Piwik_ExitWithMessage(Piwik::translateException('General_ExceptionUnreadableFileDisabledMethod', array($this->pathLocal, "parse_ini_file()"))); } } public function checkLocalConfigFound() { if (!is_readable($this->pathLocal)) { - throw new Exception(Piwik_TranslateException('General_ExceptionConfigurationFileNotFound', array($this->pathLocal))); + throw new Exception(Piwik::translateException('General_ExceptionConfigurationFileNotFound', array($this->pathLocal))); } } @@ -507,7 +507,7 @@ class Config if ($output !== false) { $success = @file_put_contents($pathLocal, $output); if (!$success) { - throw new Exception(Piwik_Translate('General_ConfigFileIsNotWritable', array("(config/config.ini.php)", ""))); + throw new Exception(Piwik::translate('General_ConfigFileIsNotWritable', array("(config/config.ini.php)", ""))); } } diff --git a/core/Controller.php b/core/Controller.php index c5ba494684..5eb739a937 100644 --- a/core/Controller.php +++ b/core/Controller.php @@ -472,8 +472,8 @@ abstract class Controller $validHost = Config::getInstance()->General['trusted_hosts'][0]; $invalidHost = Common::sanitizeInputValue($_SERVER['HTTP_HOST']); - $emailSubject = rawurlencode(Piwik_Translate('CoreHome_InjectedHostEmailSubject', $invalidHost)); - $emailBody = rawurlencode(Piwik_Translate('CoreHome_InjectedHostEmailBody')); + $emailSubject = rawurlencode(Piwik::translate('CoreHome_InjectedHostEmailSubject', $invalidHost)); + $emailBody = rawurlencode(Piwik::translate('CoreHome_InjectedHostEmailBody')); $superUserEmail = Piwik::getSuperUserEmail(); $mailToUrl = "mailto:$superUserEmail?subject=$emailSubject&body=$emailBody"; @@ -492,14 +492,14 @@ abstract class Controller )) . "#trustedHostsSection"; - $warningStart = Piwik_Translate('CoreHome_InjectedHostWarningIntro', array( + $warningStart = Piwik::translate('CoreHome_InjectedHostWarningIntro', array( '<strong>' . $invalidUrl . '</strong>', '<strong>' . $validUrl . '</strong>' )) . ' <br/>'; if (Piwik::isUserIsSuperUser()) { $view->invalidHostMessage = $warningStart . ' ' - . Piwik_Translate('CoreHome_InjectedHostSuperUserWarning', array( + . Piwik::translate('CoreHome_InjectedHostSuperUserWarning', array( "<a href=\"$changeTrustedHostsUrl\">", $invalidHost, '</a>', @@ -509,7 +509,7 @@ abstract class Controller )); } else { $view->invalidHostMessage = $warningStart . ' ' - . Piwik_Translate('CoreHome_InjectedHostNonSuperUserWarning', array( + . Piwik::translate('CoreHome_InjectedHostNonSuperUserWarning', array( "<br/><a href=\"$validUrl\">", '</a>', $mailLinkStart, @@ -546,12 +546,12 @@ abstract class Controller throw new Exception("Period must be one of: " . implode(",", $availablePeriods)); } $periodNames = array( - 'day' => array('singular' => Piwik_Translate('CoreHome_PeriodDay'), 'plural' => Piwik_Translate('CoreHome_PeriodDays')), - 'week' => array('singular' => Piwik_Translate('CoreHome_PeriodWeek'), 'plural' => Piwik_Translate('CoreHome_PeriodWeeks')), - 'month' => array('singular' => Piwik_Translate('CoreHome_PeriodMonth'), 'plural' => Piwik_Translate('CoreHome_PeriodMonths')), - 'year' => array('singular' => Piwik_Translate('CoreHome_PeriodYear'), 'plural' => Piwik_Translate('CoreHome_PeriodYears')), + 'day' => array('singular' => Piwik::translate('CoreHome_PeriodDay'), 'plural' => Piwik::translate('CoreHome_PeriodDays')), + 'week' => array('singular' => Piwik::translate('CoreHome_PeriodWeek'), 'plural' => Piwik::translate('CoreHome_PeriodWeeks')), + 'month' => array('singular' => Piwik::translate('CoreHome_PeriodMonth'), 'plural' => Piwik::translate('CoreHome_PeriodMonths')), + 'year' => array('singular' => Piwik::translate('CoreHome_PeriodYear'), 'plural' => Piwik::translate('CoreHome_PeriodYears')), // Note: plural is not used for date range - 'range' => array('singular' => Piwik_Translate('General_DateRangeInPeriodList'), 'plural' => Piwik_Translate('General_DateRangeInPeriodList')), + 'range' => array('singular' => Piwik::translate('General_DateRangeInPeriodList'), 'plural' => Piwik::translate('General_DateRangeInPeriodList')), ); $found = array_search($currentPeriod, $availablePeriods); @@ -610,8 +610,8 @@ abstract class Controller if (!empty($currentLogin) && $currentLogin != 'anonymous' ) { - $errorMessage = sprintf(Piwik_Translate('CoreHome_NoPrivilegesAskPiwikAdmin'), $currentLogin, "<br/><a href='mailto:" . Piwik::getSuperUserEmail() . "?subject=Access to Piwik for user $currentLogin'>", "</a>"); - $errorMessage .= "<br /><br /> <b><a href='index.php?module=" . Registry::get('auth')->getName() . "&action=logout'>› " . Piwik_Translate('General_Logout') . "</a></b><br />"; + $errorMessage = sprintf(Piwik::translate('CoreHome_NoPrivilegesAskPiwikAdmin'), $currentLogin, "<br/><a href='mailto:" . Piwik::getSuperUserEmail() . "?subject=Access to Piwik for user $currentLogin'>", "</a>"); + $errorMessage .= "<br /><br /> <b><a href='index.php?module=" . Registry::get('auth')->getName() . "&action=logout'>› " . Piwik::translate('General_Logout') . "</a></b><br />"; Piwik_ExitWithMessage($errorMessage, false, true); } @@ -701,7 +701,7 @@ abstract class Controller protected function checkTokenInUrl() { if (Common::getRequestVar('token_auth', false) != Piwik::getCurrentUserTokenAuth()) { - throw new NoAccessException(Piwik_TranslateException('General_ExceptionInvalidToken')); + throw new NoAccessException(Piwik::translateException('General_ExceptionInvalidToken')); } } @@ -771,10 +771,10 @@ abstract class Controller $titleEvolutionPercent = '+' . $titleEvolutionPercent; } - $title = Piwik_Translate('General_EvolutionSummaryGeneric', array( - Piwik_Translate('General_NVisits', $currentValue), + $title = Piwik::translate('General_EvolutionSummaryGeneric', array( + Piwik::translate('General_NVisits', $currentValue), $date, - Piwik_Translate('General_NVisits', $pastValue), + Piwik::translate('General_NVisits', $pastValue), $pastDate, $titleEvolutionPercent )); diff --git a/core/Controller/Admin.php b/core/Controller/Admin.php index 2facfeeac8..75849258e5 100644 --- a/core/Controller/Admin.php +++ b/core/Controller/Admin.php @@ -71,11 +71,11 @@ abstract class Admin extends Controller $pluginsLink = Url::getCurrentQueryStringWithParametersModified(array( 'module' => 'CorePluginsAdmin', 'action' => 'plugins' )); - $view->invalidPluginsWarning = Piwik_Translate('CoreAdminHome_InvalidPluginsWarning', array( + $view->invalidPluginsWarning = Piwik::translate('CoreAdminHome_InvalidPluginsWarning', array( self::getPiwikVersion(), '<strong>' . implode('</strong>, <strong>', $missingPlugins) . '</strong>')) . '<br/>' - . Piwik_Translate('CoreAdminHome_InvalidPluginsYouCanUninstall', array( + . Piwik::translate('CoreAdminHome_InvalidPluginsYouCanUninstall', array( '<a href="' . $pluginsLink . '"/>', '</a>' )); diff --git a/core/DataTable/Filter/BeautifyRangeLabels.php b/core/DataTable/Filter/BeautifyRangeLabels.php index cfa2122351..3fe02effe7 100644 --- a/core/DataTable/Filter/BeautifyRangeLabels.php +++ b/core/DataTable/Filter/BeautifyRangeLabels.php @@ -11,6 +11,7 @@ namespace Piwik\DataTable\Filter; use Piwik\DataTable; +use Piwik\Piwik; /** * A DataTable filter that replaces range label columns with prettier, @@ -102,7 +103,7 @@ class BeautifyRangeLabels extends ColumnCallbackReplace } else { // if no lower bound can be found, this isn't a valid range. in this case // we assume its a translation key and try to translate it. - return Piwik_Translate(trim($value)); + return Piwik::translate(trim($value)); } } } diff --git a/core/DataTable/Filter/ReplaceSummaryRowLabel.php b/core/DataTable/Filter/ReplaceSummaryRowLabel.php index 0a7ef49dc7..48647939aa 100644 --- a/core/DataTable/Filter/ReplaceSummaryRowLabel.php +++ b/core/DataTable/Filter/ReplaceSummaryRowLabel.php @@ -13,6 +13,7 @@ namespace Piwik\DataTable\Filter; use Piwik\DataTable\Filter; use Piwik\DataTable; use Piwik\DataTable\Manager; +use Piwik\Piwik; /** * @@ -29,7 +30,7 @@ class ReplaceSummaryRowLabel extends Filter { parent::__construct($table); if (is_null($newLabel)) { - $newLabel = Piwik_Translate('General_Others'); + $newLabel = Piwik::translate('General_Others'); } $this->newLabel = $newLabel; } diff --git a/core/DataTable/Renderer.php b/core/DataTable/Renderer.php index 2ffeb913e4..f683e01696 100644 --- a/core/DataTable/Renderer.php +++ b/core/DataTable/Renderer.php @@ -209,7 +209,7 @@ abstract class Renderer } catch (Exception $e) { $availableRenderers = implode(', ', self::getRenderers()); @header('Content-Type: text/plain; charset=utf-8'); - throw new Exception(Piwik_TranslateException('General_ExceptionInvalidRendererFormat', array($className, $availableRenderers))); + throw new Exception(Piwik::translateException('General_ExceptionInvalidRendererFormat', array($className, $availableRenderers))); } } diff --git a/core/DataTable/Renderer/Csv.php b/core/DataTable/Renderer/Csv.php index 692c61d8ef..583bf0edac 100644 --- a/core/DataTable/Renderer/Csv.php +++ b/core/DataTable/Renderer/Csv.php @@ -17,6 +17,7 @@ use Piwik\DataTable; use Piwik\Date; use Piwik\Period; use Piwik\Period\Range; +use Piwik\Piwik; use Piwik\ProxyHttp; /** @@ -215,7 +216,7 @@ class Csv extends Renderer } //if a metadata and a column have the same name make sure they dont overwrite if ($this->translateColumnNames) { - $name = Piwik_Translate('General_Metadata') . ': ' . $name; + $name = Piwik::translate('General_Metadata') . ': ' . $name; } else { $name = 'metadata_' . $name; } @@ -328,7 +329,7 @@ class Csv extends Renderer */ protected function renderHeader() { - $fileName = 'Piwik ' . Piwik_Translate('General_Export'); + $fileName = 'Piwik ' . Piwik::translate('General_Export'); $period = Common::getRequestVar('period', false); $date = Common::getRequestVar('date', false); @@ -374,7 +375,7 @@ class Csv extends Renderer && is_array(reset($value)) ) { foreach ($value as $level1Key => $level1Value) { - $inner = $name == 'goals' ? Piwik_Translate('Goals_GoalX', $level1Key) : $name . ' ' . $level1Key; + $inner = $name == 'goals' ? Piwik::translate('Goals_GoalX', $level1Key) : $name . ' ' . $level1Key; $columnNameTemplate = '%s (' . $inner . ')'; $this->flattenColumnArray($level1Value, $csvRow, $columnNameTemplate); diff --git a/core/Date.php b/core/Date.php index 1b0d31e4d6..b60e0963ff 100644 --- a/core/Date.php +++ b/core/Date.php @@ -67,7 +67,7 @@ class Date */ public static function factory($dateString, $timezone = null) { - $invalidDateException = new Exception(Piwik_TranslateException('General_ExceptionInvalidDateFormat', array("YYYY-MM-DD, or 'today' or 'yesterday'", "strtotime", "http://php.net/strtotime")) . ": $dateString"); + $invalidDateException = new Exception(Piwik::translateException('General_ExceptionInvalidDateFormat', array("YYYY-MM-DD, or 'today' or 'yesterday'", "strtotime", "http://php.net/strtotime")) . ": $dateString"); if ($dateString instanceof self) { $dateString = $dateString->toString(); } @@ -528,10 +528,10 @@ class Date $monthOfYear = $this->toString('n'); $patternToValue = array( "%day%" => $day, - "%shortMonth%" => Piwik_Translate('General_ShortMonth_' . $monthOfYear), - "%longMonth%" => Piwik_Translate('General_LongMonth_' . $monthOfYear), - "%shortDay%" => Piwik_Translate('General_ShortDay_' . $dayOfWeek), - "%longDay%" => Piwik_Translate('General_LongDay_' . $dayOfWeek), + "%shortMonth%" => Piwik::translate('General_ShortMonth_' . $monthOfYear), + "%longMonth%" => Piwik::translate('General_LongMonth_' . $monthOfYear), + "%shortDay%" => Piwik::translate('General_ShortDay_' . $dayOfWeek), + "%longDay%" => Piwik::translate('General_LongDay_' . $dayOfWeek), "%longYear%" => $this->toString('Y'), "%shortYear%" => $this->toString('y'), "%time%" => $this->toString('H:i:s') diff --git a/core/Db/Adapter/Mysqli.php b/core/Db/Adapter/Mysqli.php index eb76b9f552..a436647129 100644 --- a/core/Db/Adapter/Mysqli.php +++ b/core/Db/Adapter/Mysqli.php @@ -13,6 +13,7 @@ namespace Piwik\Db\Adapter; use Exception; use Piwik\Config; use Piwik\Db\AdapterInterface; +use Piwik\Piwik; use Zend_Config; use Zend_Db_Adapter_Mysqli; @@ -62,7 +63,7 @@ class Mysqli extends Zend_Db_Adapter_Mysqli implements AdapterInterface $serverVersion = $this->getServerVersion(); $requiredVersion = Config::getInstance()->General['minimum_mysql_version']; if (version_compare($serverVersion, $requiredVersion) === -1) { - throw new Exception(Piwik_TranslateException('General_ExceptionDatabaseVersion', array('MySQL', $serverVersion, $requiredVersion))); + throw new Exception(Piwik::translateException('General_ExceptionDatabaseVersion', array('MySQL', $serverVersion, $requiredVersion))); } } @@ -79,7 +80,7 @@ class Mysqli extends Zend_Db_Adapter_Mysqli implements AdapterInterface if (version_compare($serverVersion, '5.0.3') >= 0 && version_compare($clientVersion, '5.0.3') < 0 ) { - throw new Exception(Piwik_TranslateException('General_ExceptionIncompatibleClientServerVersions', array('MySQL', $clientVersion, $serverVersion))); + throw new Exception(Piwik::translateException('General_ExceptionIncompatibleClientServerVersions', array('MySQL', $clientVersion, $serverVersion))); } } diff --git a/core/Db/Adapter/Pdo/Mssql.php b/core/Db/Adapter/Pdo/Mssql.php index 1f218e20d7..17bb6fb6b9 100644 --- a/core/Db/Adapter/Pdo/Mssql.php +++ b/core/Db/Adapter/Pdo/Mssql.php @@ -15,6 +15,7 @@ use PDO; use PDOException; use Piwik\Config; use Piwik\Db\AdapterInterface; +use Piwik\Piwik; use Zend_Db; use Zend_Db_Adapter_Exception; use Zend_Db_Adapter_Pdo_Mssql; @@ -140,7 +141,7 @@ class Mssql extends Zend_Db_Adapter_Pdo_Mssql implements AdapterInterface $serverVersion = $this->getServerVersion(); $requiredVersion = Config::getInstance()->General['minimum_mssql_version']; if (version_compare($serverVersion, $requiredVersion) === -1) { - throw new Exception(Piwik_TranslateException('General_ExceptionDatabaseVersion', array('MSSQL', $serverVersion, $requiredVersion))); + throw new Exception(Piwik::translateException('General_ExceptionDatabaseVersion', array('MSSQL', $serverVersion, $requiredVersion))); } } @@ -175,7 +176,7 @@ class Mssql extends Zend_Db_Adapter_Pdo_Mssql implements AdapterInterface if (version_compare($serverVersion, '10') >= 0 && version_compare($clientVersion, '10') < 0 ) { - throw new Exception(Piwik_TranslateException('General_ExceptionIncompatibleClientServerVersions', array('MSSQL', $clientVersion, $serverVersion))); + throw new Exception(Piwik::translateException('General_ExceptionIncompatibleClientServerVersions', array('MSSQL', $clientVersion, $serverVersion))); } } @@ -254,7 +255,7 @@ class Mssql extends Zend_Db_Adapter_Pdo_Mssql implements AdapterInterface $version = $this->_connection->getAttribute(PDO::ATTR_CLIENT_VERSION); $requiredVersion = Config::getInstance()->General['minimum_mssql_client_version']; if (version_compare($version['DriverVer'], $requiredVersion) === -1) { - throw new Exception(Piwik_TranslateException('General_ExceptionDatabaseVersion', array('MSSQL', $version['DriverVer'], $requiredVersion))); + throw new Exception(Piwik::translateException('General_ExceptionDatabaseVersion', array('MSSQL', $version['DriverVer'], $requiredVersion))); } else { return $version['DriverVer']; } diff --git a/core/Db/Adapter/Pdo/Mysql.php b/core/Db/Adapter/Pdo/Mysql.php index 03ddc9ccad..6d3d9641fc 100644 --- a/core/Db/Adapter/Pdo/Mysql.php +++ b/core/Db/Adapter/Pdo/Mysql.php @@ -15,6 +15,7 @@ use PDO; use PDOException; use Piwik\Config; use Piwik\Db\AdapterInterface; +use Piwik\Piwik; use Zend_Config; use Zend_Db_Adapter_Pdo_Mysql; use Zend_Db_Select; @@ -96,7 +97,7 @@ class Mysql extends Zend_Db_Adapter_Pdo_Mysql implements AdapterInterface $serverVersion = $this->getServerVersion(); $requiredVersion = Config::getInstance()->General['minimum_mysql_version']; if (version_compare($serverVersion, $requiredVersion) === -1) { - throw new Exception(Piwik_TranslateException('General_ExceptionDatabaseVersion', array('MySQL', $serverVersion, $requiredVersion))); + throw new Exception(Piwik::translateException('General_ExceptionDatabaseVersion', array('MySQL', $serverVersion, $requiredVersion))); } } @@ -113,7 +114,7 @@ class Mysql extends Zend_Db_Adapter_Pdo_Mysql implements AdapterInterface if (version_compare($serverVersion, '5.0.3') >= 0 && version_compare($clientVersion, '5.0.3') < 0 ) { - throw new Exception(Piwik_TranslateException('General_ExceptionIncompatibleClientServerVersions', array('MySQL', $clientVersion, $serverVersion))); + throw new Exception(Piwik::translateException('General_ExceptionIncompatibleClientServerVersions', array('MySQL', $clientVersion, $serverVersion))); } } diff --git a/core/Db/Adapter/Pdo/Pgsql.php b/core/Db/Adapter/Pdo/Pgsql.php index 6b9b25ba19..64d3933ba3 100644 --- a/core/Db/Adapter/Pdo/Pgsql.php +++ b/core/Db/Adapter/Pdo/Pgsql.php @@ -15,6 +15,7 @@ use PDO; use PDOException; use Piwik\Config; use Piwik\Db\AdapterInterface; +use Piwik\Piwik; use Zend_Db_Adapter_Pdo_Pgsql; /** @@ -51,7 +52,7 @@ class Pgsql extends Zend_Db_Adapter_Pdo_Pgsql implements AdapterInterface $databaseVersion = $this->getServerVersion(); $requiredVersion = Config::getInstance()->General['minimum_pgsql_version']; if (version_compare($databaseVersion, $requiredVersion) === -1) { - throw new Exception(Piwik_TranslateException('General_ExceptionDatabaseVersion', array('PostgreSQL', $databaseVersion, $requiredVersion))); + throw new Exception(Piwik::translateException('General_ExceptionDatabaseVersion', array('PostgreSQL', $databaseVersion, $requiredVersion))); } } diff --git a/core/Filechecks.php b/core/Filechecks.php index 8798b78235..acf09fb840 100644 --- a/core/Filechecks.php +++ b/core/Filechecks.php @@ -117,7 +117,7 @@ class Filechecks } if (!class_exists('\\Piwik\\Manifest')) { - $messages[] = Piwik_Translate('General_WarningFileIntegrityNoManifest') . " If you are deploying Piwik from Git, this message is normal."; + $messages[] = Piwik::translate('General_WarningFileIntegrityNoManifest') . " If you are deploying Piwik from Git, this message is normal."; return $messages; } @@ -129,11 +129,11 @@ class Filechecks $file = PIWIK_INCLUDE_PATH . '/' . $path; if (!file_exists($file)) { - $messages[] = Piwik_Translate('General_ExceptionMissingFile', $file); + $messages[] = Piwik::translate('General_ExceptionMissingFile', $file); } else if (filesize($file) != $props[0]) { if (!$hasMd5 || in_array(substr($path, -4), array('.gif', '.ico', '.jpg', '.png', '.swf'))) { // files that contain binary data (e.g., images) must match the file size - $messages[] = Piwik_Translate('General_ExceptionFilesizeMismatch', array($file, $props[0], filesize($file))); + $messages[] = Piwik::translate('General_ExceptionFilesizeMismatch', array($file, $props[0], filesize($file))); } else { // convert end-of-line characters and re-test text files $content = @file_get_contents($file); @@ -141,11 +141,11 @@ class Filechecks if ((strlen($content) != $props[0]) || (@md5($content) !== $props[1]) ) { - $messages[] = Piwik_Translate('General_ExceptionFilesizeMismatch', array($file, $props[0], filesize($file))); + $messages[] = Piwik::translate('General_ExceptionFilesizeMismatch', array($file, $props[0], filesize($file))); } } } else if ($hasMd5file && (@md5_file($file) !== $props[1])) { - $messages[] = Piwik_Translate('General_ExceptionFileIntegrity', $file); + $messages[] = Piwik::translate('General_ExceptionFileIntegrity', $file); } } @@ -154,7 +154,7 @@ class Filechecks } if (!$hasMd5file) { - $messages[] = Piwik_Translate('General_WarningFileIntegrityNoMd5file'); + $messages[] = Piwik::translate('General_WarningFileIntegrityNoMd5file'); } return $messages; diff --git a/core/Http.php b/core/Http.php index ddd773999f..06feff3706 100644 --- a/core/Http.php +++ b/core/Http.php @@ -552,8 +552,8 @@ class Http && file_exists($outputPath) ) { throw new Exception( - Piwik_Translate('General_DownloadFail_FileExists', "'" . $outputPath . "'") - . ' ' . Piwik_Translate('General_DownloadPleaseRemoveExisting')); + Piwik::translate('General_DownloadFail_FileExists', "'" . $outputPath . "'") + . ' ' . Piwik::translate('General_DownloadPleaseRemoveExisting')); } // if we're starting a download, get the expected file size & save as an option @@ -578,7 +578,7 @@ class Http if ($expectedFileSize == 0) { Log::info("HEAD request for '%s' failed, got following: %s", $url, print_r($expectedFileSizeResult, true)); - throw new Exception(Piwik_Translate('General_DownloadFail_HttpRequestFail')); + throw new Exception(Piwik::translate('General_DownloadFail_HttpRequestFail')); } Option::set($downloadOption, $expectedFileSize); @@ -594,8 +594,8 @@ class Http $existingSize = file_exists($outputPath) ? filesize($outputPath) : 0; if ($existingSize >= $expectedFileSize) { throw new Exception( - Piwik_Translate('General_DownloadFail_FileExistsContinue', "'" . $outputPath . "'") - . ' ' . Piwik_Translate('General_DownloadPleaseRemoveExisting')); + Piwik::translate('General_DownloadFail_FileExistsContinue', "'" . $outputPath . "'") + . ' ' . Piwik::translate('General_DownloadPleaseRemoveExisting')); } // download a chunk of the file @@ -618,7 +618,7 @@ class Http Log::info("Failed to download range '%s-%s' of file from url '%s'. Got result: %s", $byteRange[0], $byteRange[1], $url, print_r($result, true)); - throw new Exception(Piwik_Translate('General_DownloadFail_HttpRequestFail')); + throw new Exception(Piwik::translate('General_DownloadFail_HttpRequestFail')); } // write chunk to file diff --git a/core/Metrics.php b/core/Metrics.php index 99704bcfb3..ea683df56f 100644 --- a/core/Metrics.php +++ b/core/Metrics.php @@ -235,16 +235,16 @@ class Metrics 'exit_rate' => 'General_ColumnExitRate' ); - $trans = array_map('Piwik_Translate', $trans); + $trans = array_map('Piwik::translate', $trans); - $dailySum = ' (' . Piwik_Translate('General_DailySum') . ')'; - $afterEntry = ' ' . Piwik_Translate('General_AfterEntry'); + $dailySum = ' (' . Piwik::translate('General_DailySum') . ')'; + $afterEntry = ' ' . Piwik::translate('General_AfterEntry'); - $trans['sum_daily_nb_uniq_visitors'] = Piwik_Translate('General_ColumnNbUniqVisitors') . $dailySum; - $trans['sum_daily_entry_nb_uniq_visitors'] = Piwik_Translate('General_ColumnUniqueEntrances') . $dailySum; - $trans['sum_daily_exit_nb_uniq_visitors'] = Piwik_Translate('General_ColumnUniqueExits') . $dailySum; - $trans['entry_nb_actions'] = Piwik_Translate('General_ColumnNbActions') . $afterEntry; - $trans['entry_sum_visit_length'] = Piwik_Translate('General_ColumnSumVisitLength') . $afterEntry; + $trans['sum_daily_nb_uniq_visitors'] = Piwik::translate('General_ColumnNbUniqVisitors') . $dailySum; + $trans['sum_daily_entry_nb_uniq_visitors'] = Piwik::translate('General_ColumnUniqueEntrances') . $dailySum; + $trans['sum_daily_exit_nb_uniq_visitors'] = Piwik::translate('General_ColumnUniqueExits') . $dailySum; + $trans['entry_nb_actions'] = Piwik::translate('General_ColumnNbActions') . $afterEntry; + $trans['entry_sum_visit_length'] = Piwik::translate('General_ColumnSumVisitLength') . $afterEntry; $trans = array_merge(self::getDefaultMetrics(), self::getDefaultProcessedMetrics(), $trans); @@ -258,7 +258,7 @@ class Metrics 'nb_uniq_visitors' => 'General_ColumnNbUniqVisitors', 'nb_actions' => 'General_ColumnNbActions', ); - $translations = array_map('Piwik_Translate', $translations); + $translations = array_map('Piwik::translate', $translations); return $translations; } @@ -271,7 +271,7 @@ class Metrics 'bounce_rate' => 'General_ColumnBounceRate', 'conversion_rate' => 'General_ColumnConversionRate', ); - return array_map('Piwik_Translate', $translations); + return array_map('Piwik::translate', $translations); } static public function getDefaultMetricsDocumentation() @@ -288,12 +288,12 @@ class Metrics 'nb_hits' => 'General_ColumnPageviewsDocumentation', 'exit_rate' => 'General_ColumnExitRateDocumentation' ); - return array_map('Piwik_Translate', $documentation); + return array_map('Piwik::translate', $documentation); } public static function getPercentVisitColumn() { - $percentVisitsLabel = str_replace(' ', ' ', Piwik_Translate('General_ColumnPercentageVisits')); + $percentVisitsLabel = str_replace(' ', ' ', Piwik::translate('General_ColumnPercentageVisits')); return $percentVisitsLabel; } }
\ No newline at end of file diff --git a/core/MetricsFormatter.php b/core/MetricsFormatter.php index b86453d682..29c2e71c49 100644 --- a/core/MetricsFormatter.php +++ b/core/MetricsFormatter.php @@ -78,15 +78,15 @@ class MetricsFormatter $seconds = round($seconds, $precision); if ($years > 0) { - $return = sprintf(Piwik_Translate('General_YearsDays'), $years, $days); + $return = sprintf(Piwik::translate('General_YearsDays'), $years, $days); } elseif ($days > 0) { - $return = sprintf(Piwik_Translate('General_DaysHours'), $days, $hours); + $return = sprintf(Piwik::translate('General_DaysHours'), $days, $hours); } elseif ($hours > 0) { - $return = sprintf(Piwik_Translate('General_HoursMinutes'), $hours, $minutes); + $return = sprintf(Piwik::translate('General_HoursMinutes'), $hours, $minutes); } elseif ($minutes > 0) { - $return = sprintf(Piwik_Translate('General_MinutesSeconds'), $minutes, $seconds); + $return = sprintf(Piwik::translate('General_MinutesSeconds'), $minutes, $seconds); } else { - $return = sprintf(Piwik_Translate('General_Seconds'), $seconds); + $return = sprintf(Piwik::translate('General_Seconds'), $seconds); } if ($isHtml) { return str_replace(' ', ' ', $return); diff --git a/core/Period.php b/core/Period.php index 5b5822dd09..4848086a04 100644 --- a/core/Period.php +++ b/core/Period.php @@ -77,7 +77,7 @@ abstract class Period break; default: - throw new Exception(Piwik_TranslateException('General_ExceptionInvalidPeriod', array($strPeriod, self::$errorAvailablePeriods))); + throw new Exception(Piwik::translateException('General_ExceptionInvalidPeriod', array($strPeriod, self::$errorAvailablePeriods))); break; } } diff --git a/core/Period/Day.php b/core/Period/Day.php index a53a5a49cb..61d2809ef6 100644 --- a/core/Period/Day.php +++ b/core/Period/Day.php @@ -12,6 +12,7 @@ namespace Piwik\Period; use Exception; use Piwik\Period; +use Piwik\Piwik; /** * @package Piwik @@ -42,7 +43,7 @@ class Day extends Period { //"Mon 15 Aug" $date = $this->getDateStart(); - $out = $date->getLocalized(Piwik_Translate('CoreHome_ShortDateFormat')); + $out = $date->getLocalized(Piwik::translate('CoreHome_ShortDateFormat')); return $out; } @@ -55,7 +56,7 @@ class Day extends Period { //"Mon 15 Aug" $date = $this->getDateStart(); - $template = Piwik_Translate('CoreHome_DateFormat'); + $template = Piwik::translate('CoreHome_DateFormat'); $out = $date->getLocalized($template); return $out; } diff --git a/core/Period/Month.php b/core/Period/Month.php index 0650f44883..b7fbf04346 100644 --- a/core/Period/Month.php +++ b/core/Period/Month.php @@ -11,6 +11,7 @@ namespace Piwik\Period; use Piwik\Period; +use Piwik\Piwik; /** * @package Piwik @@ -29,7 +30,7 @@ class Month extends Period public function getLocalizedShortString() { //"Aug 09" - $out = $this->getDateStart()->getLocalized(Piwik_Translate('CoreHome_ShortMonthFormat')); + $out = $this->getDateStart()->getLocalized(Piwik::translate('CoreHome_ShortMonthFormat')); return $out; } @@ -41,7 +42,7 @@ class Month extends Period public function getLocalizedLongString() { //"August 2009" - $out = $this->getDateStart()->getLocalized(Piwik_Translate('CoreHome_LongMonthFormat')); + $out = $this->getDateStart()->getLocalized(Piwik::translate('CoreHome_LongMonthFormat')); return $out; } diff --git a/core/Period/Range.php b/core/Period/Range.php index 649d557381..3b7a429e48 100644 --- a/core/Period/Range.php +++ b/core/Period/Range.php @@ -14,6 +14,7 @@ use Exception; use Piwik\Common; use Piwik\Date; use Piwik\Period; +use Piwik\Piwik; /** * from a starting date to an ending date @@ -54,7 +55,7 @@ class Range extends Period //"30 Dec 08 - 26 Feb 09" $dateStart = $this->getDateStart(); $dateEnd = $this->getDateEnd(); - $template = Piwik_Translate('CoreHome_ShortDateFormatWithYear'); + $template = Piwik::translate('CoreHome_ShortDateFormatWithYear'); $shortDateStart = $dateStart->getLocalized($template); $shortDateEnd = $dateEnd->getLocalized($template); $out = "$shortDateStart - $shortDateEnd"; @@ -93,7 +94,7 @@ class Range extends Period */ public function getPrettyString() { - $out = Piwik_Translate('General_DateRangeFromTo', array($this->getDateStart()->toString(), $this->getDateEnd()->toString())); + $out = Piwik::translate('General_DateRangeFromTo', array($this->getDateStart()->toString(), $this->getDateEnd()->toString())); return $out; } @@ -218,7 +219,7 @@ class Range extends Period } $endDate = Date::factory($strDateEnd, $timezone); } else { - throw new Exception(Piwik_TranslateException('General_ExceptionInvalidDateRange', array($this->strDate, ' \'lastN\', \'previousN\', \'YYYY-MM-DD,YYYY-MM-DD\''))); + throw new Exception(Piwik::translateException('General_ExceptionInvalidDateRange', array($this->strDate, ' \'lastN\', \'previousN\', \'YYYY-MM-DD,YYYY-MM-DD\''))); } if ($this->strPeriod != 'range') { $this->fillArraySubPeriods($startDate, $endDate, $this->strPeriod); diff --git a/core/Period/Week.php b/core/Period/Week.php index e016da3ff5..aeb8640d3c 100644 --- a/core/Period/Week.php +++ b/core/Period/Week.php @@ -12,6 +12,7 @@ namespace Piwik\Period; use Piwik\Period; +use Piwik\Piwik; /** * @package Piwik @@ -33,7 +34,7 @@ class Week extends Period $dateStart = $this->getDateStart(); $dateEnd = $this->getDateEnd(); - $string = Piwik_Translate('CoreHome_ShortWeekFormat'); + $string = Piwik::translate('CoreHome_ShortWeekFormat'); $string = self::getTranslatedRange($string, $dateStart, $dateEnd); return $string; } @@ -45,9 +46,9 @@ class Week extends Period */ public function getLocalizedLongString() { - $format = Piwik_Translate('CoreHome_LongWeekFormat'); + $format = Piwik::translate('CoreHome_LongWeekFormat'); $string = self::getTranslatedRange($format, $this->getDateStart(), $this->getDateEnd()); - return Piwik_Translate('CoreHome_PeriodWeek') . " " . $string; + return Piwik::translate('CoreHome_PeriodWeek') . " " . $string; } /** @@ -73,7 +74,7 @@ class Week extends Period */ public function getPrettyString() { - $out = Piwik_Translate('General_DateRangeFromTo', + $out = Piwik::translate('General_DateRangeFromTo', array($this->getDateStart()->toString(), $this->getDateEnd()->toString()) ); diff --git a/core/Piwik.php b/core/Piwik.php index 3be8c765eb..9d5a551a0c 100644 --- a/core/Piwik.php +++ b/core/Piwik.php @@ -253,7 +253,7 @@ class Piwik Piwik::checkUserIsSuperUser(); } } catch (NoAccessException $e) { - throw new NoAccessException(Piwik_Translate('General_ExceptionCheckUserIsSuperUserOrTheUser', array($theUser))); + throw new NoAccessException(Piwik::translate('General_ExceptionCheckUserIsSuperUserOrTheUser', array($theUser))); } } @@ -293,7 +293,7 @@ class Piwik static public function checkUserIsNotAnonymous() { if (self::isUserIsAnonymous()) { - throw new NoAccessException(Piwik_Translate('General_YouMustBeLoggedIn')); + throw new NoAccessException(Piwik::translate('General_YouMustBeLoggedIn')); } } @@ -568,7 +568,7 @@ class Piwik && $l <= $loginMaximumLength && (preg_match('/^[A-Za-z0-9_.@+-]*$/D', $userLogin) > 0)) ) { - throw new Exception(Piwik_TranslateException('UsersManager_ExceptionInvalidLoginFormat', array($loginMinimumLength, $loginMaximumLength))); + throw new Exception(Piwik::translateException('UsersManager_ExceptionInvalidLoginFormat', array($loginMinimumLength, $loginMaximumLength))); } } @@ -680,4 +680,50 @@ class Piwik Piwik::postEvent($eventName, $params, $pending, $plugins); } } + + /** + * Returns translated string or given message if translation is not found. + * + * @param string $string Translation string index + * @param array|string|int $args sprintf arguments + * @return string + * @api + */ + public static function translate($string, $args = array()) + { + if (!is_array($args)) { + $args = array($args); + } + + if (strpos($string, "_") !== false) { + list($plugin, $key) = explode("_", $string, 2); + if (isset($GLOBALS['Piwik_translations'][$plugin]) && isset($GLOBALS['Piwik_translations'][$plugin][$key])) { + $string = $GLOBALS['Piwik_translations'][$plugin][$key]; + } + } + if (count($args) == 0) { + return $string; + } + return vsprintf($string, $args); + } + + + /** + * Returns translated string or given message if translation is not found. + * This function does not throw any exception. Use it to translate exceptions. + * + * @param string $message Translation string index + * @param array $args sprintf arguments + * @return string + * @api + */ + public static function translateException($message, $args = array()) + { + try { + return Piwik::translate($message, $args); + } catch (Exception $e) { + return $message; + } + } + } diff --git a/core/Plugin/MetadataLoader.php b/core/Plugin/MetadataLoader.php index 789f485f0b..fc9e6808a6 100644 --- a/core/Plugin/MetadataLoader.php +++ b/core/Plugin/MetadataLoader.php @@ -12,6 +12,7 @@ namespace Piwik\Plugin; use Exception; use Piwik\Common; +use Piwik\Piwik; use Piwik\PluginsManager; use Piwik\Version; @@ -69,7 +70,7 @@ class MetadataLoader { $descriptionKey = $this->pluginName . '_PluginDescription'; return array( - 'description' => Piwik_Translate($descriptionKey), + 'description' => Piwik::translate($descriptionKey), 'homepage' => 'http://piwik.org/', 'author' => 'Piwik', 'author_homepage' => 'http://piwik.org/', diff --git a/core/ReportRenderer.php b/core/ReportRenderer.php index 18ac8f9c51..e3caba62e3 100644 --- a/core/ReportRenderer.php +++ b/core/ReportRenderer.php @@ -62,7 +62,7 @@ abstract class ReportRenderer @header('Content-Type: text/html; charset=utf-8'); throw new Exception( - Piwik_TranslateException( + Piwik::translateException( 'General_ExceptionInvalidReportRendererFormat', array($name, implode(', ', self::$availableReportRenderers)) ) @@ -215,8 +215,8 @@ abstract class ReportRenderer } $reportColumns = array( - 'label' => Piwik_Translate('General_Name'), - 'value' => Piwik_Translate('General_Value'), + 'label' => Piwik::translate('General_Name'), + 'value' => Piwik::translate('General_Value'), ); } diff --git a/core/ReportRenderer/Pdf.php b/core/ReportRenderer/Pdf.php index 76a5d650c0..683904564f 100644 --- a/core/ReportRenderer/Pdf.php +++ b/core/ReportRenderer/Pdf.php @@ -12,6 +12,7 @@ namespace Piwik\ReportRenderer; use Piwik\Common; use Piwik\Filesystem; +use Piwik\Piwik; use Piwik\Plugins\API\API; use Piwik\ReportRenderer; use Piwik\TCPDF; @@ -153,7 +154,7 @@ class Pdf extends ReportRenderer public function renderFrontPage($reportTitle, $prettyDate, $description, $reportMetadata, $segment) { $reportTitle = $this->formatText($reportTitle); - $dateRange = $this->formatText(Piwik_Translate('General_DateRange') . " " . $prettyDate); + $dateRange = $this->formatText(Piwik::translate('General_DateRange') . " " . $prettyDate); // footer $this->TCPDF->SetFooterFont(array($this->reportFont, $this->reportFontStyle, $this->reportSimpleFontSize)); @@ -164,7 +165,7 @@ class Pdf extends ReportRenderer $this->TCPDF->AddPage(self::PORTRAIT); $this->TCPDF->AddFont($this->reportFont, '', '', false); $this->TCPDF->SetFont($this->reportFont, $this->reportFontStyle, $this->reportSimpleFontSize); - $this->TCPDF->Bookmark(Piwik_Translate('ScheduledReports_FrontPage')); + $this->TCPDF->Bookmark(Piwik::translate('ScheduledReports_FrontPage')); // logo $this->TCPDF->Image(API::getInstance()->getLogoUrl(true), $this->logoImagePosition[0], $this->logoImagePosition[1], 180 / $factor = 2, 0, $type = '', $link = '', $align = '', $resize = false, $dpi = 300); @@ -192,7 +193,7 @@ class Pdf extends ReportRenderer $this->TCPDF->Ln(); $this->TCPDF->SetFont($this->reportFont, '', $this->reportHeaderFontSize - 2); $this->TCPDF->SetTextColor($this->headerTextColor[0], $this->headerTextColor[1], $this->headerTextColor[2]); - $this->TCPDF->Write(1, $this->formatText(Piwik_Translate('ScheduledReports_CustomVisitorSegment') . ' ' . $segment['name'])); + $this->TCPDF->Write(1, $this->formatText(Piwik::translate('ScheduledReports_CustomVisitorSegment') . ' ' . $segment['name'])); } $this->TCPDF->Ln(8); @@ -300,7 +301,7 @@ class Pdf extends ReportRenderer $this->paintReportHeader(); if (!$this->reportHasData()) { - $this->paintMessage(Piwik_Translate('CoreHome_ThereIsNoDataForThisReport')); + $this->paintMessage(Piwik::translate('CoreHome_ThereIsNoDataForThisReport')); return; } diff --git a/core/Session.php b/core/Session.php index b9d1601e6f..76fd1ae99c 100644 --- a/core/Session.php +++ b/core/Session.php @@ -131,7 +131,7 @@ class Session extends Zend_Session $pathToSessions = Filechecks::getErrorMessageMissingPermissions(Filesystem::getPathToPiwikRoot() . '/tmp/sessions/'); $pathToSessions = SettingsPiwik::rewriteTmpPathWithHostname($pathToSessions); $message = sprintf("Error: %s %s %s\n<pre>Debug: the original error was \n%s</pre>", - Piwik_Translate('General_ExceptionUnableToStartSession'), + Piwik::translate('General_ExceptionUnableToStartSession'), $pathToSessions, $enableDbSessions, $e->getMessage() diff --git a/core/TCPDF.php b/core/TCPDF.php index 69b642a6d9..019d178a4b 100644 --- a/core/TCPDF.php +++ b/core/TCPDF.php @@ -39,7 +39,7 @@ class TCPDF extends \TCPDF if ($this->currentPageNo > 1) { $this->SetY(-15); $this->SetFont($this->footer_font[0], $this->footer_font[1], $this->footer_font[2]); - $this->Cell(0, 10, $this->footerContent . Piwik_Translate('ScheduledReports_Pagination', array($this->getAliasNumPage(), $this->getAliasNbPages())), 0, false, 'C', 0, '', 0, false, 'T', 'M'); + $this->Cell(0, 10, $this->footerContent . Piwik::translate('ScheduledReports_Pagination', array($this->getAliasNumPage(), $this->getAliasNbPages())), 0, false, 'C', 0, '', 0, false, 'T', 'M'); } } diff --git a/core/Tracker/GoalManager.php b/core/Tracker/GoalManager.php index a60864ce47..3e3fcf874e 100644 --- a/core/Tracker/GoalManager.php +++ b/core/Tracker/GoalManager.php @@ -190,7 +190,7 @@ class GoalManager $match = ($matched == 0); break; default: - throw new Exception(Piwik_TranslateException('General_ExceptionInvalidGoalPattern', array($pattern_type))); + throw new Exception(Piwik::translateException('General_ExceptionInvalidGoalPattern', array($pattern_type))); break; } if ($match) { diff --git a/core/Translate.php b/core/Translate.php index 22b2193f17..c4d7f3d7e6 100644 --- a/core/Translate.php +++ b/core/Translate.php @@ -87,7 +87,7 @@ class Translate { $path = PIWIK_INCLUDE_PATH . '/lang/' . $language . '.json'; if (!Filesystem::isValidFilename($language) || !is_readable($path)) { - throw new Exception(Piwik_TranslateException('General_ExceptionLanguageFileNotFound', array($language))); + throw new Exception(Piwik::translateException('General_ExceptionLanguageFileNotFound', array($language))); } $data = file_get_contents($path); $translations = json_decode($data, true); diff --git a/core/Translate/Filter/ByBaseTranslations.php b/core/Translate/Filter/ByBaseTranslations.php index ff173b03d7..b245b6a613 100644 --- a/core/Translate/Filter/ByBaseTranslations.php +++ b/core/Translate/Filter/ByBaseTranslations.php @@ -14,7 +14,7 @@ namespace Piwik\Translate\Filter; /** * @package Piwik - * @subpackage Piwik_Translate + * @subpackage Piwik::translate */ class ByBaseTranslations extends FilterAbstract { diff --git a/core/Translate/Filter/ByParameterCount.php b/core/Translate/Filter/ByParameterCount.php index 2a0069b795..2c9cbcca05 100644 --- a/core/Translate/Filter/ByParameterCount.php +++ b/core/Translate/Filter/ByParameterCount.php @@ -14,7 +14,7 @@ namespace Piwik\Translate\Filter; /** * @package Piwik - * @subpackage Piwik_Translate + * @subpackage Piwik::translate */ class ByParameterCount extends FilterAbstract { diff --git a/core/Translate/Filter/EmptyTranslations.php b/core/Translate/Filter/EmptyTranslations.php index be3f470aac..e0467f3d3d 100644 --- a/core/Translate/Filter/EmptyTranslations.php +++ b/core/Translate/Filter/EmptyTranslations.php @@ -14,7 +14,7 @@ namespace Piwik\Translate\Filter; /** * @package Piwik - * @subpackage Piwik_Translate + * @subpackage Piwik::translate */ class EmptyTranslations extends FilterAbstract { diff --git a/core/Translate/Filter/EncodedEntities.php b/core/Translate/Filter/EncodedEntities.php index 25c6853671..b5bf295890 100644 --- a/core/Translate/Filter/EncodedEntities.php +++ b/core/Translate/Filter/EncodedEntities.php @@ -16,7 +16,7 @@ use Piwik\Translate; /** * @package Piwik - * @subpackage Piwik_Translate + * @subpackage Piwik::translate */ class EncodedEntities extends FilterAbstract { diff --git a/core/Translate/Filter/UnnecassaryWhitespaces.php b/core/Translate/Filter/UnnecassaryWhitespaces.php index f72f32ce5a..250557ad02 100644 --- a/core/Translate/Filter/UnnecassaryWhitespaces.php +++ b/core/Translate/Filter/UnnecassaryWhitespaces.php @@ -14,7 +14,7 @@ namespace Piwik\Translate\Filter; /** * @package Piwik - * @subpackage Piwik_Translate + * @subpackage Piwik::translate */ class UnnecassaryWhitespaces extends FilterAbstract { diff --git a/core/Translate/Validate/CoreTranslations.php b/core/Translate/Validate/CoreTranslations.php index 160f09b1e9..8fff7033bb 100644 --- a/core/Translate/Validate/CoreTranslations.php +++ b/core/Translate/Validate/CoreTranslations.php @@ -16,7 +16,7 @@ use Piwik\Common; /** * @package Piwik - * @subpackage Piwik_Translate + * @subpackage Piwik::translate */ class CoreTranslations extends ValidateAbstract { diff --git a/core/Translate/Validate/NoScripts.php b/core/Translate/Validate/NoScripts.php index c7751e81e4..c5e3ba1212 100644 --- a/core/Translate/Validate/NoScripts.php +++ b/core/Translate/Validate/NoScripts.php @@ -13,7 +13,7 @@ namespace Piwik\Translate\Validate; /** * @package Piwik - * @subpackage Piwik_Translate + * @subpackage Piwik::translate */ class NoScripts extends ValidateAbstract { diff --git a/core/Translate/Writer.php b/core/Translate/Writer.php index 800bbf7d47..06d77df7d7 100644 --- a/core/Translate/Writer.php +++ b/core/Translate/Writer.php @@ -13,6 +13,7 @@ namespace Piwik\Translate; use Exception; use Piwik\Filesystem; +use Piwik\Piwik; use Piwik\PluginsManager; use Piwik\Translate\Filter\FilterAbstract; use Piwik\Translate\Validate\ValidateAbstract; @@ -21,7 +22,7 @@ use Piwik\Translate\Validate\ValidateAbstract; * Writes clean translations to file * * @package Piwik - * @package Piwik_Translate + * @package Piwik::translate */ class Writer { @@ -96,7 +97,7 @@ class Writer if (!in_array($pluginName, $installedPlugins)) { - throw new Exception(Piwik_TranslateException('General_ExceptionLanguageFileNotFound', array($pluginName))); + throw new Exception(Piwik::translateException('General_ExceptionLanguageFileNotFound', array($pluginName))); } $this->pluginName = $pluginName; @@ -111,7 +112,7 @@ class Writer public function setLanguage($language) { if (!preg_match('/^([a-z]{2,3}(-[a-z]{2,3})?)$/i', $language)) { - throw new Exception(Piwik_TranslateException('General_ExceptionLanguageFileNotFound', array($language))); + throw new Exception(Piwik::translateException('General_ExceptionLanguageFileNotFound', array($language))); } $this->language = strtolower($language); diff --git a/core/Twig.php b/core/Twig.php index d0a3ddea5b..369bdf6527 100644 --- a/core/Twig.php +++ b/core/Twig.php @@ -211,7 +211,7 @@ class Twig } try { - $stringTranslated = Piwik_Translate($stringToken, $aValues); + $stringTranslated = Piwik::translate($stringToken, $aValues); } catch (Exception $e) { $stringTranslated = $stringToken; } diff --git a/core/Updates/0.4.4.php b/core/Updates/0.4.4.php index ad70569c71..d17d5a200b 100644 --- a/core/Updates/0.4.4.php +++ b/core/Updates/0.4.4.php @@ -11,6 +11,7 @@ namespace Piwik\Updates; +use Piwik\Piwik; use Piwik\Updates; /** @@ -24,7 +25,7 @@ class Updates_0_4_4 extends Updates if (file_exists($obsoleteFile)) { $rc = @unlink($obsoleteFile); if (!$rc) { - throw new \Exception(Piwik_TranslateException('General_ExceptionUndeletableFile', array($obsoleteFile))); + throw new \Exception(Piwik::translateException('General_ExceptionUndeletableFile', array($obsoleteFile))); } } } diff --git a/core/ViewDataTable.php b/core/ViewDataTable.php index 9bf0a4b544..05d62e4cc8 100644 --- a/core/ViewDataTable.php +++ b/core/ViewDataTable.php @@ -435,7 +435,7 @@ class ViewDataTable * public function getReportDisplayProperties(&$properties) * { * $properties['Provider.getProvider'] = array( - * 'translations' => array('label' => Piwik_Translate('Provider_ColumnProvider')), + * 'translations' => array('label' => Piwik::translate('Provider_ColumnProvider')), * 'filter_limit' => 5 * ) * } @@ -709,11 +709,11 @@ class ViewDataTable $elapsedSeconds = time() - $date->getTimestamp(); $timeAgo = MetricsFormatter::getPrettyTimeFromSeconds($elapsedSeconds); - return Piwik_Translate('CoreHome_ReportGeneratedXAgo', $timeAgo); + return Piwik::translate('CoreHome_ReportGeneratedXAgo', $timeAgo); } $prettyDate = $date->getLocalized("%longYear%, %longMonth% %day%") . $date->toString('S'); - return Piwik_Translate('CoreHome_ReportGeneratedOn', $prettyDate); + return Piwik::translate('CoreHome_ReportGeneratedOn', $prettyDate); } /** @@ -1176,7 +1176,7 @@ class ViewDataTable if ($this->show_table) { $normalViewIcons['buttons'][] = array( 'id' => 'table', - 'title' => Piwik_Translate('General_DisplaySimpleTable'), + 'title' => Piwik::translate('General_DisplaySimpleTable'), 'icon' => 'plugins/Zeitgeist/images/table.png', ); } @@ -1184,7 +1184,7 @@ class ViewDataTable if ($this->show_table_all_columns) { $normalViewIcons['buttons'][] = array( 'id' => 'tableAllColumns', - 'title' => Piwik_Translate('General_DisplayTableWithMoreMetrics'), + 'title' => Piwik::translate('General_DisplayTableWithMoreMetrics'), 'icon' => 'plugins/Zeitgeist/images/table_more.png' ); } @@ -1198,7 +1198,7 @@ class ViewDataTable $normalViewIcons['buttons'][] = array( 'id' => 'tableGoals', - 'title' => Piwik_Translate('General_DisplayTableWithGoalMetrics'), + 'title' => Piwik::translate('General_DisplayTableWithGoalMetrics'), 'icon' => $icon ); } @@ -1206,16 +1206,16 @@ class ViewDataTable if ($this->show_ecommerce) { $normalViewIcons['buttons'][] = array( 'id' => 'ecommerceOrder', - 'title' => Piwik_Translate('General_EcommerceOrders'), + 'title' => Piwik::translate('General_EcommerceOrders'), 'icon' => 'plugins/Zeitgeist/images/ecommerceOrder.gif', - 'text' => Piwik_Translate('General_EcommerceOrders') + 'text' => Piwik::translate('General_EcommerceOrders') ); $normalViewIcons['buttons'][] = array( 'id' => 'ecommerceAbandonedCart', - 'title' => Piwik_Translate('General_AbandonedCarts'), + 'title' => Piwik::translate('General_AbandonedCarts'), 'icon' => 'plugins/Zeitgeist/images/ecommerceAbandonedCart.gif', - 'text' => Piwik_Translate('General_AbandonedCarts') + 'text' => Piwik::translate('General_AbandonedCarts') ); } @@ -1233,7 +1233,7 @@ class ViewDataTable if ($this->show_bar_chart) { $graphViewIcons['buttons'][] = array( 'id' => 'graphVerticalBar', - 'title' => Piwik_Translate('General_VBarGraph'), + 'title' => Piwik::translate('General_VBarGraph'), 'icon' => 'plugins/Zeitgeist/images/chart_bar.png' ); } @@ -1241,7 +1241,7 @@ class ViewDataTable if ($this->show_pie_chart) { $graphViewIcons['buttons'][] = array( 'id' => 'graphPie', - 'title' => Piwik_Translate('General_Piechart'), + 'title' => Piwik::translate('General_Piechart'), 'icon' => 'plugins/Zeitgeist/images/chart_pie.png' ); } @@ -1249,7 +1249,7 @@ class ViewDataTable if ($this->show_tag_cloud) { $graphViewIcons['buttons'][] = array( 'id' => 'cloud', - 'title' => Piwik_Translate('General_TagCloud'), + 'title' => Piwik::translate('General_TagCloud'), 'icon' => 'plugins/Zeitgeist/images/tagcloud.png' ); } @@ -1261,7 +1261,7 @@ class ViewDataTable foreach ($nonCoreVisualizationInfo as $format => $info) { $graphViewIcons['buttons'][] = array( 'id' => $format, - 'title' => Piwik_Translate($info['title']), + 'title' => Piwik::translate($info['title']), 'icon' => $info['table_icon'] ); } diff --git a/core/ViewDataTable/Graph.php b/core/ViewDataTable/Graph.php index 518fff6edf..f0d2f0006e 100644 --- a/core/ViewDataTable/Graph.php +++ b/core/ViewDataTable/Graph.php @@ -12,6 +12,7 @@ namespace Piwik\ViewDataTable; use Piwik\DataTable\Row; +use Piwik\Piwik; /** * This is an abstract visualization that should be the base of any 'graph' visualization. @@ -133,8 +134,8 @@ abstract class Graph extends Visualization parent::__construct($template); if ($view->show_goals) { - $view->translations['nb_conversions'] = Piwik_Translate('Goals_ColumnConversions'); - $view->translations['revenue'] = Piwik_Translate('General_TotalRevenue'); + $view->translations['nb_conversions'] = Piwik::translate('Goals_ColumnConversions'); + $view->translations['revenue'] = Piwik::translate('General_TotalRevenue'); } // TODO: this should not be required here. filter_limit should not be a view property, instead HtmlTable should use 'limit' or something, diff --git a/core/Visualization/Sparkline.php b/core/Visualization/Sparkline.php index fbeeea0a89..9ae0fd66b7 100644 --- a/core/Visualization/Sparkline.php +++ b/core/Visualization/Sparkline.php @@ -12,6 +12,7 @@ namespace Piwik\Visualization; use Piwik\Common; +use Piwik\Piwik; use Piwik\View\ViewInterface; use Sparkline_Line; @@ -114,7 +115,7 @@ class Sparkline implements ViewInterface $min = $max = $last = null; $i = 0; - $toRemove = array('%', str_replace('%s', '', Piwik_Translate('General_Seconds'))); + $toRemove = array('%', str_replace('%s', '', Piwik::translate('General_Seconds'))); foreach ($this->values as $value) { // 50% and 50s should be plotted as 50 $value = str_replace($toRemove, '', $value); diff --git a/core/WidgetsList.php b/core/WidgetsList.php index 71a813b64f..9f65561aba 100644 --- a/core/WidgetsList.php +++ b/core/WidgetsList.php @@ -43,10 +43,10 @@ class WidgetsList $widgets = array(); foreach (self::$widgets as $key => $v) { - if (isset($widgets[Piwik_Translate($key)])) { - $v = array_merge($widgets[Piwik_Translate($key)], $v); + if (isset($widgets[Piwik::translate($key)])) { + $v = array_merge($widgets[Piwik::translate($key)], $v); } - $widgets[Piwik_Translate($key)] = $v; + $widgets[Piwik::translate($key)] = $v; } return $widgets; } @@ -118,7 +118,7 @@ class WidgetsList */ static public function add($widgetCategory, $widgetName, $controllerName, $controllerAction, $customParameters = array()) { - $widgetName = Piwik_Translate($widgetName); + $widgetName = Piwik::translate($widgetName); $widgetUniqueId = 'widget' . $controllerName . $controllerAction; foreach ($customParameters as $name => $value) { if (is_array($value)) { diff --git a/core/functions.php b/core/functions.php index 38fae1c387..8b32ab0b25 100644 --- a/core/functions.php +++ b/core/functions.php @@ -18,50 +18,6 @@ namespace { use Piwik\Menu\Top; /** - * Returns translated string or given message if translation is not found. - * - * @param string $string Translation string index - * @param array|string|int $args sprintf arguments - * @return string - * @api - */ - function Piwik_Translate($string, $args = array()) - { - if (!is_array($args)) { - $args = array($args); - } - - if (strpos($string, "_") !== false) { - list($plugin, $key) = explode("_", $string, 2); - if (isset($GLOBALS['Piwik_translations'][$plugin]) && isset($GLOBALS['Piwik_translations'][$plugin][$key])) { - $string = $GLOBALS['Piwik_translations'][$plugin][$key]; - } - } - if (count($args) == 0) { - return $string; - } - return vsprintf($string, $args); - } - - /** - * Returns translated string or given message if translation is not found. - * This function does not throw any exception. Use it to translate exceptions. - * - * @param string $message Translation string index - * @param array $args sprintf arguments - * @return string - * @api - */ - function Piwik_TranslateException($message, $args = array()) - { - try { - return Piwik_Translate($message, $args); - } catch (Exception $e) { - return $message; - } - } - - /** * Returns the AdminMenu * * @return Array |