/**
  * @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());
 }
Example #2
0
 /**
  * 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];
     }
 }
Example #3
0
 /**
  * @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 '';
 }
Example #4
0
 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');
 }
 /**
  * @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)));
 }
 /**
  * {@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));
     }
 }
Example #7
0
 /**
  *
  * @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;
 }
Example #8
0
 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;
 }
 /**
  * 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);
 }
 /**
  * {@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);
 }
Example #11
0
 /**
  * @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;
 }
 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";
         }
     }
 }
Example #13
0
 public function testGetLocales()
 {
     $locales = Locale::getLocales();
     $this->assertTrue(in_array('pt', $locales));
 }
Example #14
0
 /**
  * {@inheritdoc}
  */
 public function getDefaultOptions(array $options)
 {
     return array('choices' => Locale::getDisplayCountries(\Locale::getDefault()));
 }
Example #15
0
 /**
  * {@inheritdoc}
  */
 public function setDefaultOptions(OptionsResolverInterface $resolver)
 {
     $resolver->setDefaults(array('choices' => Locale::getDisplayLanguages(\Locale::getDefault())));
 }
 /**
  * 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;
 }
 /**
  * @param $key
  * @return mixed
  */
 public function country($key)
 {
     $countries = Locale::getDisplayCountries($this->app['locale']);
     return $countries[$key];
 }
Example #18
0
 /**
  * @inheritDoc
  */
 protected function configure()
 {
     $this->addOption('choices', Locale::getDisplayLanguages($this->locale));
     parent::configure();
 }
Example #19
0
 public function countryFilter($countryCode, $locale = "en")
 {
     $c = \Symfony\Component\Locale\Locale::getDisplayCountries($locale);
     return array_key_exists($countryCode, $c) ? $c[$countryCode] : $countryCode;
 }
Example #20
0
 /**
  * {@inheritdoc}
  */
 public function getCountryLanguages($language)
 {
     return $this->locale->getDisplayLanguages($language);
 }
 /**
  * Display language
  *
  * @return string
  */
 public function displayLanguage()
 {
     return Locale::getDisplayLanguage($this->getLang());
 }
Example #22
0
 /**
  * {@inheritdoc}
  */
 public function getDefaultOptions(array $options)
 {
     return array('choices' => Locale::getDisplayLocales(\Locale::getDefault()), 'value_strategy' => ChoiceList::COPY_CHOICE);
 }
Example #23
0
 /**
  * Returns the stub ICU data
  *
  * @param string $locale        The locale code
  * @param string $cacheVariable The name of a static attribute to cache the data to
  * @param string $stubDataDir   The stub data directory name
  *
  * @return array
  *
  * @throws \InvalidArgumentException  When the locale is different than 'en'
  */
 private static function getStubData($locale, $cacheVariable, $stubDataDir)
 {
     $dataDirectory = Locale::getIcuDataDirectory();
     if ('en' !== $locale) {
         throw new \InvalidArgumentException(sprintf('Only the \'en\' locale is supported. %s', NotImplementedException::INTL_INSTALL_MESSAGE));
     }
     if (empty(self::${$cacheVariable})) {
         self::${$cacheVariable} = (include $dataDirectory . '/stub/' . $stubDataDir . '/en.php');
     }
     return self::${$cacheVariable};
 }
Example #24
0
 /**
  * {@inheritdoc}
  */
 public function getDefaultOptions()
 {
     return array('choices' => Locale::getDisplayLanguages(\Locale::getDefault()));
 }
Example #25
0
 /**
  * Returns the locale names for locale
  *
  * @return array The locale names with their codes as keys
  */
 public function getDisplayLocales()
 {
     return SymfonyLocale::getDisplayLocales($this->getLocale());
 }
 /**
  * Translate a country indicator to its locale full name
  * Uses default system locale by default. Pass another locale string to force a different translation
  *
  * @param string $country The contry indicator
  * @param string $default The default value is the country does not exist (optionnal)
  * @param mixed $locale
  * 
  * @return string The localized string
  * @access public
  * @static
  * 
  * @author Etienne de Longeaux <*****@*****.**>
  */
 public function countryFilter($country, $default = '', $locale = null)
 {
     $locale = $locale == null ? \Locale::getDefault() : $locale;
     $countries = Locale::getDisplayCountries($locale);
     return array_key_exists($country, $countries) ? $countries[$country] : $default;
 }
 private function localizeName($name, $locale = null)
 {
     return ($locale or $locale = Locale::getDefault()) ? $name . '.' . $locale : $name;
 }
 protected function configure()
 {
     $this->addOption('choices', Locale::getDisplayCountries(\Locale::getDefault()));
     parent::configure();
 }
Example #29
0
 public function testGetLocales()
 {
     $locales = Locale::getLocales();
     $this->assertContains('pt', $locales);
 }
 public function getLocales()
 {
     return json_encode(\Symfony\Component\Locale\Locale::getLocales());
 }