php Symfony-Component-Locale-Locale类(方法)实例源码

下面列出了php Symfony-Component-Locale-Locale 类(方法)源码代码实例,从而了解它的用法。

作者:robertowes    项目:CuteFlow-V   
/**
  * @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());
 }

作者:yoy    项目:localizationbundl   
/**
  * 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];
     }
 }

作者:ingeniorwe    项目:symfo3c   
/**
  * @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 '';
 }

作者:nicodm    项目:symfon   
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');
 }

作者:Cohro    项目:KnowledgeBas   
/**
  * @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)));
 }

作者:joan16    项目:symfony2_tes   
/**
  * {@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));
     }
 }

作者:symb    项目:symb   
/**
  *
  * @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;
 }

作者:Gregwa    项目:symfon   
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;
 }

作者:Sententiaregu    项目:LocaleBundl   
/**
  * 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);
 }

作者:zenmagic    项目:zenmagic   
/**
  * {@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);
 }

作者:bcreme    项目:Syliu   
/**
  * @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;
 }

作者:ares    项目:metano_importe   
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";
         }
     }
 }

作者:d3ancole199    项目:symfon   
public function testGetLocales()
 {
     $locales = Locale::getLocales();
     $this->assertTrue(in_array('pt', $locales));
 }

作者:artz2    项目:Tv-shows-zon   
/**
  * {@inheritdoc}
  */
 public function getDefaultOptions(array $options)
 {
     return array('choices' => Locale::getDisplayCountries(\Locale::getDefault()));
 }

作者:laubosslin    项目:la   
/**
  * {@inheritdoc}
  */
 public function setDefaultOptions(OptionsResolverInterface $resolver)
 {
     $resolver->setDefaults(array('choices' => Locale::getDisplayLanguages(\Locale::getDefault())));
 }

作者:rubensaysh    项目:BCCExtraToolsBundl   
/**
  * Translate a country indicator to its locale full name
  * @param string $country The contry indicator
  * @param string $default The default value is the country does not exist (optionnal)
  * @return string The localized string
  */
 public static function countryFilter($country, $default = '')
 {
     $countries = Locale::getDisplayCountries(\Locale::getDefault());
     
     return array_key_exists($country, $countries) ? $countries[$country] : $default;
 }

作者:nym    项目:silex-twig-country-extensio   
/**
  * @param $key
  * @return mixed
  */
 public function country($key)
 {
     $countries = Locale::getDisplayCountries($this->app['locale']);
     return $countries[$key];
 }

作者:rosstuc    项目:Po   
/**
  * @inheritDoc
  */
 protected function configure()
 {
     $this->addOption('choices', Locale::getDisplayLanguages($this->locale));
     parent::configure();
 }

作者:est11    项目:lion-mirro   
public function countryFilter($countryCode, $locale = "en")
 {
     $c = \Symfony\Component\Locale\Locale::getDisplayCountries($locale);
     return array_key_exists($countryCode, $c) ? $c[$countryCode] : $countryCode;
 }

作者:bendavie    项目:LexikMailerBundl   
/**
  * Display language
  *
  * @return string
  */
 public function displayLanguage()
 {
     return Locale::getDisplayLanguage($this->getLang());
 }


问题


面经


文章

微信
公众号

扫码关注公众号