IcuLocaleBundle.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\Icu;
  11. use Symfony\Component\Intl\ResourceBundle\LocaleBundle;
  12. use Symfony\Component\Intl\ResourceBundle\Reader\StructuredBundleReaderInterface;
  13. /**
  14. * An ICU-specific implementation of {@link \Symfony\Component\Intl\ResourceBundle\LocaleBundleInterface}.
  15. *
  16. * This class normalizes the data of the ICU .res files to satisfy the contract
  17. * defined in {@link \Symfony\Component\Intl\ResourceBundle\LocaleBundleInterface}.
  18. *
  19. * @author Bernhard Schussek <bschussek@gmail.com>
  20. */
  21. class IcuLocaleBundle extends LocaleBundle
  22. {
  23. public function __construct(StructuredBundleReaderInterface $reader)
  24. {
  25. parent::__construct(realpath(IcuData::getResourceDirectory() . '/locales'), $reader);
  26. }
  27. /**
  28. * {@inheritdoc}
  29. */
  30. public function getLocaleNames($locale = null)
  31. {
  32. if (null === $locale) {
  33. $locale = \Locale::getDefault();
  34. }
  35. $locales = parent::getLocaleNames($locale);
  36. $collator = new \Collator($locale);
  37. $collator->asort($locales);
  38. return $locales;
  39. }
  40. }