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