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