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