Locale.php 10 KB

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