本文整理汇总了PHP中Symfony\Component\Translation\TranslatorInterface::trans方法的典型用法代码示例。如果您正苦于以下问题:PHP TranslatorInterface::trans方法的具体用法?PHP TranslatorInterface::trans怎么用?PHP TranslatorInterface::trans使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\Translation\TranslatorInterface
的用法示例。
在下文中一共展示了TranslatorInterface::trans方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: translate
/**
* @param null|string $messageType
* @param null|string $message
* @param array $parameters
* @param null|string $domain
* @param null|string $locale
*
* @return string Translated message
*/
public function translate($messageType = null, $message = null, array $parameters = array(), $domain = null, $locale = null)
{
if ($message === null) {
$message = $this->getTranslationId($messageType);
}
return $this->translator->trans($message, $parameters, $domain, $locale);
}
示例2: validate
/**
* @param GridQueryDesignerInterface|AbstractQueryDesigner $value
* @param QueryConstraint|Constraint $constraint
*/
public function validate($value, Constraint $constraint)
{
if (!$value instanceof GridQueryDesignerInterface) {
return;
}
$gridPrefix = $value->getGridPrefix();
$builder = $this->getBuilder($gridPrefix);
$builder->setGridName($gridPrefix);
$builder->setSource($value);
$message = $this->translator->trans($constraint->message);
try {
$dataGrid = $this->gridBuilder->build($builder->getConfiguration(), new ParameterBag());
$dataSource = $dataGrid->getDatasource();
if ($dataSource instanceof OrmDatasource) {
$qb = $dataSource->getQueryBuilder();
$qb->setMaxResults(1);
}
$dataSource->getResults();
} catch (DBALException $e) {
$this->context->addViolation($this->isDebug ? $e->getMessage() : $message);
} catch (ORMException $e) {
$this->context->addViolation($this->isDebug ? $e->getMessage() : $message);
} catch (InvalidConfigurationException $e) {
$this->context->addViolation($this->isDebug ? $e->getMessage() : $message);
}
}
示例3: process
/**
* Process form
*
* @param EmailTemplate $entity
*
* @return bool True on successful processing, false otherwise
*/
public function process(EmailTemplate $entity)
{
// always use default locale during template edit in order to allow update of default locale
$entity->setLocale($this->defaultLocale);
if ($entity->getId()) {
// refresh translations
$this->manager->refresh($entity);
}
$this->form->setData($entity);
if (in_array($this->request->getMethod(), array('POST', 'PUT'))) {
// deny to modify system templates
if ($entity->getIsSystem() && !$entity->getIsEditable()) {
$this->form->addError(new FormError($this->translator->trans('oro.email.handler.attempt_save_system_template')));
return false;
}
$this->form->submit($this->request);
if ($this->form->isValid()) {
// mark an email template creating by an user as editable
if (!$entity->getId()) {
$entity->setIsEditable(true);
}
$this->manager->persist($entity);
$this->manager->flush();
return true;
}
}
return false;
}
示例4: buildForm
/**
* {@inheritdoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$options['field_options_start'] = array_merge(array('label' => $this->translator->trans('date_range_start', array(), 'SonataCoreBundle')), $options['field_options_start']);
$options['field_options_end'] = array_merge(array('label' => $this->translator->trans('date_range_end', array(), 'SonataCoreBundle')), $options['field_options_end']);
$builder->add('start', $options['field_type'], array_merge(array('required' => false), $options['field_options'], $options['field_options_start']));
$builder->add('end', $options['field_type'], array_merge(array('required' => false), $options['field_options'], $options['field_options_end']));
}
示例5: onSuccess
/**
* On success.
*
* @return RedirectResponse
*/
public function onSuccess()
{
$alert = $this->alertManager->create();
$alert->addSuccess($this->translator->trans('success.save_banner_zone', array(), 'SilvestraBanner'));
$this->alertManager->setFlashAlert($alert);
return new RedirectResponse($this->router->generate('silvestra_banner.banner_zone_list'));
}
示例6: buildForm
/**
* {@inheritdoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
if (empty($options['data_class'])) {
return;
}
$className = $options['data_class'];
if (!$this->doctrineHelper->isManageableEntity($className)) {
return;
}
if (!$this->entityConfigProvider->hasConfig($className)) {
return;
}
$uniqueKeys = $this->entityConfigProvider->getConfig($className)->get('unique_key');
if (empty($uniqueKeys)) {
return;
}
/* @var \Symfony\Component\Validator\Mapping\ClassMetadata $validatorMetadata */
$validatorMetadata = $this->validator->getMetadataFor($className);
foreach ($uniqueKeys['keys'] as $uniqueKey) {
$fields = $uniqueKey['key'];
$labels = array_map(function ($fieldName) use($className) {
$label = $this->entityConfigProvider->getConfig($className, $fieldName)->get('label');
return $this->translator->trans($label);
}, $fields);
$constraint = new UniqueEntity(['fields' => $fields, 'errorPath' => '', 'message' => $this->translator->transChoice('oro.entity.validation.unique_field', sizeof($fields), ['%field%' => implode(', ', $labels)])]);
$validatorMetadata->addConstraint($constraint);
}
}
示例7: visitMetadata
/**
* {@inheritdoc}
*/
public function visitMetadata(DatagridConfiguration $config, MetadataObject $data)
{
$currentViewId = $this->getCurrentViewId($config->getName());
$this->setDefaultParams($config->getName());
$data->offsetAddToArray('initialState', ['gridView' => self::DEFAULT_VIEW_ID]);
$data->offsetAddToArray('state', ['gridView' => $currentViewId]);
$allLabel = null;
if (isset($config['options'], $config['options']['gridViews'], $config['options']['gridViews']['allLabel'])) {
$allLabel = $this->translator->trans($config['options']['gridViews']['allLabel']);
}
/** @var AbstractViewsList $list */
$list = $config->offsetGetOr(self::VIEWS_LIST_KEY, false);
$systemGridView = new View(self::DEFAULT_VIEW_ID);
$systemGridView->setDefault($this->getDefaultViewId($config->getName()) === null);
$gridViews = ['choices' => [['label' => $allLabel, 'value' => self::DEFAULT_VIEW_ID]], 'views' => [$systemGridView->getMetadata()]];
if ($list !== false) {
$configuredGridViews = $list->getMetadata();
$configuredGridViews['views'] = array_merge($gridViews['views'], $configuredGridViews['views']);
$configuredGridViews['choices'] = array_merge($gridViews['choices'], $configuredGridViews['choices']);
$gridViews = $configuredGridViews;
}
if ($this->eventDispatcher->hasListeners(GridViewsLoadEvent::EVENT_NAME)) {
$event = new GridViewsLoadEvent($config->getName(), $gridViews);
$this->eventDispatcher->dispatch(GridViewsLoadEvent::EVENT_NAME, $event);
$gridViews = $event->getGridViews();
}
$gridViews['gridName'] = $config->getName();
$gridViews['permissions'] = $this->getPermissions();
$data->offsetAddToArray('gridViews', $gridViews);
}
示例8: normalize
/**
* @param object $object
* @param null $format
* @param array $context
*
* @return array|bool|float|int|null|string
*/
public function normalize($object, $format = null, array $context = array())
{
if ($object instanceof \Exception) {
$message = $object->getMessage();
if ($this->debug) {
$trace = $object->getTrace();
}
}
$data = ['context' => 'Error', 'type' => 'Error', 'title' => isset($context['title']) ? $context['title'] : 'An error occurred', 'description' => isset($message) ? $message : (string) $object];
if (isset($trace)) {
$data['trace'] = $trace;
}
$msgError = $object->getMessage();
if (method_exists($object, 'getErrors')) {
$errors = [];
foreach ($object->getErrors() as $key => $error) {
foreach ($error as $name => $message) {
$errors[$key][$name] = $this->translator->trans($message);
}
}
if (!empty($errors) && isset($data['description'])) {
$data['description'] = ['title' => isset($msgError) ? $msgError : (string) $object, 'json-error' => $errors];
}
}
return $data;
}
示例9: createRootItem
/**
* @return Item
*/
private function createRootItem()
{
$rootItem = new Item('account');
$rootItem->setLabel($this->translator->trans('admin.welcome', array('%username%' => $this->tokenStorage->getToken()->getUsername()), 'FSiAdminSecurity'));
$rootItem->setOptions(array('attr' => array('id' => 'account')));
return $rootItem;
}
示例10: getErrorMessages
/**
* Returns an array with form fields errors
*
* @param FormInterface $form
* @param bool|false $useLabels
* @param array $errors
* @return array
*/
public function getErrorMessages(FormInterface $form, $useLabels = false, $errors = array())
{
if ($form->count() > 0) {
foreach ($form->all() as $child) {
if (!$child->isValid()) {
$errors = $this->getErrorMessages($child, $useLabels, $errors);
}
}
}
foreach ($form->getErrors() as $error) {
if ($useLabels) {
$fieldNameData = $this->getErrorFormLabel($form);
} else {
$fieldNameData = $this->getErrorFormId($form);
}
$fieldName = $fieldNameData;
if ($useLabels) {
/**
* @ignore
*/
$fieldName = $this->translator->trans($fieldNameData['label'], array(), $fieldNameData['domain']);
}
$errors[$fieldName] = $error->getMessage();
}
return $errors;
}
示例11: addCategoryBlock
/**
* @param ScrollData $scrollData
* @param string $html
*/
protected function addCategoryBlock(ScrollData $scrollData, $html)
{
$blockLabel = $this->translator->trans('orob2b.catalog.product.section.catalog');
$blockId = $scrollData->addBlock($blockLabel);
$subBlockId = $scrollData->addSubBlock($blockId);
$scrollData->addSubBlockData($blockId, $subBlockId, $html);
}
示例12: getEntityNames
/**
* {@inheritdoc}
*/
public function getEntityNames()
{
$result = [];
$result['_empty_'] = $this->translator->trans('ibnab.pmanager.pdftemplate.datagrid.template.filter.entityName.empty');
$result = array_merge($result, parent::getEntityNames());
return $result;
}
示例13: process
/**
* @param BreadcrumbItem $item
* @param array $variables
* @return ProcessedBreadcrumbItem
*/
public function process(BreadcrumbItem $item, $variables)
{
// Process the label
if ($item->getLabel()[0] === '$') {
$processedLabel = $this->parseValue($item->getLabel(), $variables);
} else {
$processedLabel = $this->translator->trans($item->getLabel());
}
// Process the route
// TODO: cache parameters extracted from current request
$params = [];
foreach ($this->requestStack->getCurrentRequest()->attributes as $key => $value) {
if ($key[0] !== '_') {
$params[$key] = $value;
}
}
foreach ($item->getRouteParams() ?: [] as $key => $value) {
if ($value[0] === '$') {
$params[$key] = $this->parseValue($value, $variables);
} else {
$params[$key] = $value;
}
}
if ($item->getRoute() !== null) {
$processedUrl = $this->router->generate($item->getRoute(), $params);
} else {
$processedUrl = null;
}
return new ProcessedBreadcrumbItem($processedLabel, $processedUrl);
}
示例14: process
/**
* @param Request $request
* @return array ['form' => FormInterface, 'response' => Response|null]
*/
public function process(Request $request)
{
$response = null;
$formOptions = [];
$processor = $this->getProcessor($this->getComponentName($request));
if ($processor) {
$formOptions['validation_required'] = $processor->isValidationRequired();
}
$form = $this->createQuickAddForm($formOptions);
if ($request->isMethod(Request::METHOD_POST)) {
$form->submit($request);
if ($processor && $processor->isAllowed()) {
if ($form->isValid()) {
$products = $form->get(QuickAddType::PRODUCTS_FIELD_NAME)->getData();
$products = is_array($products) ? $products : [];
$response = $processor->process([ProductDataStorage::ENTITY_ITEMS_DATA_KEY => $products], $request);
if (!$response) {
// reset form
$form = $this->createQuickAddForm($formOptions);
}
}
} else {
/** @var Session $session */
$session = $request->getSession();
$session->getFlashBag()->add('error', $this->translator->trans('orob2b.product.frontend.component_not_accessible.message'));
}
}
return ['form' => $form, 'response' => $response];
}
示例15: getEmailRecipients
/**
* @param object|null $relatedEntity
* @param string|null $query
* @param Organization|null $organization
* @param int $limit
*
* @return array
*/
public function getEmailRecipients($relatedEntity = null, $query = null, Organization $organization = null, $limit = 100)
{
$emails = [];
foreach ($this->providers as $provider) {
if ($limit <= 0) {
break;
}
$args = new EmailRecipientsProviderArgs($relatedEntity, $query, $limit, array_reduce($emails, 'array_merge', []), $organization);
$recipients = $provider->getRecipients($args);
if (!$recipients) {
continue;
}
$limit = max([0, $limit - count($recipients)]);
if (!array_key_exists($provider->getSection(), $emails)) {
$emails[$provider->getSection()] = [];
}
$emails[$provider->getSection()] = array_merge($emails[$provider->getSection()], $recipients);
}
$result = [];
foreach ($emails as $section => $sectionEmails) {
$items = array_map(function (Recipient $recipient) {
return $this->emailRecipientsHelper->createRecipientData($recipient);
}, $sectionEmails);
$result[] = ['text' => $this->translator->trans($section), 'children' => array_values($items)];
}
return $result;
}