3 * Date and Time Locale object
10 * Class that loads the calendar locale.
16 * Stores the translated strings for the full weekday names.
24 * Stores the translated strings for the one character weekday names.
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.
29 * @see WP_Locale::init() for how to handle the hack.
34 public $weekday_initial;
37 * Stores the translated strings for the abbreviated weekday names.
42 public $weekday_abbrev;
45 * Stores the default start of the week.
50 public $start_of_week;
53 * Stores the translated strings for the full month names.
61 * Stores the translated strings for the abbreviated month names.
69 * Stores the translated strings for 'am' and 'pm'.
71 * Also the capitalized versions.
79 * The text direction of the locale language.
81 * Default is left to right 'ltr'.
86 public $text_direction = 'ltr';
89 * The thousands separator and decimal point values used for localizing numbers.
95 public $number_format;
98 * Sets up the translated strings and object properties.
100 * The method creates the translatable strings for various
101 * calendar elements. Which allows for specifying locale
102 * specific calendar names and text direction.
107 * @global string $text_direction
108 * @global string $wp_version
110 public function init() {
112 $this->weekday[0] = /* translators: weekday */ __('Sunday');
113 $this->weekday[1] = /* translators: weekday */ __('Monday');
114 $this->weekday[2] = /* translators: weekday */ __('Tuesday');
115 $this->weekday[3] = /* translators: weekday */ __('Wednesday');
116 $this->weekday[4] = /* translators: weekday */ __('Thursday');
117 $this->weekday[5] = /* translators: weekday */ __('Friday');
118 $this->weekday[6] = /* translators: weekday */ __('Saturday');
120 // The first letter of each day.
121 $this->weekday_initial[ __( 'Sunday' ) ] = /* translators: one-letter abbreviation of the weekday */ _x( 'S', 'Sunday initial' );
122 $this->weekday_initial[ __( 'Monday' ) ] = /* translators: one-letter abbreviation of the weekday */ _x( 'M', 'Monday initial' );
123 $this->weekday_initial[ __( 'Tuesday' ) ] = /* translators: one-letter abbreviation of the weekday */ _x( 'T', 'Tuesday initial' );
124 $this->weekday_initial[ __( 'Wednesday' ) ] = /* translators: one-letter abbreviation of the weekday */ _x( 'W', 'Wednesday initial' );
125 $this->weekday_initial[ __( 'Thursday' ) ] = /* translators: one-letter abbreviation of the weekday */ _x( 'T', 'Thursday initial' );
126 $this->weekday_initial[ __( 'Friday' ) ] = /* translators: one-letter abbreviation of the weekday */ _x( 'F', 'Friday initial' );
127 $this->weekday_initial[ __( 'Saturday' ) ] = /* translators: one-letter abbreviation of the weekday */ _x( 'S', 'Saturday initial' );
129 // Abbreviations for each day.
130 $this->weekday_abbrev[__('Sunday')] = /* translators: three-letter abbreviation of the weekday */ __('Sun');
131 $this->weekday_abbrev[__('Monday')] = /* translators: three-letter abbreviation of the weekday */ __('Mon');
132 $this->weekday_abbrev[__('Tuesday')] = /* translators: three-letter abbreviation of the weekday */ __('Tue');
133 $this->weekday_abbrev[__('Wednesday')] = /* translators: three-letter abbreviation of the weekday */ __('Wed');
134 $this->weekday_abbrev[__('Thursday')] = /* translators: three-letter abbreviation of the weekday */ __('Thu');
135 $this->weekday_abbrev[__('Friday')] = /* translators: three-letter abbreviation of the weekday */ __('Fri');
136 $this->weekday_abbrev[__('Saturday')] = /* translators: three-letter abbreviation of the weekday */ __('Sat');
139 $this->month['01'] = /* translators: month name */ __( 'January' );
140 $this->month['02'] = /* translators: month name */ __( 'February' );
141 $this->month['03'] = /* translators: month name */ __( 'March' );
142 $this->month['04'] = /* translators: month name */ __( 'April' );
143 $this->month['05'] = /* translators: month name */ __( 'May' );
144 $this->month['06'] = /* translators: month name */ __( 'June' );
145 $this->month['07'] = /* translators: month name */ __( 'July' );
146 $this->month['08'] = /* translators: month name */ __( 'August' );
147 $this->month['09'] = /* translators: month name */ __( 'September' );
148 $this->month['10'] = /* translators: month name */ __( 'October' );
149 $this->month['11'] = /* translators: month name */ __( 'November' );
150 $this->month['12'] = /* translators: month name */ __( 'December' );
152 // The Months, genitive
153 $this->month_genitive['01'] = /* translators: month name, genitive */ _x( 'January', 'genitive' );
154 $this->month_genitive['02'] = /* translators: month name, genitive */ _x( 'February', 'genitive' );
155 $this->month_genitive['03'] = /* translators: month name, genitive */ _x( 'March', 'genitive' );
156 $this->month_genitive['04'] = /* translators: month name, genitive */ _x( 'April', 'genitive' );
157 $this->month_genitive['05'] = /* translators: month name, genitive */ _x( 'May', 'genitive' );
158 $this->month_genitive['06'] = /* translators: month name, genitive */ _x( 'June', 'genitive' );
159 $this->month_genitive['07'] = /* translators: month name, genitive */ _x( 'July', 'genitive' );
160 $this->month_genitive['08'] = /* translators: month name, genitive */ _x( 'August', 'genitive' );
161 $this->month_genitive['09'] = /* translators: month name, genitive */ _x( 'September', 'genitive' );
162 $this->month_genitive['10'] = /* translators: month name, genitive */ _x( 'October', 'genitive' );
163 $this->month_genitive['11'] = /* translators: month name, genitive */ _x( 'November', 'genitive' );
164 $this->month_genitive['12'] = /* translators: month name, genitive */ _x( 'December', 'genitive' );
166 // Abbreviations for each month.
167 $this->month_abbrev[ __( 'January' ) ] = /* translators: three-letter abbreviation of the month */ _x( 'Jan', 'January abbreviation' );
168 $this->month_abbrev[ __( 'February' ) ] = /* translators: three-letter abbreviation of the month */ _x( 'Feb', 'February abbreviation' );
169 $this->month_abbrev[ __( 'March' ) ] = /* translators: three-letter abbreviation of the month */ _x( 'Mar', 'March abbreviation' );
170 $this->month_abbrev[ __( 'April' ) ] = /* translators: three-letter abbreviation of the month */ _x( 'Apr', 'April abbreviation' );
171 $this->month_abbrev[ __( 'May' ) ] = /* translators: three-letter abbreviation of the month */ _x( 'May', 'May abbreviation' );
172 $this->month_abbrev[ __( 'June' ) ] = /* translators: three-letter abbreviation of the month */ _x( 'Jun', 'June abbreviation' );
173 $this->month_abbrev[ __( 'July' ) ] = /* translators: three-letter abbreviation of the month */ _x( 'Jul', 'July abbreviation' );
174 $this->month_abbrev[ __( 'August' ) ] = /* translators: three-letter abbreviation of the month */ _x( 'Aug', 'August abbreviation' );
175 $this->month_abbrev[ __( 'September' ) ] = /* translators: three-letter abbreviation of the month */ _x( 'Sep', 'September abbreviation' );
176 $this->month_abbrev[ __( 'October' ) ] = /* translators: three-letter abbreviation of the month */ _x( 'Oct', 'October abbreviation' );
177 $this->month_abbrev[ __( 'November' ) ] = /* translators: three-letter abbreviation of the month */ _x( 'Nov', 'November abbreviation' );
178 $this->month_abbrev[ __( 'December' ) ] = /* translators: three-letter abbreviation of the month */ _x( 'Dec', 'December abbreviation' );
181 $this->meridiem['am'] = __('am');
182 $this->meridiem['pm'] = __('pm');
183 $this->meridiem['AM'] = __('AM');
184 $this->meridiem['PM'] = __('PM');
186 // Numbers formatting
187 // See http://php.net/number_format
189 /* translators: $thousands_sep argument for http://php.net/number_format, default is , */
190 $trans = __('number_format_thousands_sep');
191 $this->number_format['thousands_sep'] = ('number_format_thousands_sep' == $trans) ? ',' : $trans;
193 /* translators: $dec_point argument for http://php.net/number_format, default is . */
194 $trans = __('number_format_decimal_point');
195 $this->number_format['decimal_point'] = ('number_format_decimal_point' == $trans) ? '.' : $trans;
197 // Set text direction.
198 if ( isset( $GLOBALS['text_direction'] ) )
199 $this->text_direction = $GLOBALS['text_direction'];
200 /* translators: 'rtl' or 'ltr'. This sets the text direction for WordPress. */
201 elseif ( 'rtl' == _x( 'ltr', 'text direction' ) )
202 $this->text_direction = 'rtl';
204 if ( 'rtl' === $this->text_direction && strpos( $GLOBALS['wp_version'], '-src' ) ) {
205 $this->text_direction = 'ltr';
206 add_action( 'all_admin_notices', array( $this, 'rtl_src_admin_notice' ) );
213 public function rtl_src_admin_notice() {
214 /* translators: %s: Name of the directory (build) */
215 echo '<div class="error"><p>' . sprintf( __( 'The %s directory of the develop repository must be used for RTL.' ), '<code>build</code>' ) . '</p></div>';
219 * Retrieve the full translated weekday word.
221 * Week starts on translated Sunday and can be fetched
222 * by using 0 (zero). So the week starts with 0 (zero)
223 * and ends on Saturday with is fetched by using 6 (six).
228 * @param int $weekday_number 0 for Sunday through 6 Saturday
229 * @return string Full translated weekday
231 public function get_weekday($weekday_number) {
232 return $this->weekday[$weekday_number];
236 * Retrieve the translated weekday initial.
238 * The weekday initial is retrieved by the translated
239 * full weekday word. When translating the weekday initial
240 * pay attention to make sure that the starting letter does
246 * @param string $weekday_name
249 public function get_weekday_initial($weekday_name) {
250 return $this->weekday_initial[$weekday_name];
254 * Retrieve the translated weekday abbreviation.
256 * The weekday abbreviation is retrieved by the translated
262 * @param string $weekday_name Full translated weekday word
263 * @return string Translated weekday abbreviation
265 public function get_weekday_abbrev($weekday_name) {
266 return $this->weekday_abbrev[$weekday_name];
270 * Retrieve the full translated month by month number.
272 * The $month_number parameter has to be a string
273 * because it must have the '0' in front of any number
274 * that is less than 10. Starts from '01' and ends at
277 * You can use an integer instead and it will add the
278 * '0' before the numbers less than 10 for you.
283 * @param string|int $month_number '01' through '12'
284 * @return string Translated full month name
286 public function get_month($month_number) {
287 return $this->month[zeroise($month_number, 2)];
291 * Retrieve translated version of month abbreviation string.
293 * The $month_name parameter is expected to be the translated or
294 * translatable version of the month.
299 * @param string $month_name Translated month to get abbreviated version
300 * @return string Translated abbreviated month
302 public function get_month_abbrev($month_name) {
303 return $this->month_abbrev[$month_name];
307 * Retrieve translated version of meridiem string.
309 * The $meridiem parameter is expected to not be translated.
314 * @param string $meridiem Either 'am', 'pm', 'AM', or 'PM'. Not translated version.
315 * @return string Translated version
317 public function get_meridiem($meridiem) {
318 return $this->meridiem[$meridiem];
322 * Global variables are deprecated. For backwards compatibility only.
324 * @deprecated For backwards compatibility only.
327 * @global array $weekday
328 * @global array $weekday_initial
329 * @global array $weekday_abbrev
330 * @global array $month
331 * @global array $month_abbrev
335 public function register_globals() {
336 $GLOBALS['weekday'] = $this->weekday;
337 $GLOBALS['weekday_initial'] = $this->weekday_initial;
338 $GLOBALS['weekday_abbrev'] = $this->weekday_abbrev;
339 $GLOBALS['month'] = $this->month;
340 $GLOBALS['month_abbrev'] = $this->month_abbrev;
344 * Constructor which calls helper methods to set up object variables
348 public function __construct() {
350 $this->register_globals();
354 * Checks if current locale is RTL.
357 * @return bool Whether locale is RTL.
359 public function is_rtl() {
360 return 'rtl' == $this->text_direction;
364 * Register date/time format strings for general POT.
366 * Private, unused method to add some date/time formats translated
367 * on wp-admin/options-general.php to the general POT that would
368 * otherwise be added to the admin POT.
372 public function _strings_for_pot() {
373 /* translators: localized date format, see http://php.net/date */
375 /* translators: localized time format, see http://php.net/date */
377 /* translators: localized date and time format, see http://php.net/date */
378 __( 'F j, Y g:i a' );
383 * Checks if current locale is RTL.
387 * @global WP_Locale $wp_locale
389 * @return bool Whether locale is RTL.
393 return $wp_locale->is_rtl();