/** * Loads the page. */ public function loadPage() { $this->translator->load(APPLICATION_PATH . '/modules/' . $this->request->getModuleName() . '/translations'); if ($this->request->isAdmin()) { $this->translator->load(APPLICATION_PATH . '/modules/admin/translations'); } $controller = $this->loadController(); $controllerName = $this->request->getControllerName(); $findSub = strpos($controllerName, '_'); $dir = ''; if ($findSub !== false) { $controllerParts = explode('_', $this->request->getControllerName()); $controllerName = $controllerParts[1]; $dir = ucfirst($controllerParts[0]) . '\\'; } $this->plugin->addPluginData('controller', $controller); $this->plugin->execute('AfterControllerLoad'); if ($this->request->isAdmin()) { $viewOutput = $this->view->loadScript(APPLICATION_PATH . '/modules/' . $this->request->getModuleName() . '/views/admin/' . $dir . $controllerName . '/' . $this->request->getActionName() . '.php'); } else { $viewPath = APPLICATION_PATH . '/' . dirname($controller->getLayout()->getFile()) . '/views/modules/' . $this->request->getModuleName() . '/' . $dir . $controllerName . '/' . $this->request->getActionName() . '.php'; if (!file_exists($viewPath)) { $viewPath = APPLICATION_PATH . '/modules/' . $this->request->getModuleName() . '/views/' . $dir . $controllerName . '/' . $this->request->getActionName() . '.php'; } $viewOutput = $this->view->loadScript($viewPath); } if (!empty($viewOutput)) { $controller->getLayout()->setContent($viewOutput); } if ($this->request->isAjax()) { echo $viewOutput; } elseif ($controller->getLayout()->getDisabled() === false) { if ($controller->getLayout()->getFile() != '') { $this->layout->loadScript(APPLICATION_PATH . '/' . $controller->getLayout()->getFile() . '.php'); } } }
/** * Defines the start page. * * @param string $startPage * @param \Ilch\Translator $translator * @return null */ public function defineStartPage($startPage, $translator) { if (!empty($this->query)) { return; } $config = \Ilch\Registry::get('config'); $locale = ''; if ((bool) $config->get('multilingual_acp')) { if ($translator->getLocale() != $config->get('content_language')) { $locale = $translator->getLocale(); } } if (strpos($startPage, 'module_') !== false) { $this->request->setModuleName(str_replace('module_', '', $startPage)); $this->request->setControllerName('index'); $this->request->setActionName('index'); } elseif (strpos($startPage, 'page_') !== false) { $this->request->setModuleName('page'); $this->request->setControllerName('index'); $this->request->setActionName('show'); $this->request->setParam('id', str_replace('page_', '', $startPage)); $this->request->setParam('locale', $locale); } elseif (strpos($startPage, 'layouts_') !== false) { $this->request->setModuleName(str_replace('layouts_', '', $startPage)); $this->request->setControllerName('index'); } else { $this->request->setModuleName(DEFAULT_MODULE); $this->request->setControllerName('index'); $this->request->setActionName('index'); } }
/** * Generating all the error messages * @param Object \Ilch\Translator $translator The translator instance * @returns Array An array with translated error messages */ public function getErrors(\Ilch\Translator $translator) { if (empty($this->errors)) { return null; } $errorMessages = []; $validationErrors = []; foreach ($this->errors as $errors) { if (!$this->breakChain) { foreach ($errors as $error) { $validationErrors[] = $error; } } else { $validationErrors[] = $errors; } } foreach ($validationErrors as $error) { $params = []; foreach ($error->getParams() as $param) { if ($param['translate'] === true) { $params[] = $translator->trans($param['value']); } else { $params[] = $param['value']; } } $field = isset(self::$customFieldAliases[$error->getField()]) ? self::$customFieldAliases[$error->getField()] : $error->getField(); $args = [$error->getKey(), $translator->trans($field)]; $args = array_merge($args, $params); $errorMessages[] = call_user_func_array([$translator, 'trans'], $args); } return $errorMessages; }
/** * Tests if the locale gets trimmed correctly to a shorter version. */ public function testShortenLocale() { $translator = new Translator(); $this->assertEquals('en', $translator->shortenLocale('en_EN'), 'The locale wasn\'t trimmed correctly.'); }