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


PHP TranslatorInterface::getLocale方法代码示例

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


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

示例1: notify

 public function notify(RequestVerifiedEvent $event)
 {
     $payment = $event->getPayment();
     $status = $event->getStatus()->getValue();
     switch ($status) {
         case GetHumanStatus::STATUS_AUTHORIZED:
         case GetHumanStatus::STATUS_CAPTURED:
         case GetHumanStatus::STATUS_REFUNDED:
             $this->repository->clearCart();
             $type = 'success';
             break;
         case GetHumanStatus::STATUS_CANCELED:
         case GetHumanStatus::STATUS_EXPIRED:
         case GetHumanStatus::STATUS_FAILED:
             $type = 'danger';
             break;
         case GetHumanStatus::STATUS_PENDING:
         case GetHumanStatus::STATUS_SUSPENDED:
             $this->repository->clearCart();
             $type = 'warning';
             break;
         case GetHumanStatus::STATUS_NEW:
         case GetHumanStatus::STATUS_UNKNOWN:
             $this->repository->clearCart();
             $type = 'info';
             break;
         default:
             throw new \RuntimeException('Unknown status ' . $status);
     }
     $formatter = new \NumberFormatter($this->translator->getLocale(), \NumberFormatter::CURRENCY);
     $this->session->getFlashBag()->add($type, $this->translator->trans('flash.payment.' . $type, ['%status%' => $this->translator->trans('meta.status.' . $status), '%amount%' => $formatter->formatCurrency($payment->getTotalAmount() / 100, $payment->getCurrencyCode())]));
 }
开发者ID:igaponov,项目名称:shop,代码行数:32,代码来源:PaymentFlashMessageSubscriber.php

示例2: postLoad

 /**
  * Inject Translator locale into loaded object.
  *
  * @param LifecycleEventArgs $args
  */
 public function postLoad(LifecycleEventArgs $args)
 {
     $object = $args->getObject();
     if ($object instanceof LocaleAware) {
         $object->setCurrentLocale($this->translator->getLocale());
     }
 }
开发者ID:nkt,项目名称:translate-bundle,代码行数:12,代码来源:LocaleEventSubscriber.php

示例3: execute

 /**
  * Executes controller.
  *
  * @param InputInterface  $input
  * @param OutputInterface $output
  *
  * @return null|integer
  */
 public function execute(InputInterface $input, OutputInterface $output)
 {
     if (!$input->getOption('story-syntax')) {
         return null;
     }
     $output->getFormatter()->setStyle('gherkin_keyword', new OutputFormatterStyle('green', null, array('bold')));
     $output->getFormatter()->setStyle('gherkin_comment', new OutputFormatterStyle('yellow'));
     $story = $this->keywordsDumper->dump($this->translator->getLocale());
     $story = preg_replace('/^\\#.*/', '<gherkin_comment>$0</gherkin_comment>', $story);
     $output->writeln($story);
     $output->writeln('');
     return 0;
 }
开发者ID:OverByThere,项目名称:Behat,代码行数:21,代码来源:SyntaxController.php

示例4: format

 /**
  * Format the given value.
  *
  * @param mixed   $value
  * @param string  $valueCurrency  $value currency code
  * @param boolean $decimal        show decimal part
  * @param boolean $symbol         show currency symbol
  * @return string
  */
 public function format($value, $valueCurrency = null, $decimal = true, $symbol = true)
 {
     if (null === $valueCurrency) {
         $valueCurrency = $this->getConverter()->getDefaultCurrency();
     }
     $formatter = new \NumberFormatter($this->translator->getLocale(), $symbol ? \NumberFormatter::CURRENCY : \NumberFormatter::PATTERN_DECIMAL);
     $value = $formatter->formatCurrency($value, $valueCurrency);
     if (!$decimal) {
         $value = preg_replace('/[.,]00((?=\\D)|$)/', '', $value);
     }
     $value = str_replace(array('EU', 'UK', 'US'), '', $value);
     return $value;
 }
开发者ID:dji-m,项目名称:LexikCurrencyBundle,代码行数:22,代码来源:CurrencyExtension.php

示例5: saveTranslations

 /**
  * @param array $translations
  */
 public function saveTranslations(array $translations)
 {
     if (!$translations) {
         return;
     }
     $locale = $this->translator->getLocale();
     $entities = [];
     foreach ($translations as $key => $value) {
         $entities[] = $this->createTranslationEntity($key, $value, $locale);
     }
     // mark translation cache dirty
     $this->translationCache->updateTimestamp($locale);
     $this->getTranslationManager()->flush($entities);
 }
开发者ID:Maksold,项目名称:platform,代码行数:17,代码来源:ConfigTranslationHelper.php

示例6: renderValue

 /**
  * @param mixed $value
  * @param array $options
  * @return string
  * @throws \Exception
  */
 public function renderValue($value, array $options = [])
 {
     if ($value instanceof \DateTime) {
         if (!empty($options['date_format'])) {
             return $value->format($options['date_format']);
         }
         $dateType = IntlDateFormatter::MEDIUM;
         $timeType = IntlDateFormatter::SHORT;
         if (array_key_exists('date_type', $options) && $options['date_type'] !== null && $options['date_type'] !== '') {
             $dateType = $options['date_type'];
         }
         if (array_key_exists('time_type', $options) && $options['time_type'] !== null && $options['time_type'] !== '') {
             $dateType = $options['time_type'];
         }
         $dateFormatter = new IntlDateFormatter($this->translator->getLocale(), $dateType, $timeType);
         return $dateFormatter->format($value);
     }
     if (is_int($value)) {
         return $value;
     }
     if (is_float($value)) {
         if (array_key_exists('decimals', $options) || array_key_exists('dec_point', $options) || array_key_exists('thousands_sep', $options)) {
             $decimals = array_key_exists('decimals', $options) ? $options['decimals'] : 2;
             $decPoint = array_key_exists('dec_point', $options) ? $options['dec_point'] : '.';
             $thousandsSep = array_key_exists('thousands_sep', $options) ? $options['thousands_sep'] : ',';
             return number_format($value, $decimals, $decPoint, $thousandsSep);
         }
         $numberFormatter = new NumberFormatter($this->translator->getLocale(), NumberFormatter::DECIMAL);
         return $numberFormatter->format($value);
     }
     if (is_array($value) || $value instanceof \Traversable) {
         $items = [];
         foreach ($value as $item) {
             $items[] = $this->renderValue($item, $options);
         }
         $glue = ', ';
         if (!empty($options['array_glue'])) {
             $glue = $options['array_glue'];
         }
         return implode($glue, $items);
     }
     if (is_callable($value)) {
         return $value($options);
     }
     if (is_bool($value)) {
         return $this->translator->trans($value ? 'sidus.datagrid.boolean.yes' : 'sidus.datagrid.boolean.no');
     }
     return $value;
 }
开发者ID:VincentChalnot,项目名称:SidusDataGridBundle,代码行数:55,代码来源:TwigRenderer.php

示例7: metaTagsHtml

 public function metaTagsHtml($defaults = true, array $arguments = array(), $canonical = true)
 {
     $locale = $this->translator->getLocale();
     $currentLang = substr($locale, 0, 2);
     if (!isset($arguments['pre'])) {
         $arguments['pre'] = sprintf("\n%8s", ' ');
     }
     $headers = self::initMetaTagString();
     if ($defaults) {
         $headers .= $arguments['pre'] . '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
         $headers .= $arguments['pre'] . '<meta http-equiv="content-language" content="' . $currentLang . '" />';
         $headers .= $arguments['pre'] . '<meta name="DC.language" scheme="RFC3066" content="' . $currentLang . '" />';
     }
     $key = $this->keyGenerator->generateMetaTagKey($this->container->get('request'), $this->container->get('router'), $locale);
     $obj = $this->manager->findMetaTag($key, $locale);
     if ($obj) {
         $headers .= $this->metaTagToHtml($obj, $arguments);
     } else {
         $tags = $arguments;
         unset($tags['pre']);
         $headers .= MetaTagToHtmlRenderer::createMetaTags($arguments['pre'], $tags, $this);
     }
     if ($canonical) {
         $headers .= $arguments['pre'] . $this->canonicalTagsHtml($this->getRequest()->getPathInfo());
     }
     return $headers;
 }
开发者ID:vstm,项目名称:IbrowsSimpleSeoBundle,代码行数:27,代码来源:TwigExtension.php

示例8: routePrefix

 /**
  * Get the route prefix.
  *
  * @return string
  */
 public function routePrefix()
 {
     $driver = $this->getDriver();
     if ($driver instanceof ShouldPrefixRoute) {
         return $driver->routePrefix($this->translator->getLocale());
     }
     return '';
 }
开发者ID:bitbeans,项目名称:laravel-language-detector,代码行数:13,代码来源:LanguageDetector.php

示例9: render

 /**
  * renders content with the real website controller.
  *
  * @param PageBridge $content
  * @param bool       $partial
  *
  * @return string
  */
 public function render(PageBridge $content, $partial = false)
 {
     // set active theme
     $webspace = $this->webspaceManager->findWebspaceByKey($content->getWebspaceKey());
     $this->activeTheme->setName($webspace->getTheme()->getKey());
     // get controller and invoke action
     $request = new Request();
     $request->attributes->set('_controller', $content->getController());
     $controller = $this->controllerResolver->getController($request);
     // prepare locale for translator and request
     $request->setLocale($content->getLanguageCode());
     $localeBefore = $this->translator->getLocale();
     $this->translator->setLocale($content->getLanguageCode());
     $this->requestStack->push($request);
     /** @var Response $response */
     $response = $controller[0]->{$controller[1]}($content, true, $partial);
     // roll back
     $this->requestStack->pop();
     $this->translator->setLocale($localeBefore);
     return $response->getContent();
 }
开发者ID:kriswillis,项目名称:sulu,代码行数:29,代码来源:PreviewRenderer.php

示例10: postSubmit

 /**
  * Post submit event handler
  *
  * @param FormEvent $event
  *
  * @SuppressWarnings(PHPMD.NPathComplexity)
  */
 public function postSubmit(FormEvent $event)
 {
     $form = $event->getForm();
     $configModel = $form->getConfig()->getOption('config_model');
     if (!$configModel instanceof FieldConfigModel) {
         return;
     }
     if (!in_array($configModel->getType(), ['enum', 'multiEnum'])) {
         return;
     }
     if (!$form->isValid()) {
         return;
     }
     $data = $event->getData();
     $enumConfig = $configModel->toArray('enum');
     $enumName = $this->getValue($data['enum'], 'enum_name');
     $enumCode = $this->getValue($enumConfig, 'enum_code');
     if (empty($enumCode)) {
         $enumCode = $enumName !== null ? ExtendHelper::buildEnumCode($enumName) : ExtendHelper::generateEnumCode($configModel->getEntity()->getClassName(), $configModel->getFieldName());
     }
     $locale = $this->translator->getLocale();
     $enumValueClassName = ExtendHelper::buildEnumValueClassName($enumCode);
     $enumConfigProvider = $this->configManager->getProvider('enum');
     if ($enumConfigProvider->hasConfig($enumValueClassName)) {
         // existing enum
         if ($configModel->getId()) {
             if ($enumName !== null) {
                 $this->enumSynchronizer->applyEnumNameTrans($enumCode, $enumName, $locale);
             }
             $enumOptions = $this->getValue($data['enum'], 'enum_options');
             if ($enumOptions !== null) {
                 $this->enumSynchronizer->applyEnumOptions($enumValueClassName, $enumOptions, $locale);
             }
             $enumPublic = $this->getValue($data['enum'], 'enum_public');
             if ($enumPublic !== null) {
                 $this->enumSynchronizer->applyEnumEntityOptions($enumValueClassName, $enumPublic);
             }
         }
         unset($data['enum']['enum_name']);
         unset($data['enum']['enum_options']);
         unset($data['enum']['enum_public']);
         $event->setData($data);
     } else {
         // new enum
         $this->sortOptions($data['enum']['enum_options']);
         $data['enum']['enum_locale'] = $locale;
         $event->setData($data);
     }
 }
开发者ID:ramunasd,项目名称:platform,代码行数:56,代码来源:EnumFieldConfigExtension.php

示例11: finishView

 public function finishView(FormView $view, FormInterface $form, array $options)
 {
     if ($view->children['country']->vars['choice_translation_domain'] === false) {
         return;
     }
     $collator = new \Collator($this->translator->getLocale());
     $translator = $this->translator;
     $sortFunction = function ($a, $b) use($collator, $translator) {
         return $collator->compare($translator->trans($a->label), $translator->trans($b->label));
     };
     usort($view->children['country']->vars['choices'], $sortFunction);
     if (array_key_exists('state', $view->children) && $view->children['state']->vars['choice_translation_domain']) {
         usort($view->children['state']->vars['choices'], $sortFunction);
     }
     if (array_key_exists('city', $view->children) && $view->children['city']->vars['choice_translation_domain']) {
         usort($view->children['city']->vars['choices'], $sortFunction);
     }
 }
开发者ID:hackultura,项目名称:login-cidadao,代码行数:18,代码来源:CitySelectorComboType.php

示例12: onKernelView

 public function onKernelView(GetResponseForControllerResultEvent $event)
 {
     $request = $event->getRequest();
     if (!$this->isApiRequest($request)) {
         return;
     }
     // we now only use json, if more formats will be added, then it can check request uri or headers
     // and only presenter object allowed as controller result etc
     $data = $event->getControllerResult();
     switch (true) {
         case is_array($data):
         case $data instanceof JsonSerializable:
             $response = new JsonResponse($data);
             break;
         case is_string($data):
             $response = new Response($data);
             $response->headers->set('Content-Type', 'application/json');
             break;
         default:
             throw new \UnexpectedValueException("Response type: " . gettype($data) . " from controller was not expected.");
     }
     $response->headers->set('Language', $this->translator->getLocale());
     $event->setResponse($response);
 }
开发者ID:vaidasif,项目名称:symfony-force,代码行数:24,代码来源:ApiResponseListener.php

示例13: normalize

 /**
  * {@inheritdoc}
  */
 public function normalize($version, $format = null, array $context = [])
 {
     $context = ['locale' => $this->translator->getLocale()];
     return ['id' => $version->getId(), 'author' => $this->normalizeAuthor($version->getAuthor()), 'resource_id' => (string) $version->getResourceId(), 'snapshot' => $version->getSnapshot(), 'changeset' => $this->convertChangeset($version->getChangeset(), $context), 'context' => $version->getContext(), 'version' => $version->getVersion(), 'logged_at' => $this->datetimePresenter->present($version->getLoggedAt(), $context), 'pending' => $version->isPending()];
 }
开发者ID:a2xchip,项目名称:pim-community-dev,代码行数:8,代码来源:VersionNormalizer.php

示例14: __construct

 /**
  * @param MetaTitleRepository        $metaTitleRepo
  * @param BundleInformationInterface $bundleInfo
  * @param TranslatorInterface        $translator
  */
 public function __construct(MetaTitleRepository $metaTitleRepo, BundleInformationInterface $bundleInfo, TranslatorInterface $translator)
 {
     $this->setMetaTitleRepo($metaTitleRepo)->setLocale($translator->getLocale())->extractBundleParts($bundleInfo);
 }
开发者ID:scr-be,项目名称:mantle-bundle,代码行数:9,代码来源:TitleProvider.php

示例15: getAttributeInformationUrl

 /**
  * @return string
  */
 public function getAttributeInformationUrl()
 {
     return $this->attributeInformationUrls[$this->translator->getLocale()];
 }
开发者ID:OpenConext,项目名称:OpenConext-profile,代码行数:7,代码来源:GlobalViewParameters.php


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