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


PHP Collator::getLocale方法代码示例

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


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

示例1: ensure_collator_available

 /**
  * Ensures that a collator is available and created
  *
  * @return bool Returns true if collation is available and ready
  */
 protected static function ensure_collator_available()
 {
     $locale = get_string('locale', 'langconfig');
     if (is_null(self::$collator) || $locale != self::$locale) {
         self::$collator = false;
         self::$locale = $locale;
         if (class_exists('Collator', false)) {
             $collator = new Collator($locale);
             if (!empty($collator) && $collator instanceof Collator) {
                 // Check for non fatal error messages. This has to be done immediately
                 // after instantiation as any further calls to collation will cause
                 // it to reset to 0 again (or another error code if one occurred)
                 $errorcode = $collator->getErrorCode();
                 $errormessage = $collator->getErrorMessage();
                 // Check for an error code, 0 means no error occurred
                 if ($errorcode !== 0) {
                     // Get the actual locale being used, e.g. en, he, zh
                     $localeinuse = $collator->getLocale(Locale::ACTUAL_LOCALE);
                     // Check for the common fallback warning error codes. If any of the two
                     // following errors occurred, there is normally little to worry about:
                     // * U_USING_FALLBACK_WARNING (-128) indicates that a fall back locale was
                     //   used. For example, 'de_CH' was requested, but nothing was found
                     //   there, so 'de' was used.
                     // * U_USING_DEFAULT_WARNING (-127) indicates that the default locale
                     //   data was used; neither the requested locale nor any of its fall
                     //   back locales could be found. For example, 'pt' was requested, but
                     //   UCA was used (Unicode Collation Algorithm http://unicode.org/reports/tr10/).
                     // See http://www.icu-project.org/apiref/icu4c/classicu_1_1ResourceBundle.html
                     if ($errorcode === -127 || $errorcode === -128) {
                         // Check if the locale in use is UCA default one ('root') or
                         // if it is anything like the locale we asked for
                         if ($localeinuse !== 'root' && strpos($locale, $localeinuse) !== 0) {
                             // The locale we asked for is completely different to the locale
                             // we have received, let the user know via debugging
                             debugging('Locale warning (not fatal) ' . $errormessage . ': ' . 'Requested locale "' . $locale . '" not found, locale "' . $localeinuse . '" used instead. ' . 'The most specific locale supported by ICU relatively to the requested locale is "' . $collator->getLocale(Locale::VALID_LOCALE) . '".');
                         } else {
                             // Nothing to do here, this is expected!
                             // The Moodle locale setting isn't what the collator expected but
                             // it is smart enough to match the first characters of our locale
                             // to find the correct locale or to use UCA collation
                         }
                     } else {
                         // We've received some other sort of non fatal warning - let the
                         // user know about it via debugging.
                         debugging('Problem with locale: ' . $errormessage . '. ' . 'Requested locale: "' . $locale . '", actual locale "' . $localeinuse . '". ' . 'The most specific locale supported by ICU relatively to the requested locale is "' . $collator->getLocale(Locale::VALID_LOCALE) . '".');
                     }
                 }
                 // Store the collator object now that we can be sure it is in a workable condition
                 self::$collator = $collator;
             } else {
                 // Fatal error while trying to instantiate the collator... something went wrong
                 debugging('Error instantiating collator for locale: "' . $locale . '", with error [' . intl_get_error_code() . '] ' . intl_get_error_message($collator));
             }
         }
     }
     return self::$collator instanceof Collator;
 }
开发者ID:EmmanuelYupit,项目名称:educursos,代码行数:62,代码来源:collator.php

示例2: ensure_collator_available

 /**
  * Ensures that a collator is available and created
  *
  * @return bool Returns true if collation is available and ready
  */
 protected static function ensure_collator_available()
 {
     $locale = get_string('locale', 'langconfig');
     if (is_null(self::$collator) || $locale != self::$locale) {
         self::$collator = false;
         self::$locale = $locale;
         if (class_exists('Collator', false)) {
             $collator = new Collator($locale);
             if (!empty($collator) && $collator instanceof Collator) {
                 // Check for non fatal error messages. This has to be done immediately
                 // after instantiation as any further calls to collation will cause
                 // it to reset to 0 again (or another error code if one occurred)
                 $errorcode = $collator->getErrorCode();
                 $errormessage = $collator->getErrorMessage();
                 // Check for an error code, 0 means no error occurred
                 if ($errorcode !== 0) {
                     // Get the actual locale being used, e.g. en, he, zh
                     $localeinuse = $collator->getLocale(Locale::ACTUAL_LOCALE);
                     // Check for the common fallback warning error codes. If this occurred
                     // there is normally little to worry about:
                     // - U_USING_DEFAULT_WARNING (127)  - default fallback locale used (pt => UCA)
                     // - U_USING_FALLBACK_WARNING (128) - fallback locale used (de_CH => de)
                     // (UCA: Unicode Collation Algorithm http://unicode.org/reports/tr10/)
                     if ($errorcode === -127 || $errorcode === -128) {
                         // Check if the locale in use is UCA default one ('root') or
                         // if it is anything like the locale we asked for
                         if ($localeinuse !== 'root' && strpos($locale, $localeinuse) !== 0) {
                             // The locale we asked for is completely different to the locale
                             // we have received, let the user know via debugging
                             debugging('Invalid locale: "' . $locale . '", with warning (not fatal) "' . $errormessage . '", falling back to "' . $collator->getLocale(Locale::VALID_LOCALE) . '"');
                         } else {
                             // Nothing to do here, this is expected!
                             // The Moodle locale setting isn't what the collator expected but
                             // it is smart enough to match the first characters of our locale
                             // to find the correct locale or to use UCA collation
                         }
                     } else {
                         // We've received some other sort of non fatal warning - let the
                         // user know about it via debugging.
                         debugging('Problem with locale: "' . $locale . '", with message "' . $errormessage . '", falling back to "' . $collator->getLocale(Locale::VALID_LOCALE) . '"');
                     }
                 }
                 // Store the collator object now that we can be sure it is in a workable condition
                 self::$collator = $collator;
             } else {
                 // Fatal error while trying to instantiate the collator... something went wrong
                 debugging('Error instantiating collator for locale: "' . $locale . '", with error [' . intl_get_error_code() . '] ' . intl_get_error_message($collator));
             }
         }
     }
     return self::$collator instanceof Collator;
 }
开发者ID:eamador,项目名称:moodle-course-custom-fields,代码行数:57,代码来源:collator.php

示例3: getLocale

 /**
  * Get locale used by collator
  *
  * @return string
  */
 public function getLocale()
 {
     return $this->collator->getLocale(\Locale::VALID_LOCALE);
 }
开发者ID:phpextra,项目名称:sorter,代码行数:9,代码来源:UnicodeComparator.php


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