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


PHP Locale\Locale类代码示例

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


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

示例1: saveSettings

 /**
  * @Route("/admin/settings/save/{formType}", name="cuteflow_admin_settings_save")
  * @Template("CuteFlowCoreBundle:Admin:settings.html.twig")
  * 
  * @param string $formType
  * @return void
  */
 public function saveSettings($formType)
 {
     $em = $this->getDoctrine()->getEntityManager();
     $settings = $em->find('CuteFlowCoreBundle:Settings', 1);
     if ($settings == null) {
         $settings = new \CuteFlow\CoreBundle\Entity\Settings();
     }
     $localeNames = Locale::getDisplayLanguages($this->getRequest()->getSession()->getLocale());
     $availableLanguages = array_intersect_key($localeNames, $this->container->getParameter('cuteflow.languages'));
     $generalForm = $this->createForm(new SettingsGeneralType(), $settings);
     $emailForm = $this->createForm(new SettingsEmailType(), $settings);
     switch ($formType) {
         case 'email':
             $form = $emailForm;
             break;
         case 'general':
             $form = $generalForm;
             break;
     }
     $success = false;
     $form->bindRequest($this->getRequest());
     if ($form->isValid()) {
         $em->persist($settings);
         $em->flush();
         $success = true;
     }
     return array('generalForm' => $generalForm->createView(), 'emailForm' => $emailForm->createView(), 'availableLanguages' => $availableLanguages, 'formType' => $formType, 'saveSuccess' => $success, 'form' => $form->createView());
 }
开发者ID:robertowest,项目名称:CuteFlow-V4,代码行数:35,代码来源:AdminController.php

示例2: getDisplayLanguage

 /**
  * Get language name
  *
  * @param  string $code
  * @return string
  */
 public function getDisplayLanguage($code)
 {
     $languages = Locale::getDisplayLanguages($this->request->getLocale());
     if (isset($languages[$code])) {
         return $languages[$code];
     }
 }
开发者ID:yoye,项目名称:localizationbundle,代码行数:13,代码来源:Localizer.php

示例3: locale

 /**
  * @param $code
  * @param null $locale
  *
  * @return string
  */
 public function locale($code, $locale = null)
 {
     $locales = Locale::getDisplayLocales($locale ?: $this->localeDetector->getLocale());
     if (array_key_exists($code, $locales)) {
         return $this->fixCharset($locales[$code]);
     }
     return '';
 }
开发者ID:ingeniorweb,项目名称:symfo3cv,代码行数:14,代码来源:LocaleHelper.php

示例4: testGetDisplayLocalesReturnsFullListForSubLocale

 public function testGetDisplayLocalesReturnsFullListForSubLocale()
 {
     $this->skipIfIntlExtensionIsNotLoaded();
     $localesDe = Locale::getDisplayLocales('de');
     $localesDeCh = Locale::getDisplayLocales('de_CH');
     $this->assertEquals(count($localesDe), count($localesDeCh));
     $this->assertEquals($localesDe['be'], 'Weißrussisch');
     $this->assertEquals($localesDeCh['be'], 'Weissrussisch');
 }
开发者ID:nicodmf,项目名称:symfony,代码行数:9,代码来源:LocaleTest.php

示例5: renderArticleLocale

 /**
  * @param  \ServerGrove\KbBundle\Document\Article $article
  * @param  string                                 $locale
  * @return string
  */
 public function renderArticleLocale(Article $article, $locale)
 {
     try {
         $active = $this->manager->findTranslation(get_class($article), $article->getId(), $locale, false)->getIsActive();
     } catch (\InvalidArgumentException $e) {
         $active = false;
     }
     $this->manager->refresh($article);
     return $this->twig->renderBlock('article_locale', array('active' => $active, 'locale' => $locale, 'locale_name' => Locale::getDisplayLanguage($locale)));
 }
开发者ID:Cohros,项目名称:KnowledgeBase,代码行数:15,代码来源:ArticleExtension.php

示例6: validate

 /**
  * {@inheritDoc}
  */
 public function validate($value, Constraint $constraint)
 {
     if (null === $value || '' === $value) {
         return;
     }
     if (!is_scalar($value) && !(is_object($value) && method_exists($value, '__toString'))) {
         throw new UnexpectedTypeException($value, 'string');
     }
     $value = (string) $value;
     if (!in_array($value, \Symfony\Component\Locale\Locale::getLocales())) {
         $this->context->addViolation($constraint->message, array('{{ value }}' => $value));
     }
 }
开发者ID:joan16v,项目名称:symfony2_test,代码行数:16,代码来源:LocaleValidator.php

示例7: getIntlDateFormater

 /**
  *
  * @param type $format
  * @return \IntlDateFormatter
  * @throws Exception
  */
 protected function getIntlDateFormater($format)
 {
     if (\is_string($format)) {
         $format = \constant('\\IntlDateFormatter::' . \strtoupper($format));
     } else {
         if (!\is_numeric($format)) {
             throw new Exception('Format must be an string or IntlDateFormater Int Value');
         }
     }
     $locale = \Symfony\Component\Locale\Locale::getDefault();
     $tz = $this->userManager->getTimezone();
     $fmt = new \IntlDateFormatter($locale, $format, $format, $tz->getName(), \IntlDateFormatter::GREGORIAN);
     return $fmt;
 }
开发者ID:symbb,项目名称:symbb,代码行数:20,代码来源:IntlExtension.php

示例8: isValid

 public function isValid($value, Constraint $constraint)
 {
     if (null === $value || '' === $value) {
         return true;
     }
     if (!is_scalar($value) && !(is_object($value) && method_exists($value, '__toString()'))) {
         throw new UnexpectedTypeException($value, 'string');
     }
     $value = (string) $value;
     if (!in_array($value, \Symfony\Component\Locale\Locale::getLanguages())) {
         $this->setMessage($constraint->message, array('{{ value }}' => $value));
         return false;
     }
     return true;
 }
开发者ID:Gregwar,项目名称:symfony,代码行数:15,代码来源:LanguageValidator.php

示例9: __construct

 /**
  * Construct the LocaleChoiceList
  *
  * @param LocaleInformation $information   LocaleInformation Service
  * @param bool              $languagesOnly If only Languages should be displayed
  * @param bool              $strictMode    If strict mode
  */
 public function __construct(LocaleInformation $information, $languagesOnly = true, $strictMode = false)
 {
     $this->localeChoices = array();
     if ($strictMode) {
         $allowedLocales = $information->getAllowedLocalesFromConfiguration();
     } else {
         $allowedLocales = $information->getAllAllowedLanguages();
     }
     foreach ($allowedLocales as $locale) {
         if ($languagesOnly && strlen($locale) == 2 || !$languagesOnly) {
             $this->localeChoices[$locale] = Locale::getDisplayName($locale, $locale);
         }
     }
     $this->preferredChoices = $information->getPreferredLocales();
     parent::__construct($this->localeChoices, $this->preferredChoices);
 }
开发者ID:Sententiaregum,项目名称:LocaleBundle,代码行数:23,代码来源:LocaleChoiceList.php

示例10: getViewData

 /**
  * {@inheritDoc}
  */
 public function getViewData($request)
 {
     $user = $this->getUser();
     $widgets = array();
     $translator = $this->get('translator');
     // WYSIWYG
     $currentEditor = $this->container->get('adminUserPrefService')->getPrefForName($user->getId(), 'wysiwygEditor');
     $widgets[] = Beans::getBean('EditorSelectFormWidget#title=' . $translator->trans('Preferred Editor') . '&value=' . $currentEditor . '&name=wysiwygEditor');
     // uiLocale  (@todo fold into widget)
     $currentLocale = $this->container->get('adminUserPrefService')->getPrefForName($user->getId(), 'uiLocale');
     $locales = Locale::getDisplayLocales($currentLocale);
     $uiLocaleWidget = Beans::getBean('selectFormWidget#name=uiLocale&title=' . $translator->trans('Admin Locale') . '&value=' . $currentLocale);
     foreach ($locales as $locale => $name) {
         // @todo decide whether to show the localized names here at all.
         $uiLocaleWidget->addOption('(' . $locale . ') ' . $name, $locale);
     }
     $uiLocaleWidget->setValue($this->container->get('adminUserPrefService')->getPrefForName($user->getId(), 'uiLocale'));
     $widgets[] = $uiLocaleWidget;
     return array('widgets' => $widgets);
 }
开发者ID:zenmagick,项目名称:zenmagick,代码行数:23,代码来源:UpdateUserController.php

示例11: thereIsCountry

 /**
  * @Given /^I created country "([^""]*)"$/
  * @Given /^there is country "([^""]*)"$/
  */
 public function thereIsCountry($name, $provinces = null, $flush = true)
 {
     /* @var $country CountryInterface */
     if (null === ($country = $this->getRepository('country')->findOneBy(array('name' => $name)))) {
         $country = $this->getRepository('country')->createNew();
         $country->setName(trim($name));
         $country->setIsoName(array_search($name, Locale::getDisplayCountries(Locale::getDefault())));
         if (null !== $provinces) {
             $provinces = $provinces instanceof TableNode ? $provinces->getHash() : $provinces;
             foreach ($provinces as $provinceName) {
                 $country->addProvince($this->thereisProvince($provinceName));
             }
         }
         $manager = $this->getEntityManager();
         $manager->persist($country);
         if ($flush) {
             $manager->flush();
         }
     }
     return $country;
 }
开发者ID:bcremer,项目名称:Sylius,代码行数:25,代码来源:AddressingContext.php

示例12: addCustomProperty

 public function addCustomProperty(TransformEvent $event)
 {
     $object = $event->getObject();
     $document = $event->getDocument();
     $document->addGeoPoint('location', $object->getLat(), $object->getLng());
     if (!$object->getProvince()) {
         $locale = 'it';
         $countries = Locale::getDisplayCountries($locale);
         $country = $countries[$object->getCountry()];
         $address = $object->getAddress() . ' ' . $object->getTown() . ' ' . $country;
         try {
             $result = $this->geocode->using('google_maps')->reverse($object->getLat(), $object->getLng());
             $document->set('town', $result->getCity());
             $document->set('zipcode', $result->getZipcode());
             $document->set('province', $result->getCountyCode());
             $document->set('country', $result->getCountryCode());
             $document->set('address', $result->getStreetName() . ' ' . $result->getStreetNumber());
             $document->set('region', $result->getRegion());
         } catch (\Exception $e) {
             print $object->getId() . '::' . $e->getMessage() . "\n";
         }
     }
 }
开发者ID:arest,项目名称:metano_importer,代码行数:23,代码来源:DistributorListener.php

示例13: testGetLocales

 public function testGetLocales()
 {
     $locales = Locale::getLocales();
     $this->assertTrue(in_array('pt', $locales));
 }
开发者ID:d3ancole1995,项目名称:symfony,代码行数:5,代码来源:LocaleTest.php

示例14: getDefaultOptions

 /**
  * {@inheritdoc}
  */
 public function getDefaultOptions(array $options)
 {
     return array('choices' => Locale::getDisplayCountries(\Locale::getDefault()));
 }
开发者ID:artz20,项目名称:Tv-shows-zone,代码行数:7,代码来源:CountryType.php

示例15: setDefaultOptions

 /**
  * {@inheritdoc}
  */
 public function setDefaultOptions(OptionsResolverInterface $resolver)
 {
     $resolver->setDefaults(array('choices' => Locale::getDisplayLanguages(\Locale::getDefault())));
 }
开发者ID:laubosslink,项目名称:lab,代码行数:7,代码来源:LanguageType.php


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