PageRenderTime 23ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-includes/locale.php

https://github.com/mhoofman/wordpress-heroku
PHP | 373 lines | 124 code | 33 blank | 216 comment | 7 complexity | 864bdb066f1a4b663a1d729ae4925a27 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. * @var array
  81. */
  82. var $number_format;
  83. /**
  84. * Sets up the translated strings and object properties.
  85. *
  86. * The method creates the translatable strings for various
  87. * calendar elements. Which allows for specifying locale
  88. * specific calendar names and text direction.
  89. *
  90. * @since 2.1.0
  91. * @access private
  92. */
  93. function init() {
  94. // The Weekdays
  95. $this->weekday[0] = /* translators: weekday */ __('Sunday');
  96. $this->weekday[1] = /* translators: weekday */ __('Monday');
  97. $this->weekday[2] = /* translators: weekday */ __('Tuesday');
  98. $this->weekday[3] = /* translators: weekday */ __('Wednesday');
  99. $this->weekday[4] = /* translators: weekday */ __('Thursday');
  100. $this->weekday[5] = /* translators: weekday */ __('Friday');
  101. $this->weekday[6] = /* translators: weekday */ __('Saturday');
  102. // The first letter of each day. The _%day%_initial suffix is a hack to make
  103. // sure the day initials are unique.
  104. $this->weekday_initial[__('Sunday')] = /* translators: one-letter abbreviation of the weekday */ __('S_Sunday_initial');
  105. $this->weekday_initial[__('Monday')] = /* translators: one-letter abbreviation of the weekday */ __('M_Monday_initial');
  106. $this->weekday_initial[__('Tuesday')] = /* translators: one-letter abbreviation of the weekday */ __('T_Tuesday_initial');
  107. $this->weekday_initial[__('Wednesday')] = /* translators: one-letter abbreviation of the weekday */ __('W_Wednesday_initial');
  108. $this->weekday_initial[__('Thursday')] = /* translators: one-letter abbreviation of the weekday */ __('T_Thursday_initial');
  109. $this->weekday_initial[__('Friday')] = /* translators: one-letter abbreviation of the weekday */ __('F_Friday_initial');
  110. $this->weekday_initial[__('Saturday')] = /* translators: one-letter abbreviation of the weekday */ __('S_Saturday_initial');
  111. foreach ($this->weekday_initial as $weekday_ => $weekday_initial_) {
  112. $this->weekday_initial[$weekday_] = preg_replace('/_.+_initial$/', '', $weekday_initial_);
  113. }
  114. // Abbreviations for each day.
  115. $this->weekday_abbrev[__('Sunday')] = /* translators: three-letter abbreviation of the weekday */ __('Sun');
  116. $this->weekday_abbrev[__('Monday')] = /* translators: three-letter abbreviation of the weekday */ __('Mon');
  117. $this->weekday_abbrev[__('Tuesday')] = /* translators: three-letter abbreviation of the weekday */ __('Tue');
  118. $this->weekday_abbrev[__('Wednesday')] = /* translators: three-letter abbreviation of the weekday */ __('Wed');
  119. $this->weekday_abbrev[__('Thursday')] = /* translators: three-letter abbreviation of the weekday */ __('Thu');
  120. $this->weekday_abbrev[__('Friday')] = /* translators: three-letter abbreviation of the weekday */ __('Fri');
  121. $this->weekday_abbrev[__('Saturday')] = /* translators: three-letter abbreviation of the weekday */ __('Sat');
  122. // The Months
  123. $this->month['01'] = /* translators: month name */ __('January');
  124. $this->month['02'] = /* translators: month name */ __('February');
  125. $this->month['03'] = /* translators: month name */ __('March');
  126. $this->month['04'] = /* translators: month name */ __('April');
  127. $this->month['05'] = /* translators: month name */ __('May');
  128. $this->month['06'] = /* translators: month name */ __('June');
  129. $this->month['07'] = /* translators: month name */ __('July');
  130. $this->month['08'] = /* translators: month name */ __('August');
  131. $this->month['09'] = /* translators: month name */ __('September');
  132. $this->month['10'] = /* translators: month name */ __('October');
  133. $this->month['11'] = /* translators: month name */ __('November');
  134. $this->month['12'] = /* translators: month name */ __('December');
  135. // Abbreviations for each month. Uses the same hack as above to get around the
  136. // 'May' duplication.
  137. $this->month_abbrev[__('January')] = /* translators: three-letter abbreviation of the month */ __('Jan_January_abbreviation');
  138. $this->month_abbrev[__('February')] = /* translators: three-letter abbreviation of the month */ __('Feb_February_abbreviation');
  139. $this->month_abbrev[__('March')] = /* translators: three-letter abbreviation of the month */ __('Mar_March_abbreviation');
  140. $this->month_abbrev[__('April')] = /* translators: three-letter abbreviation of the month */ __('Apr_April_abbreviation');
  141. $this->month_abbrev[__('May')] = /* translators: three-letter abbreviation of the month */ __('May_May_abbreviation');
  142. $this->month_abbrev[__('June')] = /* translators: three-letter abbreviation of the month */ __('Jun_June_abbreviation');
  143. $this->month_abbrev[__('July')] = /* translators: three-letter abbreviation of the month */ __('Jul_July_abbreviation');
  144. $this->month_abbrev[__('August')] = /* translators: three-letter abbreviation of the month */ __('Aug_August_abbreviation');
  145. $this->month_abbrev[__('September')] = /* translators: three-letter abbreviation of the month */ __('Sep_September_abbreviation');
  146. $this->month_abbrev[__('October')] = /* translators: three-letter abbreviation of the month */ __('Oct_October_abbreviation');
  147. $this->month_abbrev[__('November')] = /* translators: three-letter abbreviation of the month */ __('Nov_November_abbreviation');
  148. $this->month_abbrev[__('December')] = /* translators: three-letter abbreviation of the month */ __('Dec_December_abbreviation');
  149. foreach ($this->month_abbrev as $month_ => $month_abbrev_) {
  150. $this->month_abbrev[$month_] = preg_replace('/_.+_abbreviation$/', '', $month_abbrev_);
  151. }
  152. // The Meridiems
  153. $this->meridiem['am'] = __('am');
  154. $this->meridiem['pm'] = __('pm');
  155. $this->meridiem['AM'] = __('AM');
  156. $this->meridiem['PM'] = __('PM');
  157. // Numbers formatting
  158. // See http://php.net/number_format
  159. /* translators: $thousands_sep argument for http://php.net/number_format, default is , */
  160. $trans = __('number_format_thousands_sep');
  161. $this->number_format['thousands_sep'] = ('number_format_thousands_sep' == $trans) ? ',' : $trans;
  162. /* translators: $dec_point argument for http://php.net/number_format, default is . */
  163. $trans = __('number_format_decimal_point');
  164. $this->number_format['decimal_point'] = ('number_format_decimal_point' == $trans) ? '.' : $trans;
  165. // Set text direction.
  166. if ( isset( $GLOBALS['text_direction'] ) )
  167. $this->text_direction = $GLOBALS['text_direction'];
  168. /* translators: 'rtl' or 'ltr'. This sets the text direction for WordPress. */
  169. elseif ( 'rtl' == _x( 'ltr', 'text direction' ) )
  170. $this->text_direction = 'rtl';
  171. if ( 'rtl' === $this->text_direction && strpos( $GLOBALS['wp_version'], '-src' ) ) {
  172. $this->text_direction = 'ltr';
  173. add_action( 'all_admin_notices', array( $this, 'rtl_src_admin_notice' ) );
  174. }
  175. }
  176. function rtl_src_admin_notice() {
  177. echo '<div class="error"><p>' . 'The <code>build</code> directory of the develop repository must be used for RTL.' . '</p></div>';
  178. }
  179. /**
  180. * Retrieve the full translated weekday word.
  181. *
  182. * Week starts on translated Sunday and can be fetched
  183. * by using 0 (zero). So the week starts with 0 (zero)
  184. * and ends on Saturday with is fetched by using 6 (six).
  185. *
  186. * @since 2.1.0
  187. * @access public
  188. *
  189. * @param int $weekday_number 0 for Sunday through 6 Saturday
  190. * @return string Full translated weekday
  191. */
  192. function get_weekday($weekday_number) {
  193. return $this->weekday[$weekday_number];
  194. }
  195. /**
  196. * Retrieve the translated weekday initial.
  197. *
  198. * The weekday initial is retrieved by the translated
  199. * full weekday word. When translating the weekday initial
  200. * pay attention to make sure that the starting letter does
  201. * not conflict.
  202. *
  203. * @since 2.1.0
  204. * @access public
  205. *
  206. * @param string $weekday_name
  207. * @return string
  208. */
  209. function get_weekday_initial($weekday_name) {
  210. return $this->weekday_initial[$weekday_name];
  211. }
  212. /**
  213. * Retrieve the translated weekday abbreviation.
  214. *
  215. * The weekday abbreviation is retrieved by the translated
  216. * full weekday word.
  217. *
  218. * @since 2.1.0
  219. * @access public
  220. *
  221. * @param string $weekday_name Full translated weekday word
  222. * @return string Translated weekday abbreviation
  223. */
  224. function get_weekday_abbrev($weekday_name) {
  225. return $this->weekday_abbrev[$weekday_name];
  226. }
  227. /**
  228. * Retrieve the full translated month by month number.
  229. *
  230. * The $month_number parameter has to be a string
  231. * because it must have the '0' in front of any number
  232. * that is less than 10. Starts from '01' and ends at
  233. * '12'.
  234. *
  235. * You can use an integer instead and it will add the
  236. * '0' before the numbers less than 10 for you.
  237. *
  238. * @since 2.1.0
  239. * @access public
  240. *
  241. * @param string|int $month_number '01' through '12'
  242. * @return string Translated full month name
  243. */
  244. function get_month($month_number) {
  245. return $this->month[zeroise($month_number, 2)];
  246. }
  247. /**
  248. * Retrieve translated version of month abbreviation string.
  249. *
  250. * The $month_name parameter is expected to be the translated or
  251. * translatable version of the month.
  252. *
  253. * @since 2.1.0
  254. * @access public
  255. *
  256. * @param string $month_name Translated month to get abbreviated version
  257. * @return string Translated abbreviated month
  258. */
  259. function get_month_abbrev($month_name) {
  260. return $this->month_abbrev[$month_name];
  261. }
  262. /**
  263. * Retrieve translated version of meridiem string.
  264. *
  265. * The $meridiem parameter is expected to not be translated.
  266. *
  267. * @since 2.1.0
  268. * @access public
  269. *
  270. * @param string $meridiem Either 'am', 'pm', 'AM', or 'PM'. Not translated version.
  271. * @return string Translated version
  272. */
  273. function get_meridiem($meridiem) {
  274. return $this->meridiem[$meridiem];
  275. }
  276. /**
  277. * Global variables are deprecated. For backwards compatibility only.
  278. *
  279. * @deprecated For backwards compatibility only.
  280. * @access private
  281. *
  282. * @since 2.1.0
  283. */
  284. function register_globals() {
  285. $GLOBALS['weekday'] = $this->weekday;
  286. $GLOBALS['weekday_initial'] = $this->weekday_initial;
  287. $GLOBALS['weekday_abbrev'] = $this->weekday_abbrev;
  288. $GLOBALS['month'] = $this->month;
  289. $GLOBALS['month_abbrev'] = $this->month_abbrev;
  290. }
  291. /**
  292. * Constructor which calls helper methods to set up object variables
  293. *
  294. * @uses WP_Locale::init()
  295. * @uses WP_Locale::register_globals()
  296. * @since 2.1.0
  297. *
  298. * @return WP_Locale
  299. */
  300. function __construct() {
  301. $this->init();
  302. $this->register_globals();
  303. }
  304. /**
  305. * Checks if current locale is RTL.
  306. *
  307. * @since 3.0.0
  308. * @return bool Whether locale is RTL.
  309. */
  310. function is_rtl() {
  311. return 'rtl' == $this->text_direction;
  312. }
  313. /**
  314. * Register date/time format strings for general POT.
  315. *
  316. * Private, unused method to add some date/time formats translated
  317. * on wp-admin/options-general.php to the general POT that would
  318. * otherwise be added to the admin POT.
  319. *
  320. * @since 3.6.0
  321. */
  322. function _strings_for_pot() {
  323. /* translators: localized date format, see http://php.net/date */
  324. __( 'F j, Y' );
  325. /* translators: localized time format, see http://php.net/date */
  326. __( 'g:i a' );
  327. /* translators: localized date and time format, see http://php.net/date */
  328. __( 'F j, Y g:i a' );
  329. }
  330. }
  331. /**
  332. * Checks if current locale is RTL.
  333. *
  334. * @since 3.0.0
  335. * @return bool Whether locale is RTL.
  336. */
  337. function is_rtl() {
  338. global $wp_locale;
  339. return $wp_locale->is_rtl();
  340. }