locale_api.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434
  1. <?php
  2. /**
  3. * A "Locale" is an identifier used to get language, culture, or regionally-specific
  4. * behavior from an API. PHP locales are organized and identified the same
  5. * way that the CLDR locales used by ICU (and many vendors of Unix-like operating
  6. * systems, the Mac, Java, and so forth) use. Locales are identified using
  7. * RFC 4646 language tags (which use hyphen, not underscore) in addition to the
  8. * more traditional underscore-using identifiers. Unless otherwise noted
  9. * the functions in this class are tolerant of both formats.
  10. *
  11. * Examples of identifiers include:
  12. *
  13. * * en-US (English, United States)
  14. * * zh-Hant-TW (Chinese, Traditional Script, Taiwan)
  15. * * fr-CA, fr-FR (French for Canada and France respectively)
  16. *
  17. * The Locale class (and related procedural functions) are used to interact
  18. * with locale identifiers--to verify that an ID is well-formed, valid,
  19. * etc. The extensions used by CLDR in UAX #35 (and inherited by ICU) are
  20. * valid and used wherever they would be in ICU normally.
  21. *
  22. * Locales cannot be instantiated as objects. All of the functions/methods
  23. * provided are static.
  24. *
  25. * * The null or empty string obtains the "root" locale.
  26. * The "root" locale is equivalent to "en_US_POSIX" in CLDR.
  27. * * Language tags (and thus locale identifiers) are case insensitive. There
  28. * exists a canonicalization function to make case match the specification.
  29. *
  30. * @see http://www.icu-project.org/apiref/icu4c/uloc_8h.html
  31. * @see http://www.unicode.org/reports/tr35/
  32. *
  33. */
  34. class Locale {
  35. #############################################################################
  36. # Common constants.
  37. #############################################################################
  38. /**
  39. * The following static members are used with the getLocale methods of
  40. * the various locale affected classes, such as numfmt.
  41. */
  42. const DEFAULT_LOCALE = null;
  43. /**
  44. * identifiers for the actual locale, valid locale
  45. * WARNING:
  46. * The values described here are NOT the actual values in PHP code.
  47. * They are references to the ICU C definitions, so the line
  48. * const ACTUAL_LOCALE = 'ULOC_ACTUAL_LOCALE';
  49. * actually means that Locale::ACTUAL_LOCALE is the same as
  50. * ULOC_ACTUAL_LOCALE constant in the ICU library.
  51. */
  52. const ACTUAL_LOCALE = 'ULOC_ACTUAL_LOCALE';
  53. const VALID_LOCALE = 'ULOC_VALID_LOCALE';
  54. /**
  55. * Valid locale tag and subtag values
  56. */
  57. const LANG_TAG = "language";
  58. const EXTLANG_TAG = "extlang";
  59. const SCRIPT_TAG = "script";
  60. const REGION_TAG = "region";
  61. const VARIANT_TAG = "variant";
  62. const GRANDFATHERED_LANG_TAG = "grandfathered";
  63. const PRIVATE_TAG = "private";
  64. #############################################################################
  65. # Object-oriented API
  66. #############################################################################
  67. /**
  68. * Gets the default locale value from the INTL global 'default_locale'
  69. * At the PHP initilaization (MINIT) this value is set to
  70. * 'intl.default_locale' value from php.ini if that value exists
  71. * or from ICU's function uloc_getDefault()
  72. * Then onwards picks up changes from setDefault() calls also
  73. *
  74. * @return string the current runtime locale
  75. */
  76. public static function getDefault() {}
  77. /**
  78. * sets the default runtime locale to $locale
  79. * This changes the value of INTL global 'default_locale'
  80. *
  81. * @param string $locale is a BCP 47 compliant language tag containing the
  82. * locale identifier. UAX #35 extensions are accepted.
  83. * @return boolean 'true' if okay, 'false' if an error
  84. */
  85. public static function setDefault($locale) {}
  86. /**
  87. * Gets the primary language for the input locale
  88. *
  89. * @param string $locale the locale to extract the primary language code from
  90. * @return string the language code associated with the language
  91. * or null in case of error.
  92. */
  93. public static function getPrimaryLanguage($locale) {}
  94. /**
  95. * Gets the script for the input locale
  96. *
  97. * @param string $locale the locale to extract the script code from
  98. * @return string the script subtag for the locale or null if not present
  99. */
  100. public static function getScript($locale) {}
  101. /**
  102. * Gets the region for the input locale
  103. *
  104. * @param string $locale the locale to extract the region code from
  105. * @return string the region subtag for the locale or null if not present
  106. */
  107. public static function getRegion($locale) {}
  108. /**
  109. * Gets the variants for the input locale
  110. *
  111. * @param string $locale the locale to extract the variants from
  112. * @return array the array containing the list of all variants
  113. * subtag for the locale or null if not present
  114. */
  115. public static function getAllVariants($locale) {}
  116. /**
  117. * Gets the keywords for the input locale
  118. *
  119. * @param string $locale the locale to extract the keywords from
  120. * @return array associative array containing the keyword-value pairs for this locale
  121. */
  122. public static function getKeywords($locale) {}
  123. /**
  124. * Returns an appropriately localized display name for the input locale
  125. *
  126. * @param string $locale the locale to return a displayname for
  127. * @param [string] $in_locale optional format locale
  128. * If is 'null' then the default locale is used.
  129. * @return string display name of the locale in the format
  130. * appropriate for $in_locale.
  131. */
  132. public static function getDisplayName($locale, $in_locale = null) {}
  133. /**
  134. * Returns an appropriately localized display name for language of the input locale
  135. *
  136. * @param string $locale the locale to return a display language for
  137. * @param [string] $in_locale optional format locale to use to display the language name
  138. * If is 'null' then the default locale is used.
  139. * @return string display name of the language for the $locale in the format
  140. * appropriate for $in_locale.
  141. */
  142. public static function getDisplayLanguage($lang, $in_locale = null) {}
  143. /**
  144. * Returns an appropriately localized display name for script of the input locale
  145. *
  146. * @param string $locale the locale to return a display script for
  147. * @param [string] $in_locale optional format locale to use to display the script name
  148. * If is 'null' then the default locale is used.
  149. * @return string display name of the script for the $locale in the format
  150. * appropriate for $in_locale.
  151. */
  152. public static function getDisplayScript($script, $in_locale = null) {}
  153. /**
  154. * Returns an appropriately localized display name for region of the input locale
  155. *
  156. * @param string $locale the locale to return a display region for
  157. * @param [string] $in_locale optional format locale to use to display the region name
  158. * If is 'null' then the default locale is used.
  159. * @return string display name of the region for the $locale in the format
  160. * appropriate for $in_locale.
  161. */
  162. public static function getDisplayRegion($region, $in_locale = null) {}
  163. /**
  164. * Returns an appropriately localized display name for variants of the input locale
  165. *
  166. * @param string $locale the locale to return a display variant for
  167. * @param [string] $in_locale optional format locale to use to display the variant name
  168. * If is 'null' then the default locale is used.
  169. * @return string display name of the variant for the $locale in the format
  170. * appropriate for $in_locale.
  171. */
  172. public static function getDisplayVariant($variant, $in_locale = null) {}
  173. /**
  174. * Checks if a $langtag filter matches with $locale according to
  175. * RFC 4647's basic filtering algorithm
  176. *
  177. * @param string $langtag the language tag to check
  178. * @param string $locale the language range to check against
  179. * @param bool $canonicalize Canonicalize parameters?
  180. * @return boolean 'true' if $locale matches $langtag 'false' otherwise
  181. */
  182. public static function filterMatches($langtag, $locale, $canonicalize) {}
  183. /**
  184. * Searchs the items in $langtag for the best match to the language
  185. * range specified in $locale according to RFC 4647's lookup algorithm.
  186. *
  187. * @param array $langtag an array containing a list of language tags to compare
  188. * to $locale
  189. * @param string $locale the locale to use as the language range when matching
  190. * @param string $default the locale to use if no match is found
  191. * @return string closest matching language tag, $default,
  192. * or empty string
  193. */
  194. public static function lookup(array $langtag, $locale, $default = null) {}
  195. /**
  196. * Returns a correctly ordered and delimited locale ID
  197. *
  198. * @param array $subtags an array containing a list of key-value pairs, where
  199. * the keys identify the particular locale ID subtags,
  200. * and the values are the associated subtag values.
  201. *
  202. * @return string the corresponding locale identifier.
  203. */
  204. public static function composeLocale(array $subtags) {}
  205. /**
  206. * Returns a key-value array of locale ID subtag elements.
  207. *
  208. * @param string $locale the locale to extract the subtag array from
  209. *
  210. * @return array $subtags an array containing a list of key-value pairs, where
  211. * the keys identify the particular locale ID subtags,
  212. * and the values are the associated subtag values.
  213. */
  214. public static function parseLocale($locale) {}
  215. }
  216. #############################################################################
  217. # Procedural API
  218. #############################################################################
  219. /**
  220. * Gets the default locale value from the INTL global 'default_locale'
  221. * At the PHP initilaization (MINIT) this value is set to
  222. * 'intl.default_locale' value from php.ini if that value exists
  223. * or from ICU's function uloc_getDefault()
  224. * Then onwards picks up changes from setDefault() calls also
  225. *
  226. * @return string the current runtime locale
  227. */
  228. function locale_get_default() {}
  229. /**
  230. * sets the default runtime locale to $locale
  231. * This changes the value of INTL global 'default_locale'
  232. *
  233. * @param string $locale is a BCP 47 compliant language tag containing the
  234. * locale identifier. UAX #35 extensions are accepted.
  235. * @return boolean 'true' if okay, 'false' if an error
  236. */
  237. function locale_set_default($locale) {}
  238. /**
  239. * Gets the primary language for the input locale
  240. *
  241. * @param string $locale the locale to extract the primary language code from
  242. * @return string the language code associated with the language
  243. * or null in case of error.
  244. */
  245. function locale_get_primary_language($locale) {}
  246. /**
  247. * Gets the script for the input locale
  248. *
  249. * @param string $locale the locale to extract the script code from
  250. * @return string the script subtag for the locale or null if not present
  251. */
  252. function locale_get_script($locale) {}
  253. /**
  254. * Gets the region for the input locale
  255. *
  256. * @param string $locale the locale to extract the region code from
  257. * @return string the region subtag for the locale or null if not present
  258. */
  259. function locale_get_region($locale) {}
  260. /**
  261. * Gets the variants for the input locale
  262. *
  263. * @param string $locale the locale to extract the variants from
  264. * @return array the array containing the list of all variants
  265. * subtag for the locale or null if not present
  266. */
  267. function locale_get_all_variants($locale) {}
  268. /**
  269. * Gets the keywords for the input locale
  270. *
  271. * @param string $locale the locale to extract the keywords from
  272. * @return array associative array containing the keyword-value pairs for this locale
  273. */
  274. function locale_get_keywords($locale) {}
  275. /**
  276. * Returns an appropriately localized display name for the input locale
  277. *
  278. * @param string $locale the locale to return a displayname for
  279. * @param [string] $in_locale optional format locale
  280. * If is 'null' then the default locale is used.
  281. * @return string display name of the locale in the format
  282. * appropriate for $in_locale.
  283. */
  284. function locale_get_display_name($locale, $in_locale = null) {}
  285. /**
  286. * Returns an appropriately localized display name for language of the input locale
  287. *
  288. * @param string $locale the locale to return a display language for
  289. * @param [string] $in_locale optional format locale to use to display the language name
  290. * If is 'null' then the default locale is used.
  291. * @return string display name of the language for the $locale in the format
  292. * appropriate for $in_locale.
  293. */
  294. function locale_get_display_language($lang, $in_locale = null) {}
  295. /**
  296. * Returns an appropriately localized display name for script of the input locale
  297. *
  298. * @param string $locale the locale to return a display script for
  299. * @param [string] $in_locale optional format locale to use to display the script name
  300. * If is 'null' then the default locale is used.
  301. * @return string display name of the script for the $locale in the format
  302. * appropriate for $in_locale.
  303. */
  304. function locale_get_display_script($script, $in_locale = null) {}
  305. /**
  306. * Returns an appropriately localized display name for region of the input locale
  307. *
  308. * @param string $locale the locale to return a display region for
  309. * @param [string] $in_locale optional format locale to use to display the region name
  310. * If is 'null' then the default locale is used.
  311. * @return string display name of the region for the $locale in the format
  312. * appropriate for $in_locale.
  313. */
  314. function locale_get_display_region($region, $in_locale = null) {}
  315. /**
  316. * Returns an appropriately localized display name for variants of the input locale
  317. *
  318. * @param string $locale the locale to return a display variant for
  319. * @param [string] $in_locale optional format locale to use to display the variant name
  320. * If is 'null' then the default locale is used.
  321. * @return string display name of the variant for the $locale in the format
  322. * appropriate for $in_locale.
  323. */
  324. function locale_get_display_variant($variant, $in_locale = null) {}
  325. /**
  326. * Checks if a $langtag filter matches with $locale according to
  327. * RFC 4647's basic filtering algorithm
  328. *
  329. * @param string $langtag the language tag to check
  330. * @param string $locale the language range to check against
  331. * @param bool $canonicalize Canonicalize parameters?
  332. * @return boolean 'true' if $locale matches $langtag 'false' otherwise
  333. */
  334. function locale_filter_matches($langtag, $locale, $canonicalize) {}
  335. /**
  336. * Searchs the items in $langtag for the best match to the language
  337. * range specified in $locale according to RFC 4647's lookup algorithm.
  338. *
  339. * @param array $langtag an array containing a list of language tags to compare
  340. * to $locale
  341. * @param string $locale the locale to use as the language range when matching
  342. * @param string $default the locale to use if no match is found
  343. * @return string closest matching language tag, $default,
  344. * or empty string
  345. */
  346. function locale_lookup(array $langtag, $locale, $default = null) {}
  347. /**
  348. * Returns a correctly ordered and delimited locale ID
  349. *
  350. * @param array $subtags an array containing a list of key-value pairs, where
  351. * the keys identify the particular locale ID subtags,
  352. * and the values are the associated subtag values.
  353. *
  354. * @return string the corresponding locale identifier.
  355. */
  356. function locale_compose_locale(array $subtags) {}
  357. /**
  358. * Returns a key-value array of locale ID subtag elements.
  359. *
  360. * @param string $locale the locale to extract the subtag array from
  361. *
  362. * @return array $subtags an array containing a list of key-value pairs, where
  363. * the keys identify the particular locale ID subtags,
  364. * and the values are the associated subtag values.
  365. */
  366. function locale_parse_locale($locale) {}
  367. ?>