Translates the given string.
public translate ( string $message, integer $count = NULL, array $parameters = [], string $domain = NULL, string $locale = NULL ) : string | ||
$message | string | The message id |
$count | integer | The number to use to find the indice of the message |
$parameters | array | An array of parameters for the message |
$domain | string | The domain for the message |
$locale | string | The locale |
return | string |
/** * @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 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; }
public function requireLogin() { if (!$this->user->isLoggedIn()) { $this->flashMessage($this->translator->translate('main.action_require_login'), 'warning'); $this->redirect('Sign:in', ['backlink' => $this->storeRequest()]); } }
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 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; }
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')); } }
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; }
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); }
/** * 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 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; }
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); }
/** * @return Form */ public function create() { $form = new Form(); $form->addText('username', $this->translator->translate('messages.app.username') . ':')->setRequired($this->translator->translate('messages.app.usernameRequired')); $form->addPassword('password', $this->translator->translate('messages.app.password') . ':')->setRequired($this->translator->translate('messages.app.passwordRequired')); $form->addSubmit('send', $this->translator->translate('messages.app.login')); $form->onSuccess[] = array($this, 'formSucceeded'); return $form; }
/** * @param $date * @return string */ public function relativeDate($date) { if (is_int($date)) { $date = Nette\Utils\DateTime::from($date); } $diff = $date->diff(new Nette\Utils\DateTime()); if ($diff->y > 0) { return $this->translator->translate('latteHelpers.relativeDate.xYearsAgo', min(2, $diff->y), ['years' => $diff->y]); } if ($diff->m > 0) { return $this->translator->translate('latteHelpers.relativeDate.xMonthsAgo', min(2, $diff->m), ['months' => $diff->m]); } if ($diff->d > 0) { return $this->translator->translate('latteHelpers.relativeDate.xDaysAgo', min(2, $diff->d), ['days' => $diff->d]); } if ($diff->h > 0) { return $this->translator->translate('latteHelpers.relativeDate.xHoursAgo', min(2, $diff->h), ['hours' => $diff->h]); } if ($diff->i > 0) { return $this->translator->translate('latteHelpers.relativeDate.xMinutesAgo', min(2, $diff->i), ['minutes' => $diff->i]); } return $this->translator->translate('latteHelpers.relativeDate.fewSecondsAgo'); }
private function pageSaving(\Nette\Forms\Form $form, $isDraft) { if (!$this->authorizator->isAllowed($this->user, 'page', 'create') or !$this->authorizator->isAllowed($this->user, 'page', 'edit')) { $this->flashMessage('authorization.noPermission', FlashMessage::WARNING); return; } $values = $form->getValues(true); $values['saveAsDraft'] = (bool) $isDraft; $values['author'] = $this->user; $tags = $form->getHttpData(Form::DATA_TEXT, 'tags[]'); $values['tags'] = $tags; try { $page = $this->pageFacade->save($values, $this->page); $this->flashMessage('pageEditForm.messages.success' . ($values['saveAsDraft'] ? 'Draft' : 'Publish'), FlashMessage::SUCCESS); $this->onSuccessPageSaving($this, $page); } catch (PagePublicationTimeMissingException $ptm) { $form->addError($this->translator->translate('pageEditForm.messages.missingPublicationTime')); return; } catch (PagePublicationTimeException $pt) { $form->addError($this->translator->translate('pageEditForm.messages.publishedPageInvalidPublicationTime')); return; } catch (PageIntroHtmlLengthException $pi) { $form->addError($this->translator->translate('pageEditForm.messages.pageIntroHtmlLength')); return; } catch (PageTitleAlreadyExistsException $at) { $form->addError($this->translator->translate('pageEditForm.messages.titleExists')); return; } catch (UrlAlreadyExistsException $ur) { $form['url']->setValue(Strings::webalize($values['title'], '/')); $form->addError($this->translator->translate('pageEditForm.messages.urlExists')); return; } catch (DBALException $e) { $form->addError($this->translator->translate('pageEditForm.messages.savingError')); return; } }
public function timeAgoInWords($time, $locale = null) { $t = \Helpers::timeAgoInWords($time); return $this->translator->translate('timeAgoInWords.' . $t[0], isset($t['time']) ? $t['time'] : null, [], null, $locale); }
/** * @param $message * @param null $count * @param array $parameters * @param null $domain * @param null $locale * @return string */ protected function t($message, $count = NULL, $parameters = [], $domain = NULL, $locale = NULL) { return $this->translator->translate($message, $count, $parameters, $domain, $locale); }
/** * @param $message * @param null $count * @param array $parameters * @param null $domain * @param null $locale * @return string */ public function t($message, $count = NULL, $parameters = array(), $domain = NULL, $locale = NULL) { return $this->translator->translate($message, $count, $parameters, $domain, $locale); }
private function translateFlash($message, $count = NULL, $params = []) { return $this->t->translate($message, $count, $params); }
/** * @param string $title * @param string $subtitle * @return BasePresenter */ protected function title($title, $subtitle = null) { $this->template->title = $this->translator->translate($title); $this->template->subtitle = $this->translator->translate($subtitle); return $this; }