PageRenderTime 40ms CodeModel.GetById 13ms RepoModel.GetById 1ms app.codeStats 0ms

/vendor/symfony/symfony/src/Symfony/Component/Locale/Locale.php

https://gitlab.com/Isaki/le331.fr
PHP | 195 lines | 66 code | 22 blank | 107 comment | 4 complexity | 0e2b44ebf4491f1f2fccdeec543dd453 MD5 | raw file
  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\Locale;
  11. @trigger_error('The '.__NAMESPACE__.'\Locale class is deprecated since version 2.7, to be removed in Symfony 3.0. Use the methods provided by the \Symfony\Component\Intl\Intl class instead.', E_USER_DEPRECATED);
  12. use Symfony\Component\Intl\Intl;
  13. /**
  14. * Helper class for dealing with locale strings.
  15. *
  16. * @author Bernhard Schussek <bschussek@gmail.com>
  17. *
  18. * @deprecated since version 2.3, to be removed in 3.0.
  19. * Use {@link \Locale} and {@link \Symfony\Component\Intl\Intl} instead.
  20. */
  21. class Locale extends \Locale
  22. {
  23. /**
  24. * Caches the countries in different locales.
  25. *
  26. * @var array
  27. */
  28. protected static $countries = array();
  29. /**
  30. * Caches the languages in different locales.
  31. *
  32. * @var array
  33. */
  34. protected static $languages = array();
  35. /**
  36. * Caches the different locales.
  37. *
  38. * @var array
  39. */
  40. protected static $locales = array();
  41. /**
  42. * Returns the country names for a locale.
  43. *
  44. * @param string $locale The locale to use for the country names
  45. *
  46. * @return array The country names with their codes as keys
  47. *
  48. * @throws \RuntimeException When the resource bundles cannot be loaded
  49. */
  50. public static function getDisplayCountries($locale)
  51. {
  52. if (!isset(self::$countries[$locale])) {
  53. self::$countries[$locale] = Intl::getRegionBundle()->getCountryNames($locale);
  54. }
  55. return self::$countries[$locale];
  56. }
  57. /**
  58. * Returns all available country codes.
  59. *
  60. * @return array The country codes
  61. *
  62. * @throws \RuntimeException When the resource bundles cannot be loaded
  63. */
  64. public static function getCountries()
  65. {
  66. return array_keys(self::getDisplayCountries(self::getDefault()));
  67. }
  68. /**
  69. * Returns the language names for a locale.
  70. *
  71. * @param string $locale The locale to use for the language names
  72. *
  73. * @return array The language names with their codes as keys
  74. *
  75. * @throws \RuntimeException When the resource bundles cannot be loaded
  76. */
  77. public static function getDisplayLanguages($locale)
  78. {
  79. if (!isset(self::$languages[$locale])) {
  80. self::$languages[$locale] = Intl::getLanguageBundle()->getLanguageNames($locale);
  81. }
  82. return self::$languages[$locale];
  83. }
  84. /**
  85. * Returns all available language codes.
  86. *
  87. * @return array The language codes
  88. *
  89. * @throws \RuntimeException When the resource bundles cannot be loaded
  90. */
  91. public static function getLanguages()
  92. {
  93. return array_keys(self::getDisplayLanguages(self::getDefault()));
  94. }
  95. /**
  96. * Returns the locale names for a locale.
  97. *
  98. * @param string $locale The locale to use for the locale names
  99. *
  100. * @return array The locale names with their codes as keys
  101. *
  102. * @throws \RuntimeException When the resource bundles cannot be loaded
  103. */
  104. public static function getDisplayLocales($locale)
  105. {
  106. if (!isset(self::$locales[$locale])) {
  107. self::$locales[$locale] = Intl::getLocaleBundle()->getLocaleNames($locale);
  108. }
  109. return self::$locales[$locale];
  110. }
  111. /**
  112. * Returns all available locale codes.
  113. *
  114. * @return array The locale codes
  115. *
  116. * @throws \RuntimeException When the resource bundles cannot be loaded
  117. */
  118. public static function getLocales()
  119. {
  120. return array_keys(self::getDisplayLocales(self::getDefault()));
  121. }
  122. /**
  123. * Returns the ICU version as defined by the intl extension.
  124. *
  125. * @return string|null The ICU version
  126. */
  127. public static function getIntlIcuVersion()
  128. {
  129. return Intl::getIcuVersion();
  130. }
  131. /**
  132. * Returns the ICU Data version as defined by the intl extension.
  133. *
  134. * @return string|null The ICU Data version
  135. */
  136. public static function getIntlIcuDataVersion()
  137. {
  138. return Intl::getIcuDataVersion();
  139. }
  140. /**
  141. * Returns the ICU data version that ships with Symfony. If the environment variable USE_INTL_ICU_DATA_VERSION is
  142. * defined, it will try use the ICU data version as defined by the intl extension, if available.
  143. *
  144. * @return string The ICU data version that ships with Symfony
  145. */
  146. public static function getIcuDataVersion()
  147. {
  148. return Intl::getIcuDataVersion();
  149. }
  150. /**
  151. * Returns the directory path of the ICU data that ships with Symfony.
  152. *
  153. * @return string The path to the ICU data directory
  154. */
  155. public static function getIcuDataDirectory()
  156. {
  157. return Intl::getDataDirectory();
  158. }
  159. /**
  160. * Returns the fallback locale for a given locale, if any.
  161. *
  162. * @param string $locale The locale to find the fallback for.
  163. *
  164. * @return string|null The fallback locale, or null if no parent exists
  165. */
  166. protected static function getFallbackLocale($locale)
  167. {
  168. if (false === $pos = strrpos($locale, '_')) {
  169. return;
  170. }
  171. return substr($locale, 0, $pos);
  172. }
  173. }