/** * Returns the remaining locales sorted by language name * * @return array */ public function getRemainingViews() { $remainingViews = parent::getRemainingViews(); usort($remainingViews, function (ChoiceView $choiceView1, ChoiceView $choiceView2) { return \Collator::create(null)->compare($choiceView1->label, $choiceView2->label); }); return $remainingViews; }
/** * Opposite of testIsPrefix * * @dataProvider notPrefixDataProvider */ function testNotIsPrefix($lang, $base, $extended) { $cp = Collator::create($lang); $cp->setStrength(Collator::PRIMARY); $baseBin = $cp->getSortKey($base); // Remove sortkey terminator $baseBin = rtrim($baseBin, ""); $extendedBin = $cp->getSortKey($extended); $this->assertStringStartsNotWith($baseBin, $extendedBin, "{$base} is a prefix of {$extended}"); }
public function __construct($locale) { if (!extension_loaded('intl')) { throw new MWException('An ICU collation was requested, ' . 'but the intl extension is not available.'); } $this->locale = $locale; // Drop everything after the '@' in locale's name $localeParts = explode('@', $locale); $this->digitTransformLanguage = Language::factory($locale === 'root' ? 'en' : $localeParts[0]); $this->mainCollator = Collator::create($locale); if (!$this->mainCollator) { throw new MWException("Invalid ICU locale specified for collation: {$locale}"); } $this->primaryCollator = Collator::create($locale); $this->primaryCollator->setStrength(Collator::PRIMARY); }
public function __construct($name, $title = null, $source = null, $value = "", $form = null) { if (!is_array($source)) { // Get a list of countries from Zend $source = Zend_Locale::getTranslationList('territory', $this->locale(), 2); // We want them ordered by display name, not country code // PHP 5.3 has an extension that sorts UTF-8 strings correctly if (class_exists('Collator') && ($collator = Collator::create($this->locale()))) { $collator->asort($source); } else { asort($source); } // We don't want "unknown country" as an option unset($source['ZZ']); } parent::__construct($name, $title === null ? $name : $title, $source, $value, $form); }
public function setSource($source) { if ($source) { return parent::setSource($source); } // map empty source to country list // Get a list of countries from Zend $source = Zend_Locale::getTranslationList('territory', $this->locale(), 2); // We want them ordered by display name, not country code // PHP 5.3 has an extension that sorts UTF-8 strings correctly if (class_exists('Collator') && ($collator = Collator::create($this->locale()))) { $collator->asort($source); } else { // Otherwise just put up with them being weirdly ordered for now asort($source); } // We don't want "unknown country" as an option unset($source['ZZ']); return parent::setSource($source); }
public function __construct($name, $title = null, $source = null, $value = "", $form = null) { if (!is_array($source)) { // Get a list of countries from Zend $source = Zend_Locale::getTranslationList('territory', $this->locale(), 2); // We want them ordered by display name, not country code // PHP 5.3 has an extension that sorts UTF-8 strings correctly if (class_exists('Collator') && ($collator = Collator::create($this->locale()))) { $collator->asort($source); } else { asort($source); } // We don't want "unknown country" as an option unset($source['ZZ']); // We don't want a number of countries which have ceased to exist unset($source['SU']); // Soviet Union unset($source['BQ']); // British Antarctic Territory unset($source['CT']); // Canton and Enderbury Islands unset($source['NQ']); // Dronning Maud Land unset($source['FX']); // France, Metropolitan unset($source['FQ']); // French Southern and Antarctic Territories unset($source['NT']); // Iraq-Saudi-Arabia Neutral Zone unset($source['PZ']); // Panama Canal Zone unset($source['CS']); // Serbia and Montenegro } parent::__construct($name, $title === null ? $name : $title, $source, $value, $form); }
/** * @param string $path * @param array $pages * @param string $order_by * @param array $manual * * @throws \RuntimeException * @internal */ protected function buildSort($path, array $pages, $order_by = 'default', $manual = null) { $list = []; $header_default = null; $header_query = null; $sort_flags = SORT_NATURAL | SORT_FLAG_CASE; // do this header query work only once if (strpos($order_by, 'header.') === 0) { $header_query = explode('|', str_replace('header.', '', $order_by)); if (isset($header_query[1])) { $header_default = $header_query[1]; } } foreach ($pages as $key => $info) { $child = isset($this->instances[$key]) ? $this->instances[$key] : null; if (!$child) { throw new \RuntimeException("Page does not exist: {$key}"); } switch ($order_by) { case 'title': $list[$key] = $child->title(); break; case 'date': $list[$key] = $child->date(); $sort_flags = SORT_REGULAR; break; case 'modified': $list[$key] = $child->modified(); $sort_flags = SORT_REGULAR; break; case 'slug': $list[$key] = $child->slug(); break; case 'basename': $list[$key] = basename($key); break; case is_string($header_query[0]): $child_header = new Header((array) $child->header()); $header_value = $child_header->get($header_query[0]); if ($header_value) { $list[$key] = $header_value; } else { $list[$key] = $header_default ?: $key; } $sort_flags = SORT_REGULAR; break; case 'manual': case 'default': default: $list[$key] = $key; $sort_flags = SORT_REGULAR; } } // handle special case when order_by is random if ($order_by == 'random') { $list = $this->arrayShuffle($list); } else { // else just sort the list according to specified key if (extension_loaded('intl')) { $locale = setlocale(LC_COLLATE, 0); //`setlocale` with a 0 param returns the current locale set $col = \Collator::create($locale); if ($col) { $col->asort($list, $sort_flags); } else { asort($list, $sort_flags); } } else { asort($list, $sort_flags); } } // Move manually ordered items into the beginning of the list. Order of the unlisted items does not change. if (is_array($manual) && !empty($manual)) { $new_list = []; $i = count($manual); foreach ($list as $key => $dummy) { $info = $pages[$key]; $order = array_search($info['slug'], $manual); if ($order === false) { $order = $i++; } $new_list[$key] = (int) $order; } $list = $new_list; // Apply manual ordering to the list. asort($list); } foreach ($list as $key => $sort) { $info = $pages[$key]; $this->sort[$path][$order_by][$key] = $info; } }
function __construct($locale) { if (!extension_loaded('intl')) { throw new MWException('An ICU collation was requested, ' . 'but the intl extension is not available.'); } $this->locale = $locale; $this->mainCollator = Collator::create($locale); if (!$this->mainCollator) { throw new MWException("Invalid ICU locale specified for collation: {$locale}"); } $this->primaryCollator = Collator::create($locale); $this->primaryCollator->setStrength(Collator::PRIMARY); }
public function __construct($locale) { if (!extension_loaded('intl')) { throw new MWException('An ICU collation was requested, ' . 'but the intl extension is not available.'); } $this->locale = $locale; // Drop everything after the '@' in locale's name $localeParts = explode('@', $locale); $this->digitTransformLanguage = Language::factory($locale === 'root' ? 'en' : $localeParts[0]); $this->mainCollator = Collator::create($locale); if (!$this->mainCollator) { throw new MWException("Invalid ICU locale specified for collation: {$locale}"); } $this->primaryCollator = Collator::create($locale); $this->primaryCollator->setStrength(Collator::PRIMARY); // If the special suffix for numeric collation is present, turn on numeric collation. if (substr($locale, -5, 5) === '-u-kn') { $this->useNumericCollation = true; // Strip off the special suffix so it doesn't trip up fetchFirstLetterData(). $this->locale = substr($this->locale, 0, -5); $this->mainCollator->setAttribute(Collator::NUMERIC_COLLATION, Collator::ON); $this->primaryCollator->setAttribute(Collator::NUMERIC_COLLATION, Collator::ON); } }
function ut_coll_create($locale) { return $GLOBALS['oo-mode'] ? Collator::create($locale) : collator_create($locale); }
<?php use Karwana\Penelope\Types\Country; $countries = array(); foreach (Country::getCodes() as $code) { $countries[$code] = Country::getName($code, __locale()); } // Sort by country name using Unicode Collation Algorithm rules. $collator = \Collator::create('root'); uasort($countries, function ($a, $b) use($collator) { return $collator->compare($a, $b); }); if ($property->getSchema()->isMultiValue()) { foreach ((array) $property->getValue() as $value) { ?> <select name="<?php __(_e($property->getName())); ?> []"> <option value=""><?php __(_m('option_none')); ?> </option> <?php foreach ($countries as $code => $name) { ?> <option value="<?php __($code); ?> "<?php if (0 === strcasecmp($value, $code)) {