本文整理汇总了PHP中Symfony\Component\Intl\Intl::getLocaleBundle方法的典型用法代码示例。如果您正苦于以下问题:PHP Intl::getLocaleBundle方法的具体用法?PHP Intl::getLocaleBundle怎么用?PHP Intl::getLocaleBundle使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\Intl\Intl
的用法示例。
在下文中一共展示了Intl::getLocaleBundle方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: validate
/**
* {@inheritdoc}
*/
public function validate($value, Constraint $constraint)
{
if (!$constraint instanceof Locale) {
throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\Locale');
}
if (null === $value || '' === $value) {
return;
}
if (!is_scalar($value) && !(is_object($value) && method_exists($value, '__toString'))) {
throw new UnexpectedTypeException($value, 'string');
}
$value = (string) $value;
$locales = Intl::getLocaleBundle()->getLocaleNames();
if (!isset($locales[$value])) {
if ($this->context instanceof ExecutionContextInterface) {
$this->context->buildViolation($constraint->message)
->setParameter('{{ value }}', $this->formatValue($value))
->setCode(Locale::NO_SUCH_LOCALE_ERROR)
->addViolation();
} else {
$this->buildViolation($constraint->message)
->setParameter('{{ value }}', $this->formatValue($value))
->setCode(Locale::NO_SUCH_LOCALE_ERROR)
->addViolation();
}
}
}
示例2: getName
/**
* @return string
*/
public function getName($locale = null)
{
$enc = 'utf-8';
$names = Intl::getLocaleBundle()->getLocaleNames($locale ?: $this->locale);
$str = isset($names[$this->locale]) ? $names[$this->locale] : $this->locale;
return mb_strtoupper(mb_substr($str, 0, 1, $enc), $enc) . mb_substr($str, 1, mb_strlen($str, $enc), $enc);
}
示例3: configureOptions
/**
* {@inheritdoc}
*/
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(array(
'choices' => Intl::getLocaleBundle()->getLocaleNames(),
'choice_translation_domain' => false,
));
}
示例4: guard
/**
* @param mixed $value
*
* @throws InvalidLocaleException
*/
protected function guard($value)
{
$localeName = Intl::getLocaleBundle()->getLocaleName($value);
if (null === $localeName) {
throw new InvalidLocaleException($value);
}
}
示例5: loadChoiceList
/**
* {@inheritdoc}
*/
public function loadChoiceList($value = null)
{
if (null !== $this->choiceList) {
return $this->choiceList;
}
return $this->choiceList = new ArrayChoiceList(array_flip(Intl::getLocaleBundle()->getLocaleNames()), $value);
}
示例6: prettyLocaleName
/**
* Display the name of a locale by its code, like English (United States) when you provide en_US
*
* @param string $code
*
* @return string
*/
public function prettyLocaleName($code)
{
if (empty($code)) {
return '';
}
return Intl::getLocaleBundle()->getLocaleName($code);
}
示例7: getGlobals
public function getGlobals()
{
$locales = array('current' => null, 'other' => null);
$enabledLocales = $this->localeRepository->findBy(array('isEnabled' => true));
$otherLocales = $enabledLocales;
if (count($enabledLocales)) {
/** @var Locale $locale */
foreach ($enabledLocales as $localeKey => $locale) {
if ($this->currentLocale == $locale->getCode()) {
$locales['current'] = $locale;
unset($otherLocales[$localeKey]);
break;
}
}
}
if (!count($enabledLocales) || empty($locales['current'])) {
$defaultLocaleCode = $this->container->getParameter('locale');
$locale = new Locale();
$locale->setCode($defaultLocaleCode);
$locale->setTitle(Intl::getLocaleBundle()->getLocaleName($defaultLocaleCode, $defaultLocaleCode));
$locales['current'] = $locale;
}
$locales['other'] = $otherLocales;
return array('locales' => $locales);
}
示例8: getLocales
/**
* @return array
*/
public function getLocales()
{
$localeCodes = explode('|', $this->locales);
foreach ($localeCodes as $localeCode) {
$locales[] = array('code' => $localeCode, 'name' => Intl::getLocaleBundle()->getLocaleName($localeCode, $localeCode));
}
return $locales;
}
示例9: createMenu
/**
* Builds frontend locale menu.
*
* @return ItemInterface
*/
public function createMenu()
{
$menu = $this->factory->createItem('root', array('childrenAttributes' => array('class' => 'nav nav-pills')));
foreach ($this->localeProvider->getAvailableLocales() as $locale) {
$code = $locale->getCode();
$menu->addChild($code, array('route' => 'sylius_locale_change', 'routeParameters' => array('locale' => $code)))->setLabel(Intl::getLocaleBundle()->getLocaleName($code));
}
return $menu;
}
示例10: getLocaleNames
/**
* {@inheritdoc}
*/
public function getLocaleNames()
{
$locales = Intl::getLocaleBundle()->getLocaleNames();
$Data = [];
foreach ($locales as $locale => $name) {
$Data[$locale] = sprintf('%s (%s)', $name, $locale);
}
return $Data;
}
示例11: load
/**
* @param ObjectManager $manager
*/
public function load(ObjectManager $manager)
{
$localeSettings = $this->container->get('oro_locale.settings');
$locale = new Locale();
$locale->setCode(Intl::getLocaleBundle()->getLocaleName($localeSettings->getLanguage(), $localeSettings->getLocale()));
$manager->persist($locale);
/** @var EntityManager $manager */
$manager->flush($locale);
$this->addReference('default_website_locale', $locale);
}
示例12: getAvailableLocales
/**
* Should be private, used public to support PHP 5.3
*
* @internal
*
* @return array
*/
public function getAvailableLocales()
{
$availableLocales = Intl::getLocaleBundle()->getLocaleNames();
/** @var LocaleInterface[] $definedLocales */
$definedLocales = $this->localeRepository->findAll();
foreach ($definedLocales as $locale) {
unset($availableLocales[$locale->getCode()]);
}
return $availableLocales;
}
示例13: beforeRender
protected function beforeRender()
{
parent::beforeRender();
$this->template->parameters = $this->context->parameters;
$this->template->acl = $this->acl;
$this->template->addFilter('langName', function ($locale) {
return Intl::getLocaleBundle()->getLocaleName($locale);
});
$this->template->projects = $this->projectFacade->findAll();
}
示例14: doLoad
/**
* {@inheritdoc}
*/
protected function doLoad(ObjectManager $manager)
{
$defaultCode = $this->getContainer()->getParameter('lug.locale');
foreach (array_keys(Intl::getLocaleBundle()->getLocaleNames()) as $code) {
$locale = $this->getFactory()->create(['code' => $code, 'enabled' => $code === $defaultCode, 'required' => $code === $defaultCode]);
$manager->persist($locale);
$this->setReference('lug.locale.' . $code, $locale);
}
$manager->flush();
}
示例15: getLanguageChoices
/**
* @return array
*/
protected function getLanguageChoices()
{
// ensure that default value is always in choice list
$defaultValue = $this->cm->get(self::CONFIG_KEY, true);
$availableTranslations = (array) $this->cm->get(TranslationStatusInterface::CONFIG_KEY);
$availableTranslations = array_filter($availableTranslations, function ($languageStatus) {
return $languageStatus === TranslationStatusInterface::STATUS_ENABLED;
});
$availableLanguages = array_merge(array_keys($availableTranslations), [$defaultValue]);
$allLanguages = Intl::getLocaleBundle()->getLocaleNames('en');
return array_intersect_key($allLanguages, array_flip($availableLanguages));
}