PageRenderTime 45ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/wp-includes/locale.php

https://github.com/sharpmachine/wakeupmedia.com
PHP | 341 lines | 111 code | 29 blank | 201 comment | 5 complexity | ce5c1e0ec021bcbe3e5c87ea1c8a8e0f MD5 | raw file
  1. <?php
  2. /**
  3. * Date and Time Locale object
  4. *
  5. * @package WordPress
  6. * @subpackage i18n
  7. */
  8. /**
  9. * Class that loads the calendar locale.
  10. *
  11. * @since 2.1.0
  12. */
  13. class WP_Locale {
  14. /**
  15. * Stores the translated strings for the full weekday names.
  16. *
  17. * @since 2.1.0
  18. * @var array
  19. * @access private
  20. */
  21. var $weekday;
  22. /**
  23. * Stores the translated strings for the one character weekday names.
  24. *
  25. * There is a hack to make sure that Tuesday and Thursday, as well
  26. * as Sunday and Saturday, don't conflict. See init() method for more.
  27. *
  28. * @see WP_Locale::init() for how to handle the hack.
  29. *
  30. * @since 2.1.0
  31. * @var array
  32. * @access private
  33. */
  34. var $weekday_initial;
  35. /**
  36. * Stores the translated strings for the abbreviated weekday names.
  37. *
  38. * @since 2.1.0
  39. * @var array
  40. * @access private
  41. */
  42. var $weekday_abbrev;
  43. /**
  44. * Stores the translated strings for the full month names.
  45. *
  46. * @since 2.1.0
  47. * @var array
  48. * @access private
  49. */
  50. var $month;
  51. /**
  52. * Stores the translated strings for the abbreviated month names.
  53. *
  54. * @since 2.1.0
  55. * @var array
  56. * @access private
  57. */
  58. var $month_abbrev;
  59. /**
  60. * Stores the translated strings for 'am' and 'pm'.
  61. *
  62. * Also the capitalized versions.
  63. *
  64. * @since 2.1.0
  65. * @var array
  66. * @access private
  67. */
  68. var $meridiem;
  69. /**
  70. * The text direction of the locale language.
  71. *
  72. * Default is left to right 'ltr'.
  73. *
  74. * @since 2.1.0
  75. * @var string
  76. * @access private
  77. */
  78. var $text_direction = 'ltr';
  79. /**
  80. * Sets up the translated strings and object properties.
  81. *
  82. * The method creates the translatable strings for various
  83. * calendar elements. Which allows for specifying locale
  84. * specific calendar names and text direction.
  85. *
  86. * @since 2.1.0
  87. * @access private
  88. */
  89. function init() {
  90. // The Weekdays
  91. $this->weekday[0] = /* translators: weekday */ __('Sunday');
  92. $this->weekday[1] = /* translators: weekday */ __('Monday');
  93. $this->weekday[2] = /* translators: weekday */ __('Tuesday');
  94. $this->weekday[3] = /* translators: weekday */ __('Wednesday');
  95. $this->weekday[4] = /* translators: weekday */ __('Thursday');
  96. $this->weekday[5] = /* translators: weekday */ __('Friday');
  97. $this->weekday[6] = /* translators: weekday */ __('Saturday');
  98. // The first letter of each day. The _%day%_initial suffix is a hack to make
  99. // sure the day initials are unique.
  100. $this->weekday_initial[__('Sunday')] = /* translators: one-letter abbreviation of the weekday */ __('S_Sunday_initial');
  101. $this->weekday_initial[__('Monday')] = /* translators: one-letter abbreviation of the weekday */ __('M_Monday_initial');
  102. $this->weekday_initial[__('Tuesday')] = /* translators: one-letter abbreviation of the weekday */ __('T_Tuesday_initial');
  103. $this->weekday_initial[__('Wednesday')] = /* translators: one-letter abbreviation of the weekday */ __('W_Wednesday_initial');
  104. $this->weekday_initial[__('Thursday')] = /* translators: one-letter abbreviation of the weekday */ __('T_Thursday_initial');
  105. $this->weekday_initial[__('Friday')] = /* translators: one-letter abbreviation of the weekday */ __('F_Friday_initial');
  106. $this->weekday_initial[__('Saturday')] = /* translators: one-letter abbreviation of the weekday */ __('S_Saturday_initial');
  107. foreach ($this->weekday_initial as $weekday_ => $weekday_initial_) {
  108. $this->weekday_initial[$weekday_] = preg_replace('/_.+_initial$/', '', $weekday_initial_);
  109. }
  110. // Abbreviations for each day.
  111. $this->weekday_abbrev[__('Sunday')] = /* translators: three-letter abbreviation of the weekday */ __('Sun');
  112. $this->weekday_abbrev[__('Monday')] = /* translators: three-letter abbreviation of the weekday */ __('Mon');
  113. $this->weekday_abbrev[__('Tuesday')] = /* translators: three-letter abbreviation of the weekday */ __('Tue');
  114. $this->weekday_abbrev[__('Wednesday')] = /* translators: three-letter abbreviation of the weekday */ __('Wed');
  115. $this->weekday_abbrev[__('Thursday')] = /* translators: three-letter abbreviation of the weekday */ __('Thu');
  116. $this->weekday_abbrev[__('Friday')] = /* translators: three-letter abbreviation of the weekday */ __('Fri');
  117. $this->weekday_abbrev[__('Saturday')] = /* translators: three-letter abbreviation of the weekday */ __('Sat');
  118. // The Months
  119. $this->month['01'] = /* translators: month name */ __('January');
  120. $this->month['02'] = /* translators: month name */ __('February');
  121. $this->month['03'] = /* translators: month name */ __('March');
  122. $this->month['04'] = /* translators: month name */ __('April');
  123. $this->month['05'] = /* translators: month name */ __('May');
  124. $this->month['06'] = /* translators: month name */ __('June');
  125. $this->month['07'] = /* translators: month name */ __('July');
  126. $this->month['08'] = /* translators: month name */ __('August');
  127. $this->month['09'] = /* translators: month name */ __('September');
  128. $this->month['10'] = /* translators: month name */ __('October');
  129. $this->month['11'] = /* translators: month name */ __('November');
  130. $this->month['12'] = /* translators: month name */ __('December');
  131. // Abbreviations for each month. Uses the same hack as above to get around the
  132. // 'May' duplication.
  133. $this->month_abbrev[__('January')] = /* translators: three-letter abbreviation of the month */ __('Jan_January_abbreviation');
  134. $this->month_abbrev[__('February')] = /* translators: three-letter abbreviation of the month */ __('Feb_February_abbreviation');
  135. $this->month_abbrev[__('March')] = /* translators: three-letter abbreviation of the month */ __('Mar_March_abbreviation');
  136. $this->month_abbrev[__('April')] = /* translators: three-letter abbreviation of the month */ __('Apr_April_abbreviation');
  137. $this->month_abbrev[__('May')] = /* translators: three-letter abbreviation of the month */ __('May_May_abbreviation');
  138. $this->month_abbrev[__('June')] = /* translators: three-letter abbreviation of the month */ __('Jun_June_abbreviation');
  139. $this->month_abbrev[__('July')] = /* translators: three-letter abbreviation of the month */ __('Jul_July_abbreviation');
  140. $this->month_abbrev[__('August')] = /* translators: three-letter abbreviation of the month */ __('Aug_August_abbreviation');
  141. $this->month_abbrev[__('September')] = /* translators: three-letter abbreviation of the month */ __('Sep_September_abbreviation');
  142. $this->month_abbrev[__('October')] = /* translators: three-letter abbreviation of the month */ __('Oct_October_abbreviation');
  143. $this->month_abbrev[__('November')] = /* translators: three-letter abbreviation of the month */ __('Nov_November_abbreviation');
  144. $this->month_abbrev[__('December')] = /* translators: three-letter abbreviation of the month */ __('Dec_December_abbreviation');
  145. foreach ($this->month_abbrev as $month_ => $month_abbrev_) {
  146. $this->month_abbrev[$month_] = preg_replace('/_.+_abbreviation$/', '', $month_abbrev_);
  147. }
  148. // The Meridiems
  149. $this->meridiem['am'] = __('am');
  150. $this->meridiem['pm'] = __('pm');
  151. $this->meridiem['AM'] = __('AM');
  152. $this->meridiem['PM'] = __('PM');
  153. // Numbers formatting
  154. // See http://php.net/number_format
  155. /* translators: $thousands_sep argument for http://php.net/number_format, default is , */
  156. $trans = __('number_format_thousands_sep');
  157. $this->number_format['thousands_sep'] = ('number_format_thousands_sep' == $trans) ? ',' : $trans;
  158. /* translators: $dec_point argument for http://php.net/number_format, default is . */
  159. $trans = __('number_format_decimal_point');
  160. $this->number_format['decimal_point'] = ('number_format_decimal_point' == $trans) ? '.' : $trans;
  161. // Set text direction.
  162. if ( isset( $GLOBALS['text_direction'] ) )
  163. $this->text_direction = $GLOBALS['text_direction'];
  164. /* translators: 'rtl' or 'ltr'. This sets the text direction for WordPress. */
  165. elseif ( 'rtl' == _x( 'ltr', 'text direction' ) )
  166. $this->text_direction = 'rtl';
  167. }
  168. /**
  169. * Retrieve the full translated weekday word.
  170. *
  171. * Week starts on translated Sunday and can be fetched
  172. * by using 0 (zero). So the week starts with 0 (zero)
  173. * and ends on Saturday with is fetched by using 6 (six).
  174. *
  175. * @since 2.1.0
  176. * @access public
  177. *
  178. * @param int $weekday_number 0 for Sunday through 6 Saturday
  179. * @return string Full translated weekday
  180. */
  181. function get_weekday($weekday_number) {
  182. return $this->weekday[$weekday_number];
  183. }
  184. /**
  185. * Retrieve the translated weekday initial.
  186. *
  187. * The weekday initial is retrieved by the translated
  188. * full weekday word. When translating the weekday initial
  189. * pay attention to make sure that the starting letter does
  190. * not conflict.
  191. *
  192. * @since 2.1.0
  193. * @access public
  194. *
  195. * @param string $weekday_name
  196. * @return string
  197. */
  198. function get_weekday_initial($weekday_name) {
  199. return $this->weekday_initial[$weekday_name];
  200. }
  201. /**
  202. * Retrieve the translated weekday abbreviation.
  203. *
  204. * The weekday abbreviation is retrieved by the translated
  205. * full weekday word.
  206. *
  207. * @since 2.1.0
  208. * @access public
  209. *
  210. * @param string $weekday_name Full translated weekday word
  211. * @return string Translated weekday abbreviation
  212. */
  213. function get_weekday_abbrev($weekday_name) {
  214. return $this->weekday_abbrev[$weekday_name];
  215. }
  216. /**
  217. * Retrieve the full translated month by month number.
  218. *
  219. * The $month_number parameter has to be a string
  220. * because it must have the '0' in front of any number
  221. * that is less than 10. Starts from '01' and ends at
  222. * '12'.
  223. *
  224. * You can use an integer instead and it will add the
  225. * '0' before the numbers less than 10 for you.
  226. *
  227. * @since 2.1.0
  228. * @access public
  229. *
  230. * @param string|int $month_number '01' through '12'
  231. * @return string Translated full month name
  232. */
  233. function get_month($month_number) {
  234. return $this->month[zeroise($month_number, 2)];
  235. }
  236. /**
  237. * Retrieve translated version of month abbreviation string.
  238. *
  239. * The $month_name parameter is expected to be the translated or
  240. * translatable version of the month.
  241. *
  242. * @since 2.1.0
  243. * @access public
  244. *
  245. * @param string $month_name Translated month to get abbreviated version
  246. * @return string Translated abbreviated month
  247. */
  248. function get_month_abbrev($month_name) {
  249. return $this->month_abbrev[$month_name];
  250. }
  251. /**
  252. * Retrieve translated version of meridiem string.
  253. *
  254. * The $meridiem parameter is expected to not be translated.
  255. *
  256. * @since 2.1.0
  257. * @access public
  258. *
  259. * @param string $meridiem Either 'am', 'pm', 'AM', or 'PM'. Not translated version.
  260. * @return string Translated version
  261. */
  262. function get_meridiem($meridiem) {
  263. return $this->meridiem[$meridiem];
  264. }
  265. /**
  266. * Global variables are deprecated. For backwards compatibility only.
  267. *
  268. * @deprecated For backwards compatibility only.
  269. * @access private
  270. *
  271. * @since 2.1.0
  272. */
  273. function register_globals() {
  274. $GLOBALS['weekday'] = $this->weekday;
  275. $GLOBALS['weekday_initial'] = $this->weekday_initial;
  276. $GLOBALS['weekday_abbrev'] = $this->weekday_abbrev;
  277. $GLOBALS['month'] = $this->month;
  278. $GLOBALS['month_abbrev'] = $this->month_abbrev;
  279. }
  280. /**
  281. * Constructor which calls helper methods to set up object variables
  282. *
  283. * @uses WP_Locale::init()
  284. * @uses WP_Locale::register_globals()
  285. * @since 2.1.0
  286. *
  287. * @return WP_Locale
  288. */
  289. function __construct() {
  290. $this->init();
  291. $this->register_globals();
  292. }
  293. /**
  294. * Checks if current locale is RTL.
  295. *
  296. * @since 3.0.0
  297. * @return bool Whether locale is RTL.
  298. */
  299. function is_rtl() {
  300. return 'rtl' == $this->text_direction;
  301. }
  302. }
  303. /**
  304. * Checks if current locale is RTL.
  305. *
  306. * @since 3.0.0
  307. * @return bool Whether locale is RTL.
  308. */
  309. function is_rtl() {
  310. global $wp_locale;
  311. return $wp_locale->is_rtl();
  312. }