/** * @param Translator $translator * @param MessageCatalogueInterface[] $availableCatalogues * @param string $locale * @throws InvalidArgumentException * @return MessageCatalogueInterface|NULL */ public function compile(Translator $translator, array &$availableCatalogues, $locale) { if (empty($locale)) { throw new InvalidArgumentException("Invalid locale."); } if (isset($availableCatalogues[$locale])) { return $availableCatalogues; } $cacheKey = array($locale, $translator->getFallbackLocales()); $storage = $this->cache->getStorage(); if (!$storage instanceof Kdyby\Translation\Caching\PhpFileStorage) { if (($messages = $this->cache->load($cacheKey)) !== NULL) { $availableCatalogues[$locale] = new MessageCatalogue($locale, $messages); return $availableCatalogues; } $this->catalogueFactory->createCatalogue($translator, $availableCatalogues, $locale); $this->cache->save($cacheKey, $availableCatalogues[$locale]->all()); return $availableCatalogues; } $storage->hint = $locale; $cached = $compiled = $this->cache->load($cacheKey); if ($compiled === NULL) { $this->catalogueFactory->createCatalogue($translator, $availableCatalogues, $locale); $this->cache->save($cacheKey, $compiled = $this->compilePhpCache($translator, $availableCatalogues, $locale)); $cached = $this->cache->load($cacheKey); } $availableCatalogues[$locale] = self::load($cached['file']); return $availableCatalogues; }
/** * @param \Kdyby\Translation\Translator $translator * @return string|NULL */ public function resolve(Kdyby\Translation\Translator $translator) { $short = array_map(function ($locale) { return substr($locale, 0, 2); }, $translator->getAvailableLocales()); return $this->httpRequest->detectLanguage($short) ?: NULL; }
protected function startup() { parent::startup(); // Login check if ($this->getName() != 'Admin:Sign') { $role = $this->user->getRoles(); $roleCheck = $this->database->table("users_roles")->get($role[0]); if ($roleCheck->admin_access == 0) { $this->flashMessage($this->translator->translate('messages.sign.invalidLogin'), "error"); $this->redirect(':Admin:Sign:in'); } if ($this->user->isLoggedIn()) { } else { if ($this->user->logoutReason === Nette\Security\IUserStorage::INACTIVITY) { $this->flashMessage($this->translator->translate('messages.sign.youWereLoggedIn'), "note"); } $this->redirect('Sign:in', array('backlink' => $this->storeRequest())); } } if ($this->user->isLoggedIn()) { $this->template->isLoggedIn = TRUE; $this->template->member = $this->database->table("users")->get($this->user->getId()); } // Set values from db $this->template->settings = $this->database->table("settings")->fetchPairs("setkey", "setvalue"); $this->template->appDir = APP_DIR; $this->template->signed = TRUE; $this->template->langSelected = $this->translator->getLocale(); // Set language from cookie if ($this->context->httpRequest->getCookie('language_admin') == '') { $this->translator->setLocale($this->translator->getDefaultLocale()); } else { $this->translator->setLocale($this->context->httpRequest->getCookie('language_admin')); } }
public function createComponent($pres, $name) { // $cache = $this->getEntityCache(); // $data = $cache->load(self::MENU_CONTROL); // if ($data === null) { $c = new MenuControl($pres, $name); $c->setLabel($this->translator->translate("system.categoryMenu.label")); $gs = $this->getGroups(); $tmp = array_filter($gs, function ($e) { if ($e->getParent() == null) { return true; } return false; }); $tmp = $tmp[0]; $rootNode = $c->addNode($tmp->getName(), $pres->link($this->linkModuleHelper($pres), $tmp->getAbbr()), FALSE, array(), $tmp->getAbbr()); if ($pres->getParam('abbr') === null && $tmp->getAbbr() == $pres::ROOT_GROUP) { $c->setCurrentNode($rootNode); } $this->iterateChildren($tmp, $rootNode, $pres, $c); // $data = $c; // $opts = [Cache::TAGS=>[self::MENU_CONTROL, self::ENTITY_COLLECTION]]; // $cache->save(self::MENU_CONTROL, $data, $opts); // } return $c; }
/** * @param \Nette\Forms\Container $container * @param ConstraintViolationList|ConstraintViolationInterface[] $violations */ public function mapViolationsToForm(Container $container, ConstraintViolationList $violations) { foreach ($violations as $violation) { $control = $this->findControl($container, $violation); $control->addError($this->translator->translate($violation->getMessageTemplate(), $violation->getMessagePluralization(), $violation->getMessageParameters(), 'validators')); } }
public function requireLogin() { if (!$this->user->isLoggedIn()) { $this->flashMessage($this->translator->translate('main.action_require_login'), 'warning'); $this->redirect('Sign:in', ['backlink' => $this->storeRequest()]); } }
public function getLocale() { $languages = $this->translator->getAvailableLocales(); foreach ($languages as $itemL) { $result = explode("_", $itemL); $iLocale[] = $result[0]; } return $iLocale; }
protected function createComponentFilter() { $form = new Form(); $form->setTranslator($this->translator->domain('tags.filter.form')); $form->getElementPrototype()->class = 'ajax'; $form->addText('name', 'name.label')->setDefaultValue($this->name); $form->addSubmit('filter', 'filter.label')->onClick[] = [$this, 'filterTags']; $form->addSubmit('reset', 'reset.label')->onClick[] = [$this, 'filterReset']; return $form; }
public function translate(Translator $translator, $count = NULL, array $parameters = array(), $domain = NULL, $locale = NULL) { if (!is_string($this->message)) { throw new InvalidStateException("Message is not a string, type " . gettype($this->message) . ' given.'); } $count = $count !== NULL ? $count : $this->count; $parameters = !empty($parameters) ? $parameters : $this->parameters; $domain = $domain !== NULL ? $domain : $this->domain; $locale = $locale !== NULL ? $locale : $this->locale; return $translator->translate($this->message, $count, (array) $parameters, $domain, $locale); }
public function startup() { parent::startup(); if (!$this->user->loggedIn) { $this->redirect("Sign:in", ["backlink" => $this->storeRequest()]); } $this->translator->setLocale("en"); if ($this->getParameter("no_layout", false)) { $this->setLayout(false); } }
public function sortCollectionByLocales(Nextras\Orm\Mapper\Dbal\DbalCollection $collection, string $column) : Nextras\Orm\Mapper\Dbal\DbalCollection { $builder = $collection->getQueryBuilder(); foreach ([$this->translator->getLocale(), $this->translator->getDefaultLocale()] as $locale) { $separator = strpos($locale, '_'); $subLocales = $separator === FALSE ? [$locale] : [$locale, substr($locale, 0, $separator)]; foreach ($subLocales as $subLocale) { $builder->addOrderBy(implode('=', [$column, '%s']) . ' DESC', $subLocale); } } return $collection; }
protected function createComponentForm() { $form = new Form(); $form->setTranslator($this->translator->domain('users.roleRemoval.actions')); $form->addSubmit('remove', 'remove')->onClick[] = [$this, 'removeRole']; if (!$this->authorizator->isAllowed($this->user, 'user_role', 'remove')) { $form['remove']->setDisabled(); } $form->addSubmit('cancel', 'cancel')->onClick[] = [$this, 'cancel']; $form->addProtection(); return $form; }
public function dump() { $allMessages = []; $locales = $this->translator->getAvailableLocales(); foreach ($locales as $locale) { $catalogue = $this->translator->getCatalogue($locale); $messages = $catalogue->all(); $shortLocale = $this->getShortLocale($locale); $allMessages[$shortLocale] = $messages; } return Json::encode($allMessages, Json::PRETTY); }
public function render() { $template = $this->getTemplate(); $template->setFile(__DIR__ . '/page.latte'); $template->page = $this->page; $template->isOnlyIntroShown = $this->isOnlyIntroShown; $template->commentsCount = $this->commentsCount; $template->translate = function ($string, $count = null) { return $this->translator->translate($string, $count, [], null, $this->page->getLocaleCode()); }; $template->render(); }
protected function createComponentNewRoleForm() { $form = new Form(); $form->setTranslator($this->translator->domain('users.newRole.form')); $form->addText('name', 'name.label', null, Role::LENGTH_NAME)->setRequired('name.messages.required'); $form->addSelect('parent', $this->translator->translate('users.newRole.form.parent.label'))->setTranslator(null)->setPrompt($this->translator->translate('users.newRole.form.parent.prompt'))->setItems($this->prepareRolesForSelect($this->userFacade->findRolesThatAreNotParents())); $form->addSubmit('save', 'save.caption'); if (!$this->authorizator->isAllowed($this->user, 'user_role', 'create')) { $form['save']->setDisabled(); } $form->onSuccess[] = [$this, 'processNewRole']; return $form; }
protected function createComponentRemovalForm() { $form = new Form(); $form->setTranslator($this->translator->domain('pageRemoval')); $form->addText('check', 'check.label')->setRequired('check.messages.required')->addRule(Form::EQUAL, 'check.messages.notEqual', $this->page->getTitle()); $form->addSubmit('remove', 'remove.caption')->onClick[] = [$this, 'removePage']; $form->addSubmit('cancel', 'cancel.caption')->setValidationScope([])->onClick[] = [$this, 'cancelClick']; if (!$this->authorizator->isAllowed($this->user, 'page', 'remove')) { $form['remove']->setDisabled(); } $form->addProtection(); return $form; }
public function processForm(Form $form, $values) { if (!$this->authorizator->isAllowed($this->user, 'options', 'edit')) { $this->flashMessage('authorization.noPermission', FlashMessage::WARNING); $this->redirect('this'); } try { $this->optionFacade->saveOptions((array) $values); $this->flashMessage('options.form.messages.success', FlashMessage::SUCCESS); $this->redirect('this'); } catch (DBALException $e) { $form->addError($this->translator->translate('options.form.messages.savingError')); } }
/** * @param Application $sender * @param Request $request */ public function onRequest(Application $sender, Request $request) { $params = $request->getParameters(); if ($request->getMethod() === Request::FORWARD && empty($params['locale'])) { return; } $this->request = $request; if (!$this->translator) { return; } $this->translator->setLocale(NULL); $this->translator->getLocale(); // invoke resolver }
public function processForm(Form $form, $values) { if ($this->page->getAllowedComments() === false and !$this->authorizator->isAllowed($this->user, 'page_comment_form', 'comment_on_closed')) { $this->flashMessage('page.comments.form.messages.closedComments', FlashMessage::WARNING); $this->redirect('this#comments'); } $values['page'] = $this->page; try { $comment = $this->commentFacade->save((array) $values); $this->flashMessage('page.comments.form.messages.success', FlashMessage::SUCCESS); $this->redirect('this#comment-' . $comment->getId()); } catch (ActionFailedException $e) { $form->addError($this->translator->translate('page.comments.form.messages.error')); } }
/** * @param User|null $user * @return Form */ public function create(User $user = null) { $form = new Form(); $form->setTranslator($this->translator->domain('users.user.form')); $form->addText('username', 'username.label')->setRequired('username.messages.required'); $form->addText('email', 'email.label')->setRequired('email.messages.required'); $form->addText('first_name', 'first_name.label'); $form->addText('last_name', 'last_name.label'); $form->addSelect('role', $this->translator->translate('users.user.form.role.label'), $this->prepareRolesForSelect())->setTranslator(null); $form->addSubmit('save', 'save.caption'); if ($user !== null) { $this->fillForm($form, $user); } return $form; }
/** * * @param string|NULL $class * @return Nette\Application\UI\ITemplate */ protected function createTemplate($class = NULL) { $template = parent::createTemplate($class); $template->_gravatar = $this->gravatar; $this->translator->createTemplateHelpers()->register($template->getLatte()); return $template; }
/** * Get event * @param integer $eventId * @return Event */ public function getEvent($eventId) { // Má právo na editaci? (výchozí: ano) $canAccess = FALSE; $hasAccess = FALSE; $hasShare = FALSE; /** @var null|Event $event */ $event = $this->eventDao->find($eventId); if ($event->isDeleted()) { throw new Nette\Application\BadRequestException($this->translator->translate('event.general.noId')); } // Is this api call? if ($this->user->getId() === 0) { $canAccess = TRUE; } else { /** @var \App\Model\Entity\User $userEntity */ $userEntity = $this->em->getDao('\\App\\Model\\Entity\\User')->find($this->user->getId()); /** @var \App\Model\Entity\Client $client */ $client = $userEntity->getClient(); // je uživatel ADMIN? if (($this->user->isInRole('ADMIN') || $this->user->isInRole('ACCOUNTANT')) && $this->isClientsEvent($event, $client)) { $canAccess = TRUE; } elseif (($this->user->isInRole('USER') || $this->user->isInRole('ACCOUNTANT')) && $this->isClientsEvent($event, $client)) { //požadavek klienta, aby šel $canAccess = TRUE; } else { // pokud nemá přiřazené oprávnění, má přidělené sdílení? if ($event->getShares() !== NULL) { $hasShare = FALSE; foreach ($event->getShares() as $clientShare) { if ($client->getId() == $clientShare->getClient()->getId()) { $hasShare = TRUE; break; } } } // pokud ano, má přiřazená oprávnění pro event? if ($event->getAccesses() !== NULL) { foreach ($event->getAccesses() as $clientAccess) { $hasAccess = FALSE; if ($client->getId() == $clientAccess->getReceiver()->getId() || $client->getId() == $clientAccess->getCreator()->getId()) { $hasAccess = TRUE; break; } } } // pokud ne, patří událost klientovi nebo sdílení, anebo přístup? if ($hasAccess || $hasShare) { $canAccess = TRUE; } } } if ($canAccess) { // má přístup do události? return $event; } else { // jinak je přesměrován na dashboard s tím, že je upozorněn na to, že nemá oprávnění throw new Nette\Application\ForbiddenRequestException($this->translator->translate('event.general.noRights')); } }
/** * */ protected function startup() { parent::startup(); if (!$this->getUser()->isLoggedIn()) { if ($this->getUser()->logoutReason === User::INACTIVITY) { $this->flashMessage($this->translator->translate('messages.msg.inactive')); } else { $this->flashMessage($this->translator->translate('messages.msg.please_login')); } $this->redirect(':Front:Sign:in', ['backlink' => $this->storeRequest()]); } if (!$this->getUser()->isInRole('admin')) { $this->flashMessage($this->translator->translate('messages.msg.not_allowed')); $this->redirect(':Front:Sign:in', ['backlink' => $this->storeRequest()]); } }
public function translate($message, $count = NULL, $parameters = [], $domain = NULL, $locale = NULL) : string { if ($message instanceof Nextras\Orm\Entity\IEntity) { return $message; } return parent::translate($message, $count, $parameters, $domain, $locale); }
/** * @param Translator $translator * @return string|NULL */ public function resolve(Translator $translator) { if (!$this->session->isStarted() && $this->httpResponse->isSent()) { trigger_error("The advice of session locale resolver is required but the session has not been started and headers had been already sent. " . "Either start your sessions earlier or disabled the SessionResolver.", E_USER_WARNING); return NULL; } if (empty($this->localeSession->locale)) { return NULL; } $short = array_map(function ($locale) { return substr($locale, 0, 2); }, $translator->getAvailableLocales()); if (!in_array(substr($this->localeSession->locale, 0, 2), $short, TRUE)) { return NULL; } return $this->localeSession->locale; }
public function processNewTag(Form $form, $values) { if (!$this->authorizator->isAllowed($this->user, 'page_tag', 'create')) { $this->flashMessage('authorization.noPermission', FlashMessage::WARNING); return; } try { $tag = $this->tagFacade->saveTag((array) $values); $this->onSuccessTagSaving($tag, $this); } catch (TagNameAlreadyExistsException $t) { $form->addError($this->translator->translate('tags.tagForm.messages.nameExists', ['name' => $values['name']])); } catch (UrlAlreadyExistsException $url) { $form->addError($this->translator->translate('tags.tagForm.messages.tagUrlExists')); } catch (DBALException $e) { $form->addError($this->translator->translate('tags.tagForm.messages.savingError')); } }
public function notifyNewPassword(User $u) { $subjKey = "systemModule.notification.newPassword.subject"; $bodyKey = "systemModule.notification.newPassword.body"; $subject = $this->translator->translate($subjKey, null, ["host" => $this->getHostName()]); $body = $this->translator->translate($bodyKey, null, ["name" => $u->getName(), "surname" => $u->getSurname(), "pass" => $u->provideRawPassword()]); $mail = new Message(); $mail->setFrom($this->getSenderEmail())->setSubject($subject)->setBody($body)->addTo($u->getContact()->getEmail()); $this->send($mail); }
/** * Sestaveni formulare * @return \App\Form\BaseForm */ public function create() { $form = new \App\Form\BaseForm(); $form->setTranslator($this->translator); $form->addGroup('')->setOption('container', Html::el('fieldset', 'class="has-help"')); $form->addText('name', 'event.description.name')->setRequired('event.description.nameRequired')->addRule(Form::FILLED, 'event.description.nameFilled')->setOption('description', Html::el('p', $this->translator->translate('event.description.nameDescription'))->addAttributes(array('id' => 'event-name-desc'))); $form->addAddressInput('address', 'event.description.address')->setRequired('event.description.addressRequired')->addRule(Form::FILLED, 'event.description.addressFilled'); $form->addDateTimeRange('dateTimeRange', 'event.description.dateTimeRange')->addRule(Form::FILLED, 'event.description.dateFromFilled'); $form->addImageUpload('logo', 'event.description.logo')->addCondition(Form::FILLED)->addRule(Form::IMAGE, 'event.description.logoImage'); $form->addTextArea('description', 'event.description.description')->setRequired('event.description.descriptionRequired')->addRule(Form::FILLED, 'event.description.descriptionFilled'); $form->addSelect('eventType', 'event.description.eventType', $this->eventService->selectboxes['eventType'])->setRequired('event.description.eventTypeRequired')->setPrompt('event.description.eventTypePrompt'); $form->addSelect('eventCategory', 'event.description.eventCategory', Event::getCategories())->setRequired('event.description.eventCategoryRequired')->setPrompt('event.description.eventCategoryPrompt'); $form->addText('organizer', 'event.description.organizer')->setRequired('event.description.organizerRequired')->addRule(Form::FILLED, 'event.description.organizerFilled'); $form->addTextArea('organizerDescription', 'event.description.organizerDescription')->setRequired('event.description.organizerDescriptionRequired')->addRule(Form::FILLED, 'event.description.organizerDescriptionFilled'); $form->addHidden('id'); $form->addSubmit('save', 'event.description.saveChanges'); $form->addSubmit('notSave', 'event.description.cancelChanges')->setAttribute('type', 'reset'); return $form; }
protected function createTemplate($class = NULL) { $template = parent::createTemplate($class); $template->registerHelperLoader(callback($this->translator->createTemplateHelpers(), 'loader')); $context = $this->context; $template->registerHelper('thumb', function ($identifier, $type, $size = '') use($context) { $service = $context->getService($type . "ImageService"); return \Tomaj\Image\Helper\Image::thumb($service, $identifier, $size); }); $template->locale = $this->getTranslator()->getLocale(); return $template; }
public function compute(Translator $translator, $locale) { $locales = array(); foreach ($this->fallbackLocales as $fallback) { if ($fallback === $locale) { continue; } $locales[] = $fallback; } if (strrchr($locale, '_') !== false) { array_unshift($locales, substr($locale, 0, -strlen(strrchr($locale, '_')))); } foreach ($translator->getAvailableLocales() as $available) { if ($available === $locale) { continue; } if (substr($available, 0, 2) === substr($locale, 0, 2)) { array_unshift($locales, $available); break; } } return array_unique($locales); }