本文整理汇总了PHP中Piwik\Translate::reloadLanguage方法的典型用法代码示例。如果您正苦于以下问题:PHP Translate::reloadLanguage方法的具体用法?PHP Translate::reloadLanguage怎么用?PHP Translate::reloadLanguage使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Piwik\Translate
的用法示例。
在下文中一共展示了Translate::reloadLanguage方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
$dialog = $this->getHelperSet()->get('dialog');
$command = $this->getApplication()->find('translations:fetch');
$arguments = array('command' => 'translations:fetch', '--username' => $input->getOption('username'), '--password' => $input->getOption('password'), '--keep-english' => true);
$inputObject = new ArrayInput($arguments);
$inputObject->setInteractive($input->isInteractive());
$command->run($inputObject, $output);
$englishFromOTrance = FetchFromOTrance::getDownloadPath() . DIRECTORY_SEPARATOR . 'en.json';
if (!file_exists($englishFromOTrance)) {
$output->writeln("English file from oTrance missing. Aborting");
return;
}
$englishFromOTrance = json_decode(file_get_contents($englishFromOTrance), true);
Translate::reloadLanguage('en');
$availableTranslations = $GLOBALS['Piwik_translations'];
$categories = array_unique(array_merge(array_keys($englishFromOTrance), array_keys($availableTranslations)));
sort($categories);
$unnecessary = $outdated = $missing = array();
foreach ($categories as $category) {
if (!empty($englishFromOTrance[$category])) {
foreach ($englishFromOTrance[$category] as $key => $value) {
if (!array_key_exists($category, $availableTranslations) || !array_key_exists($key, $availableTranslations[$category])) {
$unnecessary[] = sprintf('%s_%s', $category, $key);
continue;
} else {
if (html_entity_decode($availableTranslations[$category][$key]) != html_entity_decode($englishFromOTrance[$category][$key])) {
$outdated[] = sprintf('%s_%s', $category, $key);
continue;
}
}
}
}
if (!empty($availableTranslations[$category])) {
foreach ($availableTranslations[$category] as $key => $value) {
if (!array_key_exists($category, $englishFromOTrance) || !array_key_exists($key, $englishFromOTrance[$category])) {
$missing[] = sprintf('%s_%s', $category, $key);
continue;
}
}
}
}
$output->writeln("");
if (!empty($missing)) {
$output->writeln("<bg=yellow;options=bold>-- Following keys are missing on oTrance --</bg=yellow;options=bold>");
$output->writeln(implode("\n", $missing));
$output->writeln("");
}
if (!empty($unnecessary)) {
$output->writeln("<bg=yellow;options=bold>-- Following keys might be unnecessary on oTrance --</bg=yellow;options=bold>");
$output->writeln(implode("\n", $unnecessary));
$output->writeln("");
}
if (!empty($outdated)) {
$output->writeln("<bg=yellow;options=bold>-- Following keys are outdated on oTrance --</bg=yellow;options=bold>");
$output->writeln(implode("\n", $outdated));
$output->writeln("");
}
$output->writeln("Finished.");
}
示例2: setUp
public function setUp()
{
parent::setUp();
StaticCache::clearAll();
PluginAwareStaticCache::clearAll();
Translate::reloadLanguage('en');
$this->api = API::getInstance();
}
示例3: getEnglishTranslationForFeatureName
private function getEnglishTranslationForFeatureName($featureName)
{
$loadedLanguage = Translate::getLanguageLoaded();
if ($loadedLanguage == 'en') {
return $featureName;
}
$translationKeyForFeature = Translate::findTranslationKeyForTranslation($featureName);
if (!empty($translationKeyForFeature)) {
Translate::reloadLanguage('en');
$featureName = Piwik::translate($translationKeyForFeature);
Translate::reloadLanguage($loadedLanguage);
return $featureName;
}
return $featureName;
}
示例4: dispatch
/**
* @param \Exception|null $exception
*/
public function dispatch($exception = null)
{
if ($exception) {
$message = $exception->getMessage();
} else {
$message = '';
}
Translate::reloadLanguage();
$action = Common::getRequestVar('action', 'welcome', 'string');
if ($this->isAllowedAction($action)) {
echo FrontController::getInstance()->dispatch('Installation', $action, array($message));
} else {
Piwik::exitWithErrorMessage(Piwik::translate('Installation_NoConfigFound'));
}
exit;
}
示例5: doRun
public function doRun(InputInterface $input, OutputInterface $output)
{
$this->initPiwikHost($input);
$this->initConfig($output);
try {
self::initPlugins();
} catch (\Exception $e) {
// Piwik not installed yet, no config file?
}
Translate::reloadLanguage('en');
$commands = $this->getAvailableCommands();
foreach ($commands as $command) {
$this->addCommandIfExists($command);
}
$self = $this;
return Access::doAsSuperUser(function () use($input, $output, $self) {
return call_user_func(array($self, 'Symfony\\Component\\Console\\Application::doRun'), $input, $output);
});
}
示例6: doRun
public function doRun(InputInterface $input, OutputInterface $output)
{
$this->initPiwikHost($input);
$this->initConfig($output);
try {
self::initPlugins();
} catch (\Exception $e) {
// Piwik not installed yet, no config file?
}
Translate::reloadLanguage('en');
$commands = $this->getAvailableCommands();
foreach ($commands as $command) {
if (!class_exists($command)) {
Log::warning(sprintf('Cannot add command %s, class does not exist', $command));
} elseif (!is_subclass_of($command, 'Piwik\\Plugin\\ConsoleCommand')) {
Log::warning(sprintf('Cannot add command %s, class does not extend Piwik\\Plugin\\ConsoleCommand', $command));
} else {
$this->add(new $command());
}
}
return parent::doRun($input, $output);
}
示例7: changeLanguage
/**
* changing the language within one request is a bit fancy
* in order to keep the core clean, we need a little hack here
*
* @param string $langId
*/
protected function changeLanguage($langId)
{
if ($this->lastLanguage != $langId) {
$_GET['language'] = $langId;
Translate::reset();
Translate::reloadLanguage($langId);
}
$this->lastLanguage = $langId;
}
示例8: loadEnglishTranslation
private function loadEnglishTranslation()
{
Translate::reloadLanguage('en');
}
示例9: performSetUp
public function performSetUp($setupEnvironmentOnly = false)
{
try {
if ($this->createConfig) {
Config::getInstance()->setTestEnvironment();
}
$this->dbName = $this->getDbName();
if ($this->persistFixtureData) {
$this->dropDatabaseInSetUp = false;
$this->dropDatabaseInTearDown = false;
$this->overwriteExisting = false;
$this->removeExistingSuperUser = false;
Config::getInstance()->database_tests['dbname'] = Config::getInstance()->database['dbname'] = $this->dbName;
$this->getTestEnvironment()->dbName = $this->dbName;
}
if ($this->dbName === false) {
// must be after test config is created
$this->dbName = Config::getInstance()->database['dbname'];
}
static::connectWithoutDatabase();
if ($this->dropDatabaseInSetUp || $this->resetPersistedFixture) {
$this->dropDatabase();
}
DbHelper::createDatabase($this->dbName);
DbHelper::disconnectDatabase();
// reconnect once we're sure the database exists
Config::getInstance()->database['dbname'] = $this->dbName;
Db::createDatabaseObject();
Db::get()->query("SET wait_timeout=28800;");
DbHelper::createTables();
\Piwik\Plugin\Manager::getInstance()->unloadPlugins();
} catch (Exception $e) {
static::fail("TEST INITIALIZATION FAILED: " . $e->getMessage() . "\n" . $e->getTraceAsString());
}
include "DataFiles/SearchEngines.php";
include "DataFiles/Socials.php";
include "DataFiles/Languages.php";
include "DataFiles/Countries.php";
include "DataFiles/Currencies.php";
include "DataFiles/LanguageToCountry.php";
include "DataFiles/Providers.php";
if (!$this->isFixtureSetUp()) {
DbHelper::truncateAllTables();
}
static::createAccessInstance();
// We need to be SU to create websites for tests
Piwik::setUserHasSuperUserAccess();
Cache::deleteTrackerCache();
static::loadAllPlugins($this->getTestEnvironment(), $this->testCaseClass, $this->extraPluginsToLoad);
self::updateDatabase();
self::installAndActivatePlugins();
$_GET = $_REQUEST = array();
$_SERVER['HTTP_REFERER'] = '';
// Make sure translations are loaded to check messages in English
if ($this->loadTranslations) {
Translate::reloadLanguage('en');
APILanguageManager::getInstance()->setLanguageForUser('superUserLogin', 'en');
}
FakeAccess::$superUserLogin = 'superUserLogin';
\Piwik\SettingsPiwik::$cachedKnownSegmentsToArchive = null;
\Piwik\CacheFile::$invalidateOpCacheBeforeRead = true;
if ($this->configureComponents) {
\Piwik\Plugins\PrivacyManager\IPAnonymizer::deactivate();
\Piwik\Plugins\PrivacyManager\DoNotTrackHeaderChecker::deactivate();
}
if ($this->createSuperUser) {
self::createSuperUser($this->removeExistingSuperUser);
}
if ($setupEnvironmentOnly) {
return;
}
$this->getTestEnvironment()->save();
$this->getTestEnvironment()->executeSetupTestEnvHook();
Piwik_TestingEnvironment::addSendMailHook();
if ($this->overwriteExisting || !$this->isFixtureSetUp()) {
$this->setUp();
$this->markFixtureSetUp();
$this->log("Database {$this->dbName} marked as successfully set up.");
} else {
$this->log("Using existing database {$this->dbName}.");
}
}
示例10: setup
protected function setup()
{
parent::setup();
Translate::reloadLanguage('en');
}
示例11: init
//.........这里部分代码省略.........
throw $exceptionToThrow;
}
// try to connect to the database
try {
Db::createDatabaseObject();
Db::fetchAll("SELECT DATABASE()");
} catch (Exception $exception) {
if (self::shouldRethrowException()) {
throw $exception;
}
Log::debug($exception);
/**
* Triggered when Piwik cannot connect to the database.
*
* This event can be used to start the installation process or to display a custom error
* message.
*
* @param Exception $exception The exception thrown from creating and testing the database
* connection.
*/
Piwik::postEvent('Db.cannotConnectToDb', array($exception), $pending = true);
throw $exception;
}
// try to get an option (to check if data can be queried)
try {
Option::get('TestingIfDatabaseConnectionWorked');
} catch (Exception $exception) {
if (self::shouldRethrowException()) {
throw $exception;
}
Log::debug($exception);
/**
* Triggered when Piwik cannot access database data.
*
* This event can be used to start the installation process or to display a custom error
* message.
*
* @param Exception $exception The exception thrown from trying to get an option value.
*/
Piwik::postEvent('Config.badConfigurationFile', array($exception), $pending = true);
throw $exception;
}
// Init the Access object, so that eg. core/Updates/* can enforce Super User and use some APIs
Access::getInstance();
/**
* Triggered just after the platform is initialized and plugins are loaded.
*
* This event can be used to do early initialization.
*
* _Note: At this point the user is not authenticated yet._
*/
Piwik::postEvent('Request.dispatchCoreAndPluginUpdatesScreen');
\Piwik\Plugin\Manager::getInstance()->installLoadedPlugins();
// ensure the current Piwik URL is known for later use
if (method_exists('Piwik\\SettingsPiwik', 'getPiwikUrl')) {
SettingsPiwik::getPiwikUrl();
}
/**
* Triggered before the user is authenticated, when the global authentication object
* should be created.
*
* Plugins that provide their own authentication implementation should use this event
* to set the global authentication object (which must derive from {@link Piwik\Auth}).
*
* **Example**
*
* Piwik::addAction('Request.initAuthenticationObject', function() {
* Piwik\Registry::set('auth', new MyAuthImplementation());
* });
*/
Piwik::postEvent('Request.initAuthenticationObject');
try {
$authAdapter = Registry::get('auth');
} catch (Exception $e) {
throw new Exception("Authentication object cannot be found in the Registry. Maybe the Login plugin is not activated?\n <br />You can activate the plugin by adding:<br />\n <code>Plugins[] = Login</code><br />\n under the <code>[Plugins]</code> section in your config/config.ini.php");
}
Access::getInstance()->reloadAccess($authAdapter);
// Force the auth to use the token_auth if specified, so that embed dashboard
// and all other non widgetized controller methods works fine
if (Common::getRequestVar('token_auth', false, 'string') !== false) {
Request::reloadAuthUsingTokenAuth();
}
SettingsServer::raiseMemoryLimitIfNecessary();
Translate::reloadLanguage();
\Piwik\Plugin\Manager::getInstance()->postLoadPlugins();
/**
* Triggered after the platform is initialized and after the user has been authenticated, but
* before the platform has handled the request.
*
* Piwik uses this event to check for updates to Piwik.
*/
Piwik::postEvent('Platform.initialized');
} catch (Exception $e) {
if (self::shouldRethrowException()) {
throw $e;
}
$debugTrace = $e->getTraceAsString();
Piwik_ExitWithMessage($e->getMessage(), $debugTrace, true);
}
}
示例12: setUp
public function setUp()
{
Translate::reloadLanguage('en');
}
示例13: generateReport
/**
* Generates a report file.
*
* @param int $idReport ID of the report to generate.
* @param string $date YYYY-MM-DD
* @param bool|false|string $language If not passed, will use default language.
* @param bool|false|int $outputType 1 = download report, 2 = save report to disk, 3 = output report in browser, 4 = return report content to caller, defaults to download
* @param bool|false|string $period Defaults to 'day'. If not specified, will default to the report's period set when creating the report
* @param bool|false|string $reportFormat 'pdf', 'html' or any other format provided via the ScheduledReports.getReportFormats hook
* @param bool|false|array $parameters array of parameters
* @return array|void
*/
public function generateReport($idReport, $date, $language = false, $outputType = false, $period = false, $reportFormat = false, $parameters = false)
{
Piwik::checkUserIsNotAnonymous();
// load specified language
if (empty($language)) {
$language = Translate::getLanguageDefault();
}
Translate::reloadLanguage($language);
$reports = $this->getReports($idSite = false, $_period = false, $idReport);
$report = reset($reports);
$idSite = $report['idsite'];
$login = $report['login'];
$reportType = $report['type'];
$this->checkUserHasViewPermission($login, $idSite);
// override report period
if (empty($period)) {
$period = $report['period'];
}
// override report format
if (!empty($reportFormat)) {
self::validateReportFormat($reportType, $reportFormat);
$report['format'] = $reportFormat;
} else {
$reportFormat = $report['format'];
}
// override and/or validate report parameters
$report['parameters'] = Common::json_decode(self::validateReportParameters($reportType, empty($parameters) ? $report['parameters'] : $parameters), true);
// available reports
$availableReportMetadata = \Piwik\Plugins\API\API::getInstance()->getReportMetadata($idSite);
// we need to lookup which reports metadata are registered in this report
$reportMetadata = array();
foreach ($availableReportMetadata as $metadata) {
if (in_array($metadata['uniqueId'], $report['reports'])) {
$reportMetadata[] = $metadata;
}
}
// the report will be rendered with the first 23 rows and will aggregate other rows in a summary row
// 23 rows table fits in one portrait page
$initialFilterTruncate = Common::getRequestVar('filter_truncate', false);
$_GET['filter_truncate'] = self::REPORT_TRUNCATE;
$prettyDate = null;
$processedReports = array();
$segment = self::getSegment($report['idsegment']);
foreach ($reportMetadata as $action) {
$apiModule = $action['module'];
$apiAction = $action['action'];
$apiParameters = array();
if (isset($action['parameters'])) {
$apiParameters = $action['parameters'];
}
$mustRestoreGET = false;
// all Websites dashboard should not be truncated in the report
if ($apiModule == 'MultiSites') {
$mustRestoreGET = $_GET;
$_GET['enhanced'] = true;
if ($apiAction == 'getAll') {
$_GET['filter_truncate'] = false;
// when a view/admin user created a report, workaround the fact that "Super User"
// is enforced in Scheduled tasks, and ensure Multisites.getAll only return the websites that this user can access
$userLogin = $report['login'];
if (!empty($userLogin) && !Piwik::hasTheUserSuperUserAccess($userLogin)) {
$_GET['_restrictSitesToLogin'] = $userLogin;
}
}
}
$processedReport = \Piwik\Plugins\API\API::getInstance()->getProcessedReport($idSite, $period, $date, $apiModule, $apiAction, $segment != null ? urlencode($segment['definition']) : false, $apiParameters, $idGoal = false, $language);
$processedReport['segment'] = $segment;
// TODO add static method getPrettyDate($period, $date) in Period
$prettyDate = $processedReport['prettyDate'];
if ($mustRestoreGET) {
$_GET = $mustRestoreGET;
}
$processedReports[] = $processedReport;
}
// restore filter truncate parameter value
if ($initialFilterTruncate !== false) {
$_GET['filter_truncate'] = $initialFilterTruncate;
}
/**
* Triggered when generating the content of scheduled reports.
*
* This event can be used to modify the report data or report metadata of one or more reports
* in a scheduled report, before the scheduled report is rendered and delivered.
*
* TODO: list data available in $report or make it a new class that can be documented (same for
* all other events that use a $report)
*
* @param array &$processedReports The list of processed reports in the scheduled
//.........这里部分代码省略.........
示例14: getMetadata
/**
* Loads reports metadata, then return the requested one,
* matching optional API parameters.
*/
public function getMetadata($idSite, $apiModule, $apiAction, $apiParameters = array(), $language = false, $period = false, $date = false, $hideMetricsDoc = false, $showSubtableReports = false)
{
Translate::reloadLanguage($language);
$reporter = new ProcessedReport();
$metadata = $reporter->getMetadata($idSite, $apiModule, $apiAction, $apiParameters, $language, $period, $date, $hideMetricsDoc, $showSubtableReports);
return $metadata;
}