public function detect() { if (session_status() === PHP_SESSION_ACTIVE && isset($_SESSION[self::$fieldName]) && !empty($_SESSION[self::$fieldName])) { return collator_create($_SESSION[self::$fieldName]); } return null; }
public function detect() { if (isset($_COOKIE[self::$fieldName]) && !empty($_COOKIE[self::$fieldName])) { return collator_create($_COOKIE[self::$fieldName]); } return null; }
protected function _getLocaleFromTld($tld) { if (isset(self::$locales[$tld])) { return collator_create(self::$locales[$tld]); } return null; }
public function detect() { if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) && !empty($_SERVER['HTTP_ACCEPT_LANGUAGE'])) { $locale = locale_accept_from_http($_SERVER['HTTP_ACCEPT_LANGUAGE']); if ($locale !== null) { return collator_create($locale); } } return null; }
public function testMyCallback() { $localeDetector = new Menencia\LocaleDetector\LocaleDetector(); $localeDetector->addCallback('MyCallback', function ($a) { return collator_create($a); }, ['fr_FR']); $localeDetector->setOrder(['MyCallback']); $locale = $localeDetector->detect(); $this->assertEquals('fr_FR', $locale); }
/** * @return null|string */ public function detect() { $i = 0; while ($i < count($this->_order) && self::$current == NULL) { $strategy = $this->_order[$i]; $locale = $this->_strategies[$strategy]; $this->setLocale($locale); $i++; } if (self::$current == NULL) { $this->setLocale(collator_create(\Locale::getDefault())); } return $this->getLocale(); }
<?php $coll = collator_create('en_US'); $result = collator_compare($coll, "string#1", "string#2");
/** * Returns an instance of Collator class (ICU) created for a specified language. This collator treats substrings of digits as numbers. * @param string $language (optional) Language indentificator. If it is omited, the current interface language is assumed. * @return object Returns a instance of Collator class that is suitable for alpha-numerical comparisons. */ function _api_get_alpha_numerical_collator($language = null) { static $collator = array(); if (empty($language)) { $language = api_get_interface_language(); } if (!isset($collator[$language])) { $locale = _api_get_locale_from_language($language); $collator[$language] = collator_create($locale); if (is_object($collator[$language])) { collator_set_attribute($collator[$language], Collator::CASE_FIRST, Collator::UPPER_FIRST); collator_set_attribute($collator[$language], Collator::NUMERIC_COLLATION, Collator::ON); } } return $collator[$language]; }
private static function getCollator($locale) { return collator_create($locale); }
function ut_coll_create($locale) { return $GLOBALS['oo-mode'] ? Collator::create($locale) : collator_create($locale); }
/** * Locale aware sorting, the key associations are kept, values are sorted alphabetically. * @param array $arr array to be sorted * @param string $lang moodle language * @return void, modifies parameter */ function asort(array &$arr) { if (function_exists('collator_asort')) { $coll = collator_create(get_string('locale', 'langconfig')); collator_asort($coll, $arr); } else { asort($arr, SORT_LOCALE_STRING); } }
}); if (empty($diff)) { // The duplicates are not removed right away because they might // still be needed for other duplicate checks (for example, // when there are locales like bs-Latn-BA, bs-Latn, bs). $duplicates[] = $locale; } } } // Remove the duplicates. foreach ($duplicates as $locale) { unset($languages[$locale]); } // Write out the localizations. foreach ($languages as $locale => $localizedLanguages) { $collator = collator_create($locale); uasort($localizedLanguages, function ($a, $b) use($collator) { return collator_compare($collator, $a['name'], $b['name']); }); file_put_json($locale . '.json', $localizedLanguages); } /** * Converts the provided data into json and writes it to the disk. */ function file_put_json($filename, $data) { $data = json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE); // Indenting with tabs instead of 4 spaces gives us 20% smaller files. $data = str_replace(' ', "\t", $data); file_put_contents($filename, $data); }
function sortArray($testArray) { $coll = collator_create('fr_FR'); $coll->sort($testArray); return $testArray; }
/** * Load and return a collator instance. * * @return \Collator */ protected static function getCollator() { if (!self::$collator) { self::$collator = collator_create('root'); } return self::$collator; }