当前位置: 首页>>代码示例>>PHP>>正文


PHP Translation\TranslatorInterface类代码示例

本文整理汇总了PHP中Symfony\Component\Translation\TranslatorInterface的典型用法代码示例。如果您正苦于以下问题:PHP TranslatorInterface类的具体用法?PHP TranslatorInterface怎么用?PHP TranslatorInterface使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了TranslatorInterface类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: setUp

 /**
  * Set up the tests.
  */
 public function setUp()
 {
     parent::setUp();
     $this->translator = $this->app['translator'];
     $this->detector = new LanguageDetector($this->translator);
     $this->translator->setLocale('fr');
 }
开发者ID:bitbeans,项目名称:laravel-language-detector,代码行数:10,代码来源:AbstractDriversTestCase.php

示例2: buildForm

 /**
  * {@inheritdoc}
  */
 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     $builder->addEventSubscriber(new DecodeFolderSubscriber());
     $this->addOwnerOrganizationEventListener($builder);
     $this->addNewOriginCreateEventListener($builder);
     $this->addPrepopulateRefreshTokenEventListener($builder);
     $builder->addEventSubscriber(new OriginFolderSubscriber());
     $builder->addEventSubscriber(new ApplySyncSubscriber());
     $builder->add('check', 'button', ['label' => $this->translator->trans('oro.imap.configuration.connect'), 'attr' => ['class' => 'btn btn-primary']])->add('accessToken', 'hidden')->add('refreshToken', 'hidden')->add('accessTokenExpiresAt', 'hidden')->add('imapHost', 'hidden', ['required' => true, 'data' => GmailImap::DEFAULT_GMAIL_HOST])->add('imapPort', 'hidden', ['required' => true, 'data' => GmailImap::DEFAULT_GMAIL_PORT])->add('user', 'hidden', ['required' => true])->add('imapEncryption', 'hidden', ['required' => true, 'data' => GmailImap::DEFAULT_GMAIL_SSL])->add('clientId', 'hidden', ['data' => $this->userConfigManager->get('oro_google_integration.client_id')])->add('smtpHost', 'hidden', ['required' => false, 'data' => GmailImap::DEFAULT_GMAIL_SMTP_HOST])->add('smtpPort', 'hidden', ['required' => false, 'data' => GmailImap::DEFAULT_GMAIL_SMTP_PORT])->add('smtpEncryption', 'hidden', ['required' => false, 'data' => GmailImap::DEFAULT_GMAIL_SMTP_SSL]);
     $builder->get('accessTokenExpiresAt')->addModelTransformer(new CallbackTransformer(function ($originalAccessTokenExpiresAt) {
         if ($originalAccessTokenExpiresAt === null) {
             return '';
         }
         $now = new \DateTime('now', new \DateTimeZone('UTC'));
         return $originalAccessTokenExpiresAt->format('U') - $now->format('U');
     }, function ($submittedAccessTokenExpiresAt) {
         if ($submittedAccessTokenExpiresAt instanceof \DateTime) {
             return $submittedAccessTokenExpiresAt;
         }
         $utcTimeZone = new \DateTimeZone('UTC');
         $newExpireDate = new \DateTime('+' . (int) $submittedAccessTokenExpiresAt . ' seconds', $utcTimeZone);
         return $newExpireDate;
     }));
     $builder->addEventSubscriber(new GmailOAuthSubscriber($this->translator));
 }
开发者ID:startupz,项目名称:platform-1,代码行数:28,代码来源:ConfigurationGmailType.php

示例3: updateForm

 /**
  * @param FormInterface $form
  * @param UserEmailOrigin $emailOrigin
  */
 protected function updateForm(FormInterface $form, UserEmailOrigin $emailOrigin)
 {
     if (!empty($emailOrigin->getAccessToken())) {
         $form->add('checkFolder', 'button', ['label' => $this->translator->trans('oro.email.retrieve_folders.label'), 'attr' => ['class' => 'btn btn-primary']])->add('folders', 'oro_email_email_folder_tree', ['label' => $this->translator->trans('oro.email.folders.label'), 'attr' => ['class' => 'folder-tree'], 'tooltip' => $this->translator->trans('oro.email.folders.tooltip')]);
         $form->remove('check');
     }
 }
开发者ID:ramunasd,项目名称:platform,代码行数:11,代码来源:GmailOAuthSubscriber.php

示例4: 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;
 }
开发者ID:eliberty,项目名称:api-bundle,代码行数:33,代码来源:ErrorNormalizer.php

示例5: 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;
 }
开发者ID:Maksold,项目名称:platform,代码行数:35,代码来源:EmailRecipientsProvider.php

示例6: validate

 /**
  * @param AbstractQueryDesigner         $value
  * @param GroupingConstraint|Constraint $constraint
  */
 public function validate($value, Constraint $constraint)
 {
     $definition = json_decode($value->getDefinition(), true);
     if (empty($definition['columns'])) {
         return;
     }
     $columns = $definition['columns'];
     $aggregateColumns = array_filter($columns, function (array $column) {
         return !empty($column['func']);
     });
     if (empty($aggregateColumns)) {
         return;
     }
     $groupingColumns = [];
     if (!empty($definition['grouping_columns'])) {
         $groupingColumns = $definition['grouping_columns'];
     }
     $groupingColumnNames = ArrayUtil::arrayColumn($groupingColumns, 'name');
     $columnNames = ArrayUtil::arrayColumn($columns, 'name');
     $columnNamesToCheck = array_diff($columnNames, ArrayUtil::arrayColumn($aggregateColumns, 'name'));
     $columnsToGroup = array_diff($columnNamesToCheck, $groupingColumnNames);
     if (empty($columnsToGroup)) {
         return;
     }
     $columnLabels = [];
     foreach ($columns as $column) {
         if (in_array($column['name'], $columnsToGroup)) {
             $columnLabels[] = $column['label'];
         }
     }
     $this->context->addViolation($this->translator->trans($constraint->message, ['%columns%' => implode(', ', $columnLabels)]));
 }
开发者ID:ramunasd,项目名称:platform,代码行数:36,代码来源:GroupingValidator.php

示例7: 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;
 }
开发者ID:Maksold,项目名称:platform,代码行数:35,代码来源:EmailTemplateHandler.php

示例8: visitMetadata

 /**
  * {@inheritDoc}
  */
 public function visitMetadata(DatagridConfiguration $config, MetadataObject $data)
 {
     $params = $this->getParameters()->get(ParameterBag::ADDITIONAL_PARAMETERS, []);
     $currentView = isset($params[self::VIEWS_PARAM_KEY]) ? $params[self::VIEWS_PARAM_KEY] : null;
     $data->offsetAddToArray('initialState', ['gridView' => '__all__']);
     $data->offsetAddToArray('state', ['gridView' => $currentView]);
     $allLabel = null;
     if (isset($config['options']) && isset($config['options']['gridViews']) && isset($config['options']['gridViews']['allLabel'])) {
         $allLabel = $this->translator->trans($config['options']['gridViews']['allLabel']);
     }
     /** @var AbstractViewsList $list */
     $list = $config->offsetGetOr(self::VIEWS_LIST_KEY, false);
     $gridViews = ['choices' => [['label' => $allLabel, 'value' => '__all__']], 'views' => [(new View('__all__'))->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->offsetSet('gridViews', $gridViews);
 }
开发者ID:northdakota,项目名称:platform,代码行数:31,代码来源:GridViewsExtension.php

示例9: buildResultsObject

 /**
  * @param ResultSet $resultSet
  * @param $section
  * @return array
  */
 public function buildResultsObject(ResultSet $resultSet, $section)
 {
     $results = [];
     /**
      * @var Result $object
      */
     foreach ($resultSet as $object) {
         $objectType = $object->getType();
         if (!isset($results[$objectType])) {
             $results[$objectType]['data'] = [];
             $results[$objectType]['total_item'] = 1;
             $results[$objectType]['type'] = $this->translator->trans($object->getType());
         } else {
             $results[$objectType]['total_item']++;
         }
         if ($section == $objectType) {
             $result['detail'] = $this->getObjectDetail($object);
             $result['source'] = $object->getSource();
             if ($result['detail']['route']) {
                 $results[$objectType]['data'][] = $result;
             }
         }
     }
     //set only acceptable count for selected section
     if (!empty($section) && isset($results[$section])) {
         $results[$section]['total_item'] = count($results[$section]['data']);
     }
     foreach ($results as $result) {
         $this->setTotalHit($this->getTotalHit() + $result['total_item']);
     }
     return $results;
 }
开发者ID:hasantayyar,项目名称:ojs,代码行数:37,代码来源:SearchManager.php

示例10: createGridViewLabel

 /**
  * @param User $currentUser
  * @param GridView $gridView
  *
  * @return string
  */
 protected function createGridViewLabel(User $currentUser, GridView $gridView)
 {
     if ($gridView->getOwner()->getId() === $currentUser->getId()) {
         return $gridView->getName();
     }
     return $this->translator->trans('oro.datagrid.gridview.shared_by', ['%name%' => $gridView->getName(), '%owner%' => $gridView->getOwner()->getUsername()]);
 }
开发者ID:Maksold,项目名称:platform,代码行数:13,代码来源:GridViewsLoadListener.php

示例11: getGroupedResults

 /**
  * Returns grouped search results
  *
  * @param string $string
  * @return array
  */
 public function getGroupedResults($string)
 {
     $search = $this->getResults($string);
     // empty key array contains all data
     $result = array('' => array('count' => 0, 'class' => '', 'config' => array(), 'icon' => '', 'label' => ''));
     /** @var $item Item */
     foreach ($search->getElements() as $item) {
         $config = $item->getEntityConfig();
         $alias = $config['alias'];
         if (!isset($result[$alias])) {
             $group = array('count' => 0, 'class' => $item->getEntityName(), 'config' => $config, 'icon' => '', 'label' => '');
             if (!empty($group['class']) && $this->configManager->hasConfig($group['class'])) {
                 $entityConfigId = new EntityConfigId('entity', $group['class']);
                 $entityConfig = $this->configManager->getConfig($entityConfigId);
                 if ($entityConfig->has('plural_label')) {
                     $group['label'] = $this->translator->trans($entityConfig->get('plural_label'));
                 }
                 if ($entityConfig->has('icon')) {
                     $group['icon'] = $entityConfig->get('icon');
                 }
             }
             $result[$alias] = $group;
         }
         $result[$alias]['count']++;
         $result['']['count']++;
     }
     uasort($result, function ($first, $second) {
         if ($first['label'] == $second['label']) {
             return 0;
         }
         return $first['label'] > $second['label'] ? 1 : -1;
     });
     return $result;
 }
开发者ID:Maksold,项目名称:platform,代码行数:40,代码来源:ResultStatisticsProvider.php

示例12: testBuildFormRegularGuesser

 /**
  * @param bool $withRelations
  *
  * @dataProvider testDataProvider
  */
 public function testBuildFormRegularGuesser($withRelations)
 {
     $entityName = 'Test\\Entity';
     $this->doctrineHelperMock->expects($this->once())->method('getEntityIdentifierFieldNames')->with($entityName)->willReturn(['id']);
     $fields = [['name' => 'oneField', 'type' => 'string', 'label' => 'One field'], ['name' => 'anotherField', 'type' => 'string', 'label' => 'Another field']];
     if ($withRelations) {
         $fields[] = ['name' => 'relField', 'relation_type' => 'ref-one', 'label' => 'Many to One field'];
     }
     $this->entityFieldMock->expects($this->once())->method('getFields')->willReturn($fields);
     $this->formConfigMock->expects($this->at(0))->method('getConfig')->with($entityName, 'oneField')->willReturn(new Config(new FieldConfigId('form', $entityName, 'someField'), ['is_enabled' => false]));
     $this->formConfigMock->expects($this->at(1))->method('getConfig')->with($entityName, 'anotherField')->willReturn(new Config(new FieldConfigId('form', $entityName, 'anotherField'), ['is_enabled' => true]));
     if ($withRelations) {
         $this->formConfigMock->expects($this->at(2))->method('getConfig')->with($entityName, 'relField')->willReturn(new Config(new FieldConfigId('form', $entityName, 'relField'), ['is_enabled' => true]));
         $this->translatorMock->expects($this->at(0))->method('trans')->with('oro.entity.form.entity_fields')->willReturn('Fields');
         $this->translatorMock->expects($this->at(1))->method('trans')->with('oro.entity.form.entity_related')->willReturn('Relations');
     }
     $form = $this->factory->create($this->type, null, ['entity' => $entityName, 'with_relations' => $withRelations]);
     $view = $form->createView();
     $this->assertEquals('update_field_choice', $view->vars['full_name'], 'Failed asserting that field name is correct');
     $this->assertNotEmpty($view->vars['configs']['component']);
     $this->assertEquals('entity-field-choice', $view->vars['configs']['component']);
     $this->assertEquals('update_field_choice', $form->getConfig()->getType()->getName(), 'Failed asserting that correct underlying type was used');
     if ($withRelations) {
         $this->assertCount(2, $view->vars['choices'], 'Failed asserting that choices are grouped');
     } else {
         $this->assertCount(1, $view->vars['choices'], 'Failed asserting that choices exists');
         /** @var ChoiceView $choice */
         $choice = reset($view->vars['choices']);
         $this->assertEquals('Another field', $choice->label);
     }
 }
开发者ID:trustify,项目名称:oroplatform-mass-update-bundle,代码行数:36,代码来源:UpdateFieldChoiceTypeTest.php

示例13: shareList

 /**
  * {@inheritdoc}
  */
 public function shareList(array $posts)
 {
     $contacts = $this->contactProvider->getContacts();
     $now = new \DateTime();
     $from = $this->from;
     $subject = $this->getSubject($now);
     $response = array('sended' => false, 'errors' => array());
     foreach ($posts as $key => $post) {
         if (!$post->getPublished()) {
             $response['errors'][] = $this->translator->trans('newsletter_post_not_published', array('%post_title%' => $post->getTitle()), 'PostAdmin');
         }
     }
     if (empty($response['errors'])) {
         foreach ($contacts as $contact) {
             if (!$contact instanceof ContactInterface) {
                 throw new \InvalidArgumentException(sprintf("%s must implement %s.", get_class($contact), ContactInterface::class));
             }
             $template = $this->templating->render('@Admin/Batch/Newsletter/share_posts.html.twig', array('posts' => $posts, 'contact' => $contact));
             $to = array($contact->getEmail());
             if ($this->emailSender->send($from, $to, $subject, $template)) {
                 foreach ($posts as $post) {
                     $post->setSharedNewsletter($now);
                 }
                 $response['sended'] = true;
             }
         }
     }
     return $response;
 }
开发者ID:nathix86,项目名称:bcp-website,代码行数:32,代码来源:NewsletterManager.php

示例14: createRootItem

 /**
  * @return Item
  */
 private function createRootItem()
 {
     $translation = new Item('translation-locale');
     $translation->setLabel($this->translator->trans('admin.locale.dropdown.title', array('%locale%' => $this->localeManager->getLocale()), 'FSiAdminTranslatableBundle'));
     $translation->setOptions(array('attr' => array('id' => 'translatable-switcher')));
     return $translation;
 }
开发者ID:szymach,项目名称:admin-translatable-bundle,代码行数:10,代码来源:TranslationLocaleMenuListener.php

示例15: 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;
 }
开发者ID:szymach,项目名称:admin-security-bundle,代码行数:10,代码来源:ToolsMenuListener.php


注:本文中的Symfony\Component\Translation\TranslatorInterface类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。