本文整理汇总了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());
}
示例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];
}
}
示例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 '';
}
示例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');
}
示例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)));
}
示例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));
}
}
示例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;
}
示例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;
}
示例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);
}
示例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);
}
示例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;
}
示例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";
}
}
}
示例13: testGetLocales
public function testGetLocales()
{
$locales = Locale::getLocales();
$this->assertTrue(in_array('pt', $locales));
}
示例14: getDefaultOptions
/**
* {@inheritdoc}
*/
public function getDefaultOptions(array $options)
{
return array('choices' => Locale::getDisplayCountries(\Locale::getDefault()));
}
示例15: setDefaultOptions
/**
* {@inheritdoc}
*/
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$resolver->setDefaults(array('choices' => Locale::getDisplayLanguages(\Locale::getDefault())));
}