本文整理汇总了PHP中Symfony\Bundle\FrameworkBundle\Translation\Translator::trans方法的典型用法代码示例。如果您正苦于以下问题:PHP Translator::trans方法的具体用法?PHP Translator::trans怎么用?PHP Translator::trans使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Bundle\FrameworkBundle\Translation\Translator
的用法示例。
在下文中一共展示了Translator::trans方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: createBreadcrumbsMenu
/**
* Breadcrumbs
*
* @param Request $request
*
* @return mixed
*/
public function createBreadcrumbsMenu(Request $request)
{
$menu = $this->factory->createItem('root');
$menu->setUri($request->getRequestUri());
$menu->addChild($this->translator->trans('Главная'), array('route' => 'homepage'));
return $menu;
}
示例2: onKernelRequest
public function onKernelRequest(GetResponseEvent $event)
{
if ($event->getRequestType() !== HttpKernelInterface::MASTER_REQUEST) {
return;
}
$request = $event->getRequest();
$fc_form = $this->form_service->guessFcForm($request);
if (!$fc_form instanceof FcForm) {
return;
}
if ($fc_form->getAction()) {
return;
}
/** @var FormInterface $form */
$form = $this->form_service->create($fc_form);
$form->handleRequest($request);
if ($form->isValid()) {
$data = $form->getData();
$this->form_service->clear($fc_form, array('template' => $data['_template'], 'data' => $this->form_service->initData($data)));
if ($fc_form->getIsAjax()) {
return;
}
if ($fc_form->getMessage()) {
$message = $fc_form->getMessage();
} else {
$message = $this->translator->trans('fc.message.form.is_valid', array(), 'FenrizbesFormConstructorBundle');
}
// TODO: Связывать сообщение с конкретной формой и подчищать старые
$this->session->getFlashBag()->add('fc_form.success', $message);
$response = new RedirectResponse($this->router->generate($request->get('_route'), $request->get('_route_params')));
$event->setResponse($response);
}
}
示例3: buildForm
/**
* {@inheritdoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->addEventSubscriber(new CleanFormSubscriber());
$builder->addEventSubscriber(new FormExitSubscriber('user.user', $options));
$builder->add('username', 'text', array('label' => 'mautic.core.username', 'label_attr' => array('class' => 'control-label'), 'attr' => array('class' => 'form-control', 'preaddon' => 'fa fa-user', 'autocomplete' => 'off')));
$builder->add('firstName', 'text', array('label' => 'mautic.core.firstname', 'label_attr' => array('class' => 'control-label'), 'attr' => array('class' => 'form-control')));
$builder->add('lastName', 'text', array('label' => 'mautic.core.lastname', 'label_attr' => array('class' => 'control-label'), 'attr' => array('class' => 'form-control')));
$positions = $this->model->getLookupResults('position', null, 0, true);
$builder->add('position', 'text', array('label' => 'mautic.core.position', 'label_attr' => array('class' => 'control-label'), 'attr' => array('class' => 'form-control', 'data-options' => json_encode($positions)), 'required' => false));
$builder->add('email', 'email', array('label' => 'mautic.core.type.email', 'label_attr' => array('class' => 'control-label'), 'attr' => array('class' => 'form-control', 'preaddon' => 'fa fa-envelope')));
$existing = !empty($options['data']) && $options['data']->getId();
$placeholder = $existing ? $this->translator->trans('mautic.user.user.form.passwordplaceholder') : '';
$required = $existing ? false : true;
$builder->add('plainPassword', 'repeated', array('first_name' => 'password', 'first_options' => array('label' => 'mautic.core.password', 'label_attr' => array('class' => 'control-label'), 'attr' => array('class' => 'form-control', 'placeholder' => $placeholder, 'tooltip' => 'mautic.user.user.form.help.passwordrequirements', 'preaddon' => 'fa fa-lock', 'autocomplete' => 'off'), 'required' => $required, 'error_bubbling' => false), 'second_name' => 'confirm', 'second_options' => array('label' => 'mautic.user.user.form.passwordconfirm', 'label_attr' => array('class' => 'control-label'), 'attr' => array('class' => 'form-control', 'placeholder' => $placeholder, 'tooltip' => 'mautic.user.user.form.help.passwordrequirements', 'preaddon' => 'fa fa-lock', 'autocomplete' => 'off'), 'required' => $required, 'error_bubbling' => false), 'type' => 'password', 'invalid_message' => 'mautic.user.user.password.mismatch', 'required' => $required, 'error_bubbling' => false));
$builder->add('timezone', 'timezone', array('label' => 'mautic.core.timezone', 'label_attr' => array('class' => 'control-label'), 'attr' => array('class' => 'form-control'), 'multiple' => false, 'empty_value' => 'mautic.user.user.form.defaulttimezone'));
$builder->add('locale', 'choice', array('choices' => $this->supportedLanguages, 'label' => 'mautic.core.language', 'label_attr' => array('class' => 'control-label'), 'attr' => array('class' => 'form-control'), 'multiple' => false, 'empty_value' => 'mautic.user.user.form.defaultlocale'));
if (empty($options['in_profile'])) {
$builder->add($builder->create('role', 'entity', array('label' => 'mautic.user.role', 'label_attr' => array('class' => 'control-label'), 'attr' => array('class' => 'form-control'), 'class' => 'MauticUserBundle:Role', 'property' => 'name', 'query_builder' => function (EntityRepository $er) {
return $er->createQueryBuilder('r')->where('r.isPublished = true')->orderBy('r.name', 'ASC');
})));
$builder->add('isPublished', 'yesno_button_group');
$builder->add('buttons', 'form_buttons');
} else {
$builder->add('buttons', 'form_buttons', array('save_text' => 'mautic.core.form.apply', 'apply_text' => false));
}
if (!empty($options["action"])) {
$builder->setAction($options["action"]);
}
}
示例4: buildForm
/**
* {@inheritdoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
// Build a list of columns
$builder->add('column', 'choice', array('choices' => $options['columnList'], 'expanded' => false, 'multiple' => false, 'label' => 'mautic.report.report.label.filtercolumn', 'label_attr' => array('class' => 'control-label'), 'empty_value' => false, 'required' => false, 'attr' => array('class' => 'form-control filter-columns')));
// Direction
$builder->add('direction', 'choice', array('choices' => array('ASC' => $this->translator->trans('mautic.report.report.label.tableorder_dir.asc'), 'DESC' => $this->translator->trans('mautic.report.report.label.tableorder_dir.desc')), 'expanded' => false, 'multiple' => false, 'label' => 'mautic.core.order', 'label_attr' => array('class' => 'control-label'), 'empty_value' => false, 'required' => false, 'attr' => array('class' => 'form-control not-chosen')));
}
示例5: returnAjaxError
/**
* Permet de retourner une erreur ajax avec le bon message en fonction du code erreur envoyé
* @param $errorCode
* @param string $notificationType
* @param null $infos
* @param null $specificMessage
* @return Response
*/
public function returnAjaxError($errorCode, $notificationType = 'error', $infos = null, $specificMessage = null)
{
switch ($errorCode) {
case 103:
$message = 'La recherche est vide';
break;
case 130:
case 131:
case 132:
$message = 'Vous n\'êtes pas autorisé à accéder à cette page (seulement ROLE_SUPER_ADMIN)';
break;
case 200:
$message = 'Tout a fonctionné correctement';
break;
default:
$message = $this->translator->trans('bo.global.errorProcessing', array(), 'messages');
break;
}
$message .= ' - ' . $errorCode;
if (null !== $infos) {
$message .= ' (' . $infos . ')';
}
if (null !== $specificMessage) {
$message = $specificMessage;
}
$return = json_encode(array('responseCode' => $errorCode, 'message' => $message, 'notification' => $notificationType));
return new Response($return, 200, array('Content-Type' => 'application/json'));
}
示例6: departmentLabel
public function departmentLabel($code)
{
try {
return $this->departements->getLabel($code, true);
} catch (\InvalidArgumentException $e) {
return $this->translator->trans('report.company_departement.unknown');
}
}
示例7: sendWelcomeEmail
public function sendWelcomeEmail(User $user)
{
$token = $this->tokenGenerator->generateToken();
$link = $this->router->generate('fos_user_registration_register', array('token' => $token), true);
$this->mailer->sendMail($this->translator->trans('jwkh.publishers.email.welcome.subject', array(), null, $user->getPublisher()->getCongregation()->getDefaultLocale()), 'territory@jwkh.com', $user->getEmail(), $this->translator->trans('jwkh.publishers.email.welcome.body', array('%link%' => $link), null, $user->getPublisher()->getCongregation()->getDefaultLocale()));
$user->setConfirmationToken($token);
$this->userManager->updateUser($user);
}
示例8: createMainMenu
public function createMainMenu(Request $request, Translator $translator, SecurityContext $securityContext)
{
$menu = $this->factory->createItem('root');
$menu->setCurrentUri($request->getRequestUri());
$menu->addChild('bundles', array('route' => 'bundle_list'))->setLabel($translator->trans('menu.bundles'));
$menu->addChild('users', array('route' => 'user_list'))->setLabel($translator->trans('menu.users'));
$menu->addChild('evolution', array('route' => 'evolution'))->setLabel($translator->trans('menu.evolution'));
$menu->addChild('add-bundle', array('route' => 'add_bundle'))->setLabel($translator->trans('menu.addBundleManually'));
return $menu;
}
示例9: onPreAuthorizationProcess
/**
* @param OAuthEvent $event
*
* @throws AccessDeniedException
*/
public function onPreAuthorizationProcess(OAuthEvent $event)
{
if ($user = $this->getUser($event)) {
//check to see if user has api access
if (!$this->mauticSecurity->isGranted('api:access:full')) {
throw new AccessDeniedException($this->translator->trans('mautic.core.error.accessdenied', [], 'flashes'));
}
$client = $event->getClient();
$event->setAuthorizedClient($client->isAuthorizedClient($user, $this->em));
}
}
示例10: getNameDQL
/**
* Returns a DQL expression that can be used to get a text representation of the given type of entities.
*
* @param string $format The representation format, for example full, short, etc.
* @param string|null $locale The representation locale.
* @param string $className The FQCN of the entity
* @param string $alias The alias in SELECT or JOIN statement
*
* @return string A DQL expression or FALSE if this provider cannot return reliable result
*/
public function getNameDQL($format, $locale, $className, $alias)
{
if ($className === self::CLASS_NAME) {
if ($format === self::SHORT) {
return $alias . 'label';
} else {
return sprintf('CONCAT(%s.label, \' %s\')', $alias, $this->translator->trans('oro.email.mailbox.entity_label', [], null, $locale));
}
}
return false;
}
示例11: addEvent
/**
* Adds an action to the list of available .
*
* @param string $key - a unique identifier; it is recommended that it be namespaced i.e. lead.action
* @param array $event - can contain the following keys:
* 'label' => (required) what to display in the list
* 'description' => (optional) short description of event
* 'template' => (optional) template to use for the action's HTML in the point builder
* i.e AcmeMyBundle:PointAction:theaction.html.php
* 'formType' => (optional) name of the form type SERVICE for the action
* 'formTypeOptions' => (optional) array of options to pass to formType
* 'callback' => (required) callback function that will be passed when the action is triggered
* The callback function can receive the following arguments by name (via ReflectionMethod::invokeArgs())
* Mautic\CoreBundle\Factory\MauticFactory $factory
* Mautic\PointBundle\Entity\TriggerEvent $event
* Mautic\LeadBundle\Entity\Lead $lead
*
* @return void
* @throws InvalidArgumentException
*/
public function addEvent($key, array $event)
{
if (array_key_exists($key, $this->events)) {
throw new InvalidArgumentException("The key, '{$key}' is already used by another action. Please use a different key.");
}
//check for required keys and that given functions are callable
$this->verifyComponent(array('group', 'label', 'callback'), array('callback'), $event);
$event['label'] = $this->translator->trans($event['label']);
$event['group'] = $this->translator->trans($event['group']);
$event['description'] = isset($event['description']) ? $this->translator->trans($event['description']) : '';
$this->events[$key] = $event;
}
示例12: addAction
/**
* Adds an action to the list of available .
*
* @param string $key - a unique identifier; it is recommended that it be namespaced i.e. lead.action
* @param array $action - can contain the following keys:
* 'label' => (required) what to display in the list
* 'description' => (optional) short description of event
* 'template' => (optional) template to use for the action's HTML in the point builder
* i.e AcmeMyBundle:PointAction:theaction.html.php
* 'formType' => (optional) name of the form type SERVICE for the action; will use a default form with point change only
* 'formTypeOptions' => (optional) array of options to pass to formType
* 'callback' => (optional) callback function that will be passed when the action is triggered; return true to
* change the configured points or false to ignore the action
* The callback function can receive the following arguments by name (via ReflectionMethod::invokeArgs())
* Mautic\CoreBundle\Factory\MauticFactory $factory
* Mautic\LeadBundle\Entity\Lead $lead
* $eventDetails - variable sent from firing function to call back function
* array $action = array(
* 'id' => int
* 'type' => string
* 'name' => string
* 'properties' => array()
* )
*
* @return void
* @throws InvalidArgumentException
*/
public function addAction($key, array $action)
{
if (array_key_exists($key, $this->actions)) {
throw new InvalidArgumentException("The key, '{$key}' is already used by another action. Please use a different key.");
}
//check for required keys and that given functions are callable
$this->verifyComponent(array('group', 'label'), array('callback'), $action);
//translate the label and group
$action['label'] = $this->translator->trans($action['label']);
$action['group'] = $this->translator->trans($action['group']);
$this->actions[$key] = $action;
}
示例13: addSubmitAction
/**
* Adds a submit action to the list of available actions.
*
* @param string $key a unique identifier; it is recommended that it be namespaced i.e. lead.action
* @param array $action can contain the following keys:
* $action = [
* 'group' => (required) Label of the group to add this action to
* 'label' => (required) what to display in the list
* 'eventName' => (required) Event dispatched to execute action; it will receive a SubmissionEvent object
* 'formType' => (required) name of the form type SERVICE for the action
* 'allowCampaignForm' => (optional) true to allow this action for campaign forms; defaults to false
* 'description' => (optional) short description of event
* 'template' => (optional) template to use for the action's HTML in the form builder;
* eg AcmeMyBundle:FormAction:theaction.html.php
* 'formTypeOptions' => (optional) array of options to pass to formType
* 'formTheme' => (optional theme for custom form views
* 'validator' => (deprecated) callback function to validate form results - use addValidator() instead
* 'callback' => (deprecated) callback function that will be passed the results upon a form submit; use eventName instead
* ]
*
* @throws InvalidArgumentException
*/
public function addSubmitAction($key, array $action)
{
if (array_key_exists($key, $this->actions)) {
throw new InvalidArgumentException("The key, '{$key}' is already used by another action. Please use a different key.");
}
//check for required keys and that given functions are callable
$this->verifyComponent(['group', 'label', 'formType', ['eventName', 'callback', 'validator']], $action);
$action['label'] = $this->translator->trans($action['label']);
if (!isset($action['description'])) {
$action['description'] = '';
}
$this->actions[$key] = $action;
}
示例14: getConstraints
/**
* @param PersistentCollection $key
*
* @return array|mixed
*/
public function getConstraints(Attachment $attachment, DimensionContainer $dimensionContainer)
{
$constraints = array();
foreach ($this->constraints as $constraintClass) {
$constraintClass->setup($attachment, $dimensionContainer);
$validate = $constraintClass->validate();
if ($validate && $validate instanceof TranslatorObject) {
$constraints[] = $this->translator->trans($validate->getId(), $validate->getData());
}
}
if (count($constraints) == 0) {
return;
}
return $constraints;
}
示例15: getClientBillStatusText
public function getClientBillStatusText(User $client, $year, $quarter)
{
$status = $this->getClientBillStatus($client, $year, $quarter);
if ($status < 0) {
return $this->translator->transChoice('bill.accounts_require_attention', -$status, array('%count%' => -$status));
}
return $this->translator->trans('bill.status' . $status);
}