php Piwik-Translate类(方法)实例源码

下面列出了php Piwik-Translate 类(方法)源码代码实例,从而了解它的用法。

作者:emersonmatsumot    项目:piwi   
public function configureReportingMenu(MenuReporting $menu)
 {
     $idSite = Common::getRequestVar('idSite', null, 'int');
     $goals = API::getInstance()->getGoals($idSite);
     $mainGoalMenu = $this->getGoalCategoryName($idSite);
     $site = new Site($idSite);
     if (count($goals) == 0) {
         $menu->add($mainGoalMenu, '', array('module' => 'Goals', 'action' => $site->isEcommerceEnabled() ? 'ecommerceReport' : 'addNewGoal', 'idGoal' => $site->isEcommerceEnabled() ? Piwik::LABEL_ID_GOAL_IS_ECOMMERCE_ORDER : null), true, 25);
         if ($site->isEcommerceEnabled()) {
             $menu->add($mainGoalMenu, 'Goals_Ecommerce', array('module' => 'Goals', 'action' => 'ecommerceReport', 'idGoal' => Piwik::LABEL_ID_GOAL_IS_ECOMMERCE_ORDER), true, 1);
         }
         $menu->add($mainGoalMenu, 'Goals_AddNewGoal', array('module' => 'Goals', 'action' => 'addNewGoal'));
     } else {
         $menu->add($mainGoalMenu, '', array('module' => 'Goals', 'action' => $site->isEcommerceEnabled() ? 'ecommerceReport' : 'index', 'idGoal' => $site->isEcommerceEnabled() ? Piwik::LABEL_ID_GOAL_IS_ECOMMERCE_ORDER : null), true, 25);
         if ($site->isEcommerceEnabled()) {
             $menu->add($mainGoalMenu, 'Goals_Ecommerce', array('module' => 'Goals', 'action' => 'ecommerceReport', 'idGoal' => Piwik::LABEL_ID_GOAL_IS_ECOMMERCE_ORDER), true, 1);
         }
         $menu->add($mainGoalMenu, 'Goals_GoalsOverview', array('module' => 'Goals', 'action' => 'index'), true, 2);
         $group = new Group();
         foreach ($goals as $goal) {
             $subMenuName = str_replace('%', '%%', Translate::clean($goal['name']));
             $params = array('module' => 'Goals', 'action' => 'goalReport', 'idGoal' => $goal['idgoal']);
             $tooltip = sprintf('%s (id = %d)', $subMenuName, $goal['idgoal']);
             if (count($goals) <= 3) {
                 $menu->add($mainGoalMenu, $subMenuName, $params, true, 50, $tooltip);
             } else {
                 $group->add($subMenuName, $params, $tooltip);
             }
         }
         if (count($goals) > 3) {
             $menu->addGroup($mainGoalMenu, 'Goals_ChooseGoal', $group, $orderId = 50, $tooltip = false);
         }
     }
 }

作者:kreyne    项目:elmsl   
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.");
 }

作者:jos    项目:CGE-File-Sharin   
protected function completeKey($cacheKey)
 {
     $pluginManager = PluginManager::getInstance();
     $pluginNames = $pluginManager->getLoadedPluginsName();
     $cacheKey = $cacheKey . md5(implode('', $pluginNames)) . Translate::getLanguageLoaded();
     return $cacheKey;
 }

作者:a4tunad    项目:piwi   
/**
  * @group Core
  */
 public function testGetPrettyString()
 {
     Translate::loadEnglishTranslation();
     $year = new Year(Date::factory('2024-10-09'));
     $shouldBe = '2024';
     $this->assertEquals($shouldBe, $year->getPrettyString());
 }

作者:NikitaEgoro    项目:plugin-clickhea   
public function init()
 {
     $__languages = array('bg', 'cz', 'de', 'en', 'es', 'fr', 'hu', 'id', 'it', 'ja', 'nl', 'pl', 'pt', 'ro', 'ru', 'sr', 'tr', 'uk', 'zh');
     if (isset($_SERVER['REQUEST_URI']) && $_SERVER['REQUEST_URI'] !== '') {
         $realPath =& $_SERVER['REQUEST_URI'];
     } elseif (isset($_SERVER['SCRIPT_NAME']) && $_SERVER['SCRIPT_NAME'] !== '') {
         $realPath =& $_SERVER['SCRIPT_NAME'];
     } else {
         exit(LANG_UNKNOWN_DIR);
     }
     /** First of all, check if we are inside Piwik */
     $dirName = dirname($realPath);
     if ($dirName === '/') {
         $dirName = '';
     }
     define('CLICKHEAT_PATH', $dirName . '/plugins/ClickHeat/libs/');
     define('CLICKHEAT_INDEX_PATH', 'index.php?module=ClickHeat&');
     define('CLICKHEAT_ROOT', PIWIK_INCLUDE_PATH . '/plugins/ClickHeat/libs/');
     define('CLICKHEAT_CONFIG', PIWIK_INCLUDE_PATH . '/plugins/ClickHeat/clickheat.php');
     define('IS_PIWIK_MODULE', true);
     if (Piwik::hasUserSuperUserAccess()) {
         define('CLICKHEAT_ADMIN', true);
     } else {
         define('CLICKHEAT_ADMIN', false);
     }
     define('CLICKHEAT_LANGUAGE', Translate::getLanguageToLoad());
     require_once CLICKHEAT_CONFIG;
     /** Specific definitions */
     $clickheatConf['__screenSizes'] = array(0, 640, 800, 1024, 1280, 1440, 1600, 1800);
     $clickheatConf['__browsersList'] = array('all' => '', 'firefox' => 'Firefox', 'chrome' => 'Google Chrome', 'msie' => 'Internet Explorer', 'safari' => 'Safari', 'opera' => 'Opera', 'kmeleon' => 'K-meleon', 'unknown' => '');
     self::conf($clickheatConf);
 }

作者:pombredann    项目:ArcherSy   
/**
  * @param InputInterface $input
  * @param OutputInterface $output
  * @return array
  * @throws \RuntimeException
  */
 protected function getCategory(InputInterface $input, OutputInterface $output)
 {
     $validate = function ($category) {
         if (empty($category)) {
             throw new \InvalidArgumentException('Please enter the name of the category your widget should belong to');
         }
         return $category;
     };
     $category = $input->getOption('category');
     $categories = array();
     foreach (Widgets::getAllWidgets() as $widget) {
         if ($widget->getCategory()) {
             $categories[] = Piwik::translate($widget->getCategory());
         }
     }
     $categories = array_values(array_unique($categories));
     if (empty($category)) {
         $dialog = $this->getHelperSet()->get('dialog');
         $category = $dialog->askAndValidate($output, 'Enter the widget category, for instance "Visitor" (you can reuse any existing category or define a new one): ', $validate, false, null, $categories);
     } else {
         $validate($category);
     }
     $translationKey = Translate::findTranslationKeyForTranslation($category);
     if (!empty($translationKey)) {
         return $translationKey;
     }
     $category = ucfirst($category);
     return $category;
 }

作者:CaptainShar    项目:SSAD_Projec   
public function configureReportingMenu(MenuReporting $menu)
 {
     $idSite = $this->getIdSite();
     $goals = API::getInstance()->getGoals($idSite);
     $mainGoalMenu = 'Goals_Goals';
     if (count($goals) == 0) {
         $linkToAddNewGoal = $this->urlForAction('addNewGoal', array('idGoal' => null));
         $menu->addItem($mainGoalMenu, '', $linkToAddNewGoal, 25);
         $menu->addItem($mainGoalMenu, 'Goals_AddNewGoal', $linkToAddNewGoal, 1);
         return;
     }
     $order = 1;
     $url = $this->urlForAction('index', array('idGoal' => null));
     $menu->addItem($mainGoalMenu, '', $url, 25);
     $menu->addItem($mainGoalMenu, 'General_Overview', $url, ++$order);
     $group = new Group();
     foreach ($goals as $goal) {
         $subMenuName = str_replace('%', '%%', Translate::clean($goal['name']));
         $params = $this->urlForAction('goalReport', array('idGoal' => $goal['idgoal']));
         $tooltip = sprintf('%s (id = %d)', $subMenuName, $goal['idgoal']);
         if (count($goals) > 3) {
             $group->add($subMenuName, $params, $tooltip);
         } else {
             $menu->addItem($mainGoalMenu, $subMenuName, $params, ++$order, $tooltip);
         }
     }
     if (count($goals) > 3) {
         $menu->addGroup($mainGoalMenu, 'Goals_ChooseGoal', $group, ++$order, $tooltip = false);
     }
     $menu->addItem($mainGoalMenu, 'Goals_ManageGoals', $this->urlForAction('editGoals'), ++$order);
 }

作者:FluentDevelopmen    项目:piwi   
private function getEnglishTranslationForFeatureName($featureName)
 {
     if (Translate::getLanguageLoaded() == 'en') {
         return $featureName;
     }
     $translationKeyForFeature = Translate::findTranslationKeyForTranslation($featureName);
     return Piwik::translate($translationKeyForFeature, array(), 'en');
 }

作者:TensorWrenchOS    项目:piwi   
public function setUp()
 {
     parent::setUp();
     StaticCache::clearAll();
     PluginAwareStaticCache::clearAll();
     Translate::reloadLanguage('en');
     $this->api = API::getInstance();
 }

作者:normimu    项目:piwi   
public function setUp()
 {
     parent::setUp();
     for ($i = 1; $i <= $this->numSitesToCreate; $i++) {
         Fixture::createWebsite('2012-12-12 00:00:00', $ecommerce = 0, 'Site ' . $i);
     }
     Translate::loadAllTranslations();
     $this->dashboard = $this->getMockBuilder('Piwik\\Plugins\\MultiSites\\Dashboard')->setMethods(null)->disableOriginalConstructor()->getMock();
 }

作者:heiglandrea    项目:plugin-LoginLda   
public function setUp()
 {
     parent::setUp();
     $this->addNonLdapUsers();
     $this->addPreexistingLdapUser();
     $plugins = Config::getInstance()->Plugins;
     $plugins['Plugins'][] = 'LoginLdap';
     Config::getInstance()->Plugins = $plugins;
     $application = new Console(self::$fixture->piwikEnvironment);
     $application->setAutoExit(false);
     $this->applicationTester = new ApplicationTester($application);
     Translate::loadEnglishTranslation();
     // needed due to travis build that tests against minimum required piwik
 }

作者:TensorWrenchOS    项目:piwi   
public function setUp()
 {
     parent::setUp();
     $config = Config::getInstance();
     $config->clear();
     $config->setTestEnvironment();
     $section = Config::getInstance()->Tracker;
     $section['default_action_url'] = '/';
     $section['campaign_var_name'] = 'campaign_param_name,piwik_campaign,utm_campaign,test_campaign_name';
     $section['action_url_category_delimiter'] = '/';
     $section['campaign_keyword_var_name'] = 'piwik_kwd,utm_term,test_piwik_kwd';
     Config::getInstance()->Tracker = $section;
     PluginManager::getInstance()->loadPlugins(array('SitesManager'));
     Translate::loadEnglishTranslation();
 }

作者:KiwiJuice    项目:handball-dacha   
/**
  * Decodes all encoded entities in the given translations
  *
  * @param array $translations
  *
  * @return array   filtered translations
  */
 public function filter($translations)
 {
     foreach ($translations as $pluginName => $pluginTranslations) {
         foreach ($pluginTranslations as $key => $translation) {
             // remove encoded entities
             $decoded = Translate::clean($translation);
             if ($translation != $decoded) {
                 $this->filteredData[$pluginName][$key] = $translation;
                 $translations[$pluginName][$key] = $decoded;
                 continue;
             }
         }
     }
     return $translations;
 }

作者:a4tunad    项目:piwi   
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;
 }

作者:carriercom    项目:piwi   
/**
  * @param \Exception|null $exception
  */
 public function dispatch($exception = null)
 {
     if ($exception) {
         $message = $exception->getMessage();
     } else {
         $message = '';
     }
     Translate::loadCoreTranslation();
     $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;
 }

作者:FluentDevelopmen    项目:piwi   
public function testExecute_ShouldReturnLogAfterWorkingWithSomeData()
 {
     $result = $this->executeCommand('2010-01-03,2010-06-03');
     $this->assertContains('Re-attribution for date range: 2010-01-03 to 2010-06-03. 35 visits to process with provider "geoip_php".', $result);
     $this->assertRegExp('/100% processed. Time elapsed: [0-9.]+s/', $result);
     $queryParams = array('idSite' => self::$fixture->idSite, 'date' => self::$fixture->dateTime, 'period' => 'month');
     // we need to manually reload the translations since they get reset for some reason in IntegrationTestCase::tearDown();
     // if we do not load translations, a DataTable\Map containing multiple periods will contain only one DataTable having
     // the label `General_DateRangeFromTo` instead of many like `From 2010-01-04 to 2010-01-11`, ' `From 2010-01-11 to 2010-01-18`
     // As those data tables would all have the same prettyfied period label they would overwrite each other.
     Translate::loadAllTranslations();
     $this->assertApiResponseEqualsExpected("UserCountry.getCountry", $queryParams);
     $this->assertApiResponseEqualsExpected("UserCountry.getContinent", $queryParams);
     $this->assertApiResponseEqualsExpected("UserCountry.getRegion", $queryParams);
     $this->assertApiResponseEqualsExpected("UserCountry.getCity", $queryParams);
 }

作者:KiwiJuice    项目:handball-dacha   
/**
  * @param \Exception|null $exception
  */
 public function dispatch($exception = null)
 {
     if ($exception) {
         $message = $exception->getMessage();
     } else {
         $message = '';
     }
     Translate::loadCoreTranslation();
     $step = Common::getRequestVar('action', 'welcome', 'string');
     $controller = $this->getInstallationController();
     $isActionWhiteListed = in_array($step, array('saveLanguage', 'getBaseCss'));
     if (in_array($step, array_keys($controller->getInstallationSteps())) || $isActionWhiteListed) {
         echo FrontController::getInstance()->dispatch('Installation', $step, array($message));
     } else {
         Piwik::exitWithErrorMessage(Piwik::translate('Installation_NoConfigFound'));
     }
     exit;
 }

作者:TensorWrenchOS    项目:piwi   
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);
     });
 }

作者:jos    项目:CGE-File-Sharin   
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);
 }

作者:carriercom    项目:piwi   
public function configureReportingMenu(MenuReporting $menu)
 {
     $idSite = Common::getRequestVar('idSite', null, 'int');
     $goals = API::getInstance()->getGoals($idSite);
     $mainGoalMenu = $this->getGoalCategoryName($idSite);
     $site = new Site($idSite);
     if (count($goals) == 0) {
         $menu->add($mainGoalMenu, '', array('module' => 'Goals', 'action' => $site->isEcommerceEnabled() ? 'ecommerceReport' : 'addNewGoal', 'idGoal' => $site->isEcommerceEnabled() ? Piwik::LABEL_ID_GOAL_IS_ECOMMERCE_ORDER : null), true, 25);
         if ($site->isEcommerceEnabled()) {
             $menu->add($mainGoalMenu, 'Goals_Ecommerce', array('module' => 'Goals', 'action' => 'ecommerceReport', 'idGoal' => Piwik::LABEL_ID_GOAL_IS_ECOMMERCE_ORDER), true, 1);
         }
         $menu->add($mainGoalMenu, 'Goals_AddNewGoal', array('module' => 'Goals', 'action' => 'addNewGoal'));
     } else {
         $menu->add($mainGoalMenu, '', array('module' => 'Goals', 'action' => $site->isEcommerceEnabled() ? 'ecommerceReport' : 'index', 'idGoal' => $site->isEcommerceEnabled() ? Piwik::LABEL_ID_GOAL_IS_ECOMMERCE_ORDER : null), true, 25);
         if ($site->isEcommerceEnabled()) {
             $menu->add($mainGoalMenu, 'Goals_Ecommerce', array('module' => 'Goals', 'action' => 'ecommerceReport', 'idGoal' => Piwik::LABEL_ID_GOAL_IS_ECOMMERCE_ORDER), true, 1);
         }
         $menu->add($mainGoalMenu, 'Goals_GoalsOverview', array('module' => 'Goals', 'action' => 'index'), true, 2);
         foreach ($goals as $goal) {
             $menu->add($mainGoalMenu, str_replace('%', '%%', Translate::clean($goal['name'])), array('module' => 'Goals', 'action' => 'goalReport', 'idGoal' => $goal['idgoal']));
         }
     }
 }


问题


面经


文章

微信
公众号

扫码关注公众号