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


PHP Locale::getRegion方法代码示例

本文整理汇总了PHP中Locale::getRegion方法的典型用法代码示例。如果您正苦于以下问题:PHP Locale::getRegion方法的具体用法?PHP Locale::getRegion怎么用?PHP Locale::getRegion使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Locale的用法示例。


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

示例1: addLineItemAction

 public function addLineItemAction(Request $request)
 {
     $locale = $this->get('commercetools.locale.converter')->convert($request->getLocale());
     $session = $this->get('session');
     $form = $this->createForm(AddToCartType::class, ['variantIdText' => true]);
     $form->handleRequest($request);
     if ($form->isValid() && $form->isSubmitted()) {
         $productId = $form->get('productId')->getData();
         $variantId = (int) $form->get('variantId')->getData();
         $quantity = (int) $form->get('quantity')->getData();
         $slug = $form->get('slug')->getData();
         $cartId = $session->get(CartRepository::CART_ID);
         $country = \Locale::getRegion($locale);
         $currency = $this->getParameter('commercetools.currency.' . $country);
         /**
          * @var CartRepository $repository
          */
         $repository = $this->get('commercetools.repository.cart');
         $repository->addLineItem($request->getLocale(), $cartId, $productId, $variantId, $quantity, $currency, $country, $this->getCustomerId());
         $redirectUrl = $this->generateUrl('_ctp_example_product', ['slug' => $slug]);
     } else {
         $redirectUrl = $this->generateUrl('_ctp_example');
     }
     return new RedirectResponse($redirectUrl);
 }
开发者ID:sphereio,项目名称:commercetools-php-symfony,代码行数:25,代码来源:CartController.php

示例2: _getOptionLocales

 /**
  * Get options array for locale dropdown
  *
  * @param   bool $translatedName translation flag
  * @return  array
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  */
 protected function _getOptionLocales($translatedName = false)
 {
     $currentLocale = $this->localeResolver->getLocale();
     $locales = \ResourceBundle::getLocales('') ?: [];
     $languages = (new LanguageBundle())->get($currentLocale)['Languages'];
     $countries = (new RegionBundle())->get($currentLocale)['Countries'];
     $options = [];
     $allowedLocales = $this->_config->getAllowedLocales();
     foreach ($locales as $locale) {
         if (!in_array($locale, $allowedLocales)) {
             continue;
         }
         $language = \Locale::getPrimaryLanguage($locale);
         $country = \Locale::getRegion($locale);
         if (!$languages[$language] || !$countries[$country]) {
             continue;
         }
         if ($translatedName) {
             $label = ucwords(\Locale::getDisplayLanguage($locale, $locale)) . ' (' . \Locale::getDisplayRegion($locale, $locale) . ') / ' . $languages[$language] . ' (' . $countries[$country] . ')';
         } else {
             $label = $languages[$language] . ' (' . $countries[$country] . ')';
         }
         $options[] = ['value' => $locale, 'label' => $label];
     }
     return $this->_sortOptionArray($options);
 }
开发者ID:vasiljok,项目名称:magento2,代码行数:33,代码来源:TranslatedLists.php

示例3: add

 public function add(Request $request)
 {
     $session = $this->get('session');
     // TODO: enable if product add form has a csrf token
     //        if (!$this->validateCsrfToken(static::CSRF_TOKEN_FORM, $request->get(static::CSRF_TOKEN_NAME))) {
     //            throw new \InvalidArgumentException('CSRF Token invalid');
     //        }
     $productId = $request->get('productId');
     $variantId = (int) $request->get('variantId');
     $quantity = (int) $request->get('quantity');
     $sku = $request->get('productSku');
     $slug = $request->get('productSlug');
     $cartId = $session->get('cartId');
     $country = \Locale::getRegion($this->locale);
     $currency = $this->config->get('currencies.' . $country);
     $cart = $this->get('app.repository.cart')->addLineItem($cartId, $productId, $variantId, $quantity, $currency, $country);
     $session->set('cartId', $cart->getId());
     $session->set('cartNumItems', $this->getItemCount($cart));
     $session->save();
     if (empty($sku)) {
         $redirectUrl = $this->generateUrl('pdp-master', ['slug' => $slug]);
     } else {
         $redirectUrl = $this->generateUrl('pdp', ['slug' => $slug, 'sku' => $sku]);
     }
     return new RedirectResponse($redirectUrl);
 }
开发者ID:sphereio,项目名称:commercetools-sunrise-php,代码行数:26,代码来源:CartController.php

示例4: getNameForValidNumber

 /**
  * Returns a carrier name for the given phone number, in the language provided. The carrier name
  * is the one the number was originally allocated to, however if the country supports mobile
  * number portability the number might not belong to the returned carrier anymore. If no mapping
  * is found an empty string is returned.
  *
  * <p>This method assumes the validity of the number passed in has already been checked, and that
  * the number is suitable for carrier lookup. We consider mobile and pager numbers possible
  * candidates for carrier lookup.
  *
  * @param PhoneNumber $number a valid phone number for which we want to get a carrier name
  * @param string $languageCode the language code in which the name should be written
  * @return string a carrier name for the given phone number
  */
 public function getNameForValidNumber(PhoneNumber $number, $languageCode)
 {
     $languageStr = \Locale::getPrimaryLanguage($languageCode);
     $scriptStr = "";
     $regionStr = \Locale::getRegion($languageCode);
     return $this->prefixFileReader->getDescriptionForNumber($number, $languageStr, $scriptStr, $regionStr);
 }
开发者ID:wasabiNorman,项目名称:libphonenumber-for-php,代码行数:21,代码来源:PhoneNumberToCarrierMapper.php

示例5: geocode

 public function geocode($ipAddress)
 {
     $region = \Locale::getRegion($this->getLocale());
     $countryName = \Locale::getDisplayRegion($this->getLocale(), 'en');
     $countryCode = \Locale::getRegion($this->getLocale());
     if ($countryCode == '') {
         throw new NoResult(sprintf('No results found for IP address "%s".', $ipAddress));
     }
     return $this->returnResults([$this->fixEncoding(array_merge($this->getDefaults(), array('country' => $countryName, 'countryCode' => $countryCode)))]);
 }
开发者ID:ThaDafinser,项目名称:Piwik-GeoIpChain,代码行数:10,代码来源:BrowserLocale.php

示例6: getLocaleList

 /**
  * Retrieve list of locales
  *
  * @return  array
  */
 public function getLocaleList()
 {
     $languages = (new LanguageBundle())->get(Resolver::DEFAULT_LOCALE)['Languages'];
     $countries = (new RegionBundle())->get(Resolver::DEFAULT_LOCALE)['Countries'];
     $locales = \ResourceBundle::getLocales('') ?: [];
     $list = [];
     foreach ($locales as $locale) {
         if (!in_array($locale, $this->allowedLocales)) {
             continue;
         }
         $language = \Locale::getPrimaryLanguage($locale);
         $country = \Locale::getRegion($locale);
         if (!$languages[$language] || !$countries[$country]) {
             continue;
         }
         $list[$locale] = $languages[$language] . ' (' . $countries[$country] . ')';
     }
     asort($list);
     return $list;
 }
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:25,代码来源:Lists.php

示例7: validate

 /**
  * Validates a Locale
  *
  * @param string     $locale     The locale to be validated
  * @param Constraint $constraint Locale Constraint
  *
  * @throws \Symfony\Component\Validator\Exception\UnexpectedTypeException
  */
 public function validate($locale, Constraint $constraint)
 {
     if (null === $locale || '' === $locale) {
         return;
     }
     if (!is_scalar($locale) && !(is_object($locale) && method_exists($locale, '__toString'))) {
         throw new UnexpectedTypeException($locale, 'string');
     }
     $locale = (string) $locale;
     if ($this->intlExtension) {
         $primary = \Locale::getPrimaryLanguage($locale);
         $region = \Locale::getRegion($locale);
         $locales = Intl::getLocaleBundle()->getLocales();
         if (null !== $region && strtolower($primary) != strtolower($region) && !in_array($locale, $locales) && !in_array($primary, $locales)) {
             $this->context->addViolation($constraint->message, array('%string%' => $locale));
         }
     } else {
         $splittedLocale = explode('_', $locale);
         $splitCount = count($splittedLocale);
         if ($splitCount == 1) {
             $primary = $splittedLocale[0];
             if (!in_array($primary, $this->iso639)) {
                 $this->context->addViolation($constraint->message, array('%string%' => $locale));
             }
         } elseif ($splitCount == 2) {
             $primary = $splittedLocale[0];
             $region = $splittedLocale[1];
             if (!in_array($primary, $this->iso639) && !in_array($region, $this->iso3166)) {
                 $this->context->addViolation($constraint->message, array('%string%' => $locale));
             }
         } elseif ($splitCount > 2) {
             $primary = $splittedLocale[0];
             $script = $splittedLocale[1];
             $region = $splittedLocale[2];
             if (!in_array($primary, $this->iso639) && !in_array($region, $this->iso3166) && !in_array($script, $this->script)) {
                 $this->context->addViolation($constraint->message, array('%string%' => $locale));
             }
         }
     }
 }
开发者ID:Sententiaregum,项目名称:LocaleBundle,代码行数:48,代码来源:LocaleValidator.php

示例8: getValueOptions

 /**
  * @return array
  */
 public function getValueOptions()
 {
     if (empty($this->valueOptions)) {
         $this->valueOptions = array();
         $enabledLocales = $this->getServiceLocator()->get('Locale')->getAvailableFlags();
         if ($this->onlyEnabledLocales) {
             $enabledLocales = array_filter($enabledLocales);
         }
         foreach ($enabledLocales as $locale => $enabled) {
             $main = IntlLocale::getPrimaryLanguage($locale);
             $sub = IntlLocale::getRegion($locale);
             $mainKey = 'locale.main.' . $main;
             $localeKey = 'locale.sub.' . $locale;
             if (!empty($this->valueOptions[$mainKey])) {
                 $this->valueOptions[$mainKey]['options'][$locale] = $localeKey;
             } elseif (!$sub && empty($this->valueOptions[$locale])) {
                 $this->valueOptions[$locale] = $mainKey;
             } else {
                 if ($sub && !empty($this->valueOptions[$main])) {
                     $this->valueOptions[$mainKey]['options'] = array($main => 'locale.sub.' . $main);
                     unset($this->valueOptions[$main]);
                 }
                 $this->valueOptions[$mainKey]['options'][$locale] = $localeKey;
                 $this->valueOptions[$mainKey]['label'] = $mainKey;
             }
         }
         foreach ($this->valueOptions as &$valueGroup) {
             if (is_array($valueGroup) && isset($valueGroup['options']) && is_array($valueGroup['options'])) {
                 ksort($valueGroup['options']);
             }
         }
         $first = reset($this->valueOptions);
         if (count($this->valueOptions) === 1 && is_array($first) && !empty($first['options'])) {
             $this->valueOptions = $first['options'];
         }
     }
     return parent::getValueOptions();
 }
开发者ID:gridguyz,项目名称:zork,代码行数:41,代码来源:LocaleTrait.php

示例9: getCountryCode

 /**
  * Returns the ISO code of the country according to locale
  *
  * @return Locale 2-letter ISO code
  */
 public function getCountryCode()
 {
     $localeIso = $this->locale->getIso();
     if (isset($this->localeCountryAssociations[$localeIso])) {
         return Locale::create($this->localeCountryAssociations[$localeIso]);
     }
     $regionLocale = \Locale::getRegion($localeIso);
     return $regionLocale ? Locale::create($regionLocale) : $this->locale;
 }
开发者ID:axelvnk,项目名称:elcodi,代码行数:14,代码来源:LocaleManager.php

示例10: regionCode

 /**
  * Returns the country/region code of a locale.
  *
  * @return CUStringObject The locale's two-letter country/region code (always uppercased).
  */
 public function regionCode()
 {
     assert('$this->hasRegionCode()', vs(isset($this), get_defined_vars()));
     return Locale::getRegion($this->m_name);
 }
开发者ID:nunodotferreira,项目名称:Phred,代码行数:10,代码来源:CULocale.php

示例11: getDescriptionForValidNumber

 /**
  * Returns a text description for the given phone number, in the language provided. The
  * description might consist of the name of the country where the phone number is from, or the
  * name of the geographical area the phone number is from if more detailed information is
  * available.
  *
  * <p>This method assumes the validity of the number passed in has already been checked, and that
  * the number is suitable for geocoding. We consider fixed-line and mobile numbers possible
  * candidates for geocoding.
  *
  * <p>If $userRegion is set, we also consider the region of the user. If the phone number is from
  * the same region as the user, only a lower-level description will be returned, if one exists.
  * Otherwise, the phone number's region will be returned, with optionally some more detailed
  * information.
  *
  * <p>For example, for a user from the region "US" (United States), we would show "Mountain View,
  * CA" for a particular number, omitting the United States from the description. For a user from
  * the United Kingdom (region "GB"), for the same number we may show "Mountain View, CA, United
  * States" or even just "United States".
  *
  * @param PhoneNumber $number a valid phone number for which we want to get a text description
  * @param string $locale the language code for which the description should be written
  * @param string $userRegion the region code for a given user. This region will be omitted from the
  *     description if the phone number comes from this region. It is a two-letter uppercase ISO
  *     country code as defined by ISO 3166-1.
  * @return string a text description for the given language code for the given phone number
  */
 public function getDescriptionForValidNumber(PhoneNumber $number, $locale, $userRegion = null)
 {
     // If the user region matches the number's region, then we just show the lower-level
     // description, if one exists - if no description exists, we will show the region(country) name
     // for the number.
     $regionCode = $this->phoneUtil->getRegionCodeForNumber($number);
     if ($userRegion == null || $userRegion == $regionCode) {
         $languageStr = Locale::getPrimaryLanguage($locale);
         $scriptStr = "";
         $regionStr = Locale::getRegion($locale);
         $mobileToken = $this->phoneUtil->getCountryMobileToken($number->getCountryCode());
         $nationalNumber = $this->phoneUtil->getNationalSignificantNumber($number);
         if ($mobileToken !== "" && !strncmp($nationalNumber, $mobileToken, strlen($mobileToken))) {
             // In some countries, eg. Argentina, mobile numbers have a mobile token before the national
             // destination code, this should be removed before geocoding.
             $nationalNumber = substr($nationalNumber, strlen($mobileToken));
             $region = $this->phoneUtil->getRegionCodeForCountryCode($number->getCountryCode());
             try {
                 $copiedNumber = $this->phoneUtil->parse($nationalNumber, $region);
             } catch (NumberParseException $e) {
                 // If this happens, just reuse what we had.
                 $copiedNumber = $number;
             }
             $areaDescription = $this->prefixFileReader->getDescriptionForNumber($copiedNumber, $languageStr, $scriptStr, $regionStr);
         } else {
             $areaDescription = $this->prefixFileReader->getDescriptionForNumber($number, $languageStr, $scriptStr, $regionStr);
         }
         return strlen($areaDescription) > 0 ? $areaDescription : $this->getCountryNameForNumber($number, $locale);
     }
     // Otherwise, we just show the region(country) name for now.
     return $this->getRegionDisplayName($regionCode, $locale);
     // TODO: Concatenate the lower-level and country-name information in an appropriate
     // way for each language.
 }
开发者ID:ayurmedia,项目名称:faveo-helpdesk,代码行数:61,代码来源:PhoneNumberOfflineGeocoder.php

示例12: prepareDisplayProperties

 private function prepareDisplayProperties($lang)
 {
     $locale = $this->config->findLocaleByLanguage($lang);
     $nameOfLanguage = \Locale::getDisplayName($lang, $locale);
     $nameOfCountry = \Locale::getDisplayLanguage($lang, \Locale::getDefault());
     $countryCode = \Locale::getRegion($locale);
     return [$nameOfLanguage, $nameOfCountry, $countryCode];
 }
开发者ID:omusico,项目名称:zf2-demo,代码行数:8,代码来源:LanguagesSwitcher.php

示例13: getRegion

 /**
  * Gets the region for the input locale
  *
  * @return string The region subtag for the locale or NULL if not present
  */
 public function getRegion()
 {
     return IntlLocale::getRegion($this->getLocale());
 }
开发者ID:ledgr,项目名称:localefacade,代码行数:9,代码来源:LocaleFacade.php

示例14: getDefaultCountry

 public function getDefaultCountry()
 {
     $defaultCountry = $this->container->getParameter('form.type.location.defaultCountry');
     if (false === $defaultCountry) {
         $defaultCountry = '';
     } else {
         if (empty($defaultCountry)) {
             $defaultCountry = \Locale::getRegion($this->container->get('request')->getLocale());
         }
     }
     return $defaultCountry;
 }
开发者ID:nmariani,项目名称:bootstrapp-bundle,代码行数:12,代码来源:LocationType.php

示例15: foreach

foreach ($translatedLocales as $translatedLocale) {
    // Don't include ICU's root resource bundle
    if ($translatedLocale === 'root') {
        continue;
    }
    $langBundle = load_resource_bundle($translatedLocale, $langDir);
    $regionBundle = load_resource_bundle($translatedLocale, $regionDir);
    $localeNames = array();
    foreach ($supportedLocales as $supportedLocale) {
        // Don't include ICU's root resource bundle
        if ($supportedLocale === 'root') {
            continue;
        }
        $lang = \Locale::getPrimaryLanguage($supportedLocale);
        $script = \Locale::getScript($supportedLocale);
        $region = \Locale::getRegion($supportedLocale);
        $variants = \Locale::getAllVariants($supportedLocale);
        // Currently the only available variant is POSIX, which we don't want
        // to include in the list
        if (count($variants) > 0) {
            continue;
        }
        $langName = $langBundle->get('Languages')->get($lang);
        $extras = array();
        // Some languages are simply not translated
        // Example: "az" (Azerbaijani) has no translation in "af" (Afrikaans)
        if (!$langName) {
            continue;
        }
        // "af" (Afrikaans) has no "Scripts" block
        if (!$langBundle->get('Scripts')) {
开发者ID:ronaldlunaramos,项目名称:webstore,代码行数:31,代码来源:build-data.php


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