Locale.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323
  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\Intl\Locale;
  11. use Symfony\Component\Intl\Exception\MethodNotImplementedException;
  12. /**
  13. * Replacement for PHP's native {@link \Locale} class.
  14. *
  15. * The only method supported in this class is {@link getDefault}. This method
  16. * will always return "en". All other methods will throw an exception when used.
  17. *
  18. * @author Eriksen Costa <eriksen.costa@infranology.com.br>
  19. * @author Bernhard Schussek <bschussek@gmail.com>
  20. *
  21. * @internal
  22. */
  23. class Locale
  24. {
  25. const DEFAULT_LOCALE = null;
  26. /* Locale method constants */
  27. const ACTUAL_LOCALE = 0;
  28. const VALID_LOCALE = 1;
  29. /* Language tags constants */
  30. const LANG_TAG = 'language';
  31. const EXTLANG_TAG = 'extlang';
  32. const SCRIPT_TAG = 'script';
  33. const REGION_TAG = 'region';
  34. const VARIANT_TAG = 'variant';
  35. const GRANDFATHERED_LANG_TAG = 'grandfathered';
  36. const PRIVATE_TAG = 'private';
  37. /**
  38. * Not supported. Returns the best available locale based on HTTP "Accept-Language" header according to RFC 2616.
  39. *
  40. * @param string $header The string containing the "Accept-Language" header value
  41. *
  42. * @return string The corresponding locale code
  43. *
  44. * @see http://www.php.net/manual/en/locale.acceptfromhttp.php
  45. *
  46. * @throws MethodNotImplementedException
  47. */
  48. public static function acceptFromHttp($header)
  49. {
  50. throw new MethodNotImplementedException(__METHOD__);
  51. }
  52. /**
  53. * Not supported. Returns a correctly ordered and delimited locale code.
  54. *
  55. * @param array $subtags A keyed array where the keys identify the particular locale code subtag
  56. *
  57. * @return string The corresponding locale code
  58. *
  59. * @see http://www.php.net/manual/en/locale.composelocale.php
  60. *
  61. * @throws MethodNotImplementedException
  62. */
  63. public static function composeLocale(array $subtags)
  64. {
  65. throw new MethodNotImplementedException(__METHOD__);
  66. }
  67. /**
  68. * Not supported. Checks if a language tag filter matches with locale.
  69. *
  70. * @param string $langtag The language tag to check
  71. * @param string $locale The language range to check against
  72. * @param bool $canonicalize
  73. *
  74. * @return string The corresponding locale code
  75. *
  76. * @see http://www.php.net/manual/en/locale.filtermatches.php
  77. *
  78. * @throws MethodNotImplementedException
  79. */
  80. public static function filterMatches($langtag, $locale, $canonicalize = false)
  81. {
  82. throw new MethodNotImplementedException(__METHOD__);
  83. }
  84. /**
  85. * Not supported. Returns the variants for the input locale.
  86. *
  87. * @param string $locale The locale to extract the variants from
  88. *
  89. * @return array The locale variants
  90. *
  91. * @see http://www.php.net/manual/en/locale.getallvariants.php
  92. *
  93. * @throws MethodNotImplementedException
  94. */
  95. public static function getAllVariants($locale)
  96. {
  97. throw new MethodNotImplementedException(__METHOD__);
  98. }
  99. /**
  100. * Returns the default locale.
  101. *
  102. * @return string The default locale code. Always returns 'en'
  103. *
  104. * @see http://www.php.net/manual/en/locale.getdefault.php
  105. */
  106. public static function getDefault()
  107. {
  108. return 'en';
  109. }
  110. /**
  111. * Not supported. Returns the localized display name for the locale language.
  112. *
  113. * @param string $locale The locale code to return the display language from
  114. * @param string $inLocale Optional format locale code to use to display the language name
  115. *
  116. * @return string The localized language display name
  117. *
  118. * @see http://www.php.net/manual/en/locale.getdisplaylanguage.php
  119. *
  120. * @throws MethodNotImplementedException
  121. */
  122. public static function getDisplayLanguage($locale, $inLocale = null)
  123. {
  124. throw new MethodNotImplementedException(__METHOD__);
  125. }
  126. /**
  127. * Not supported. Returns the localized display name for the locale.
  128. *
  129. * @param string $locale The locale code to return the display locale name from
  130. * @param string $inLocale Optional format locale code to use to display the locale name
  131. *
  132. * @return string The localized locale display name
  133. *
  134. * @see http://www.php.net/manual/en/locale.getdisplayname.php
  135. *
  136. * @throws MethodNotImplementedException
  137. */
  138. public static function getDisplayName($locale, $inLocale = null)
  139. {
  140. throw new MethodNotImplementedException(__METHOD__);
  141. }
  142. /**
  143. * Not supported. Returns the localized display name for the locale region.
  144. *
  145. * @param string $locale The locale code to return the display region from
  146. * @param string $inLocale Optional format locale code to use to display the region name
  147. *
  148. * @return string The localized region display name
  149. *
  150. * @see http://www.php.net/manual/en/locale.getdisplayregion.php
  151. *
  152. * @throws MethodNotImplementedException
  153. */
  154. public static function getDisplayRegion($locale, $inLocale = null)
  155. {
  156. throw new MethodNotImplementedException(__METHOD__);
  157. }
  158. /**
  159. * Not supported. Returns the localized display name for the locale script.
  160. *
  161. * @param string $locale The locale code to return the display script from
  162. * @param string $inLocale Optional format locale code to use to display the script name
  163. *
  164. * @return string The localized script display name
  165. *
  166. * @see http://www.php.net/manual/en/locale.getdisplayscript.php
  167. *
  168. * @throws MethodNotImplementedException
  169. */
  170. public static function getDisplayScript($locale, $inLocale = null)
  171. {
  172. throw new MethodNotImplementedException(__METHOD__);
  173. }
  174. /**
  175. * Not supported. Returns the localized display name for the locale variant.
  176. *
  177. * @param string $locale The locale code to return the display variant from
  178. * @param string $inLocale Optional format locale code to use to display the variant name
  179. *
  180. * @return string The localized variant display name
  181. *
  182. * @see http://www.php.net/manual/en/locale.getdisplayvariant.php
  183. *
  184. * @throws MethodNotImplementedException
  185. */
  186. public static function getDisplayVariant($locale, $inLocale = null)
  187. {
  188. throw new MethodNotImplementedException(__METHOD__);
  189. }
  190. /**
  191. * Not supported. Returns the keywords for the locale.
  192. *
  193. * @param string $locale The locale code to extract the keywords from
  194. *
  195. * @return array Associative array with the extracted variants
  196. *
  197. * @see http://www.php.net/manual/en/locale.getkeywords.php
  198. *
  199. * @throws MethodNotImplementedException
  200. */
  201. public static function getKeywords($locale)
  202. {
  203. throw new MethodNotImplementedException(__METHOD__);
  204. }
  205. /**
  206. * Not supported. Returns the primary language for the locale.
  207. *
  208. * @param string $locale The locale code to extract the language code from
  209. *
  210. * @return string|null The extracted language code or null in case of error
  211. *
  212. * @see http://www.php.net/manual/en/locale.getprimarylanguage.php
  213. *
  214. * @throws MethodNotImplementedException
  215. */
  216. public static function getPrimaryLanguage($locale)
  217. {
  218. throw new MethodNotImplementedException(__METHOD__);
  219. }
  220. /**
  221. * Not supported. Returns the region for the locale.
  222. *
  223. * @param string $locale The locale code to extract the region code from
  224. *
  225. * @return string|null The extracted region code or null if not present
  226. *
  227. * @see http://www.php.net/manual/en/locale.getregion.php
  228. *
  229. * @throws MethodNotImplementedException
  230. */
  231. public static function getRegion($locale)
  232. {
  233. throw new MethodNotImplementedException(__METHOD__);
  234. }
  235. /**
  236. * Not supported. Returns the script for the locale.
  237. *
  238. * @param string $locale The locale code to extract the script code from
  239. *
  240. * @return string|null The extracted script code or null if not present
  241. *
  242. * @see http://www.php.net/manual/en/locale.getscript.php
  243. *
  244. * @throws MethodNotImplementedException
  245. */
  246. public static function getScript($locale)
  247. {
  248. throw new MethodNotImplementedException(__METHOD__);
  249. }
  250. /**
  251. * Not supported. Returns the closest language tag for the locale.
  252. *
  253. * @param array $langtag A list of the language tags to compare to locale
  254. * @param string $locale The locale to use as the language range when matching
  255. * @param bool $canonicalize If true, the arguments will be converted to canonical form before matching
  256. * @param string $default The locale to use if no match is found
  257. *
  258. * @see http://www.php.net/manual/en/locale.lookup.php
  259. *
  260. * @throws MethodNotImplementedException
  261. */
  262. public static function lookup(array $langtag, $locale, $canonicalize = false, $default = null)
  263. {
  264. throw new MethodNotImplementedException(__METHOD__);
  265. }
  266. /**
  267. * Not supported. Returns an associative array of locale identifier subtags.
  268. *
  269. * @param string $locale The locale code to extract the subtag array from
  270. *
  271. * @return array Associative array with the extracted subtags
  272. *
  273. * @see http://www.php.net/manual/en/locale.parselocale.php
  274. *
  275. * @throws MethodNotImplementedException
  276. */
  277. public static function parseLocale($locale)
  278. {
  279. throw new MethodNotImplementedException(__METHOD__);
  280. }
  281. /**
  282. * Not supported. Sets the default runtime locale.
  283. *
  284. * @param string $locale The locale code
  285. *
  286. * @return bool true on success or false on failure
  287. *
  288. * @see http://www.php.net/manual/en/locale.setdefault.php
  289. *
  290. * @throws MethodNotImplementedException
  291. */
  292. public static function setDefault($locale)
  293. {
  294. if ('en' !== $locale) {
  295. throw new MethodNotImplementedException(__METHOD__);
  296. }
  297. return true;
  298. }
  299. }