[ Index ] |
PHP Cross Reference of WordPress |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * Locale API: WP_Locale class 4 * 5 * @package WordPress 6 * @subpackage i18n 7 * @since 4.6.0 8 */ 9 10 /** 11 * Core class used to store translated data for a locale. 12 * 13 * @since 2.1.0 14 * @since 4.6.0 Moved to its own file from wp-includes/locale.php. 15 */ 16 class WP_Locale { 17 /** 18 * Stores the translated strings for the full weekday names. 19 * 20 * @since 2.1.0 21 * @var string[] 22 */ 23 public $weekday; 24 25 /** 26 * Stores the translated strings for the one character weekday names. 27 * 28 * There is a hack to make sure that Tuesday and Thursday, as well 29 * as Sunday and Saturday, don't conflict. See init() method for more. 30 * 31 * @see WP_Locale::init() for how to handle the hack. 32 * 33 * @since 2.1.0 34 * @var string[] 35 */ 36 public $weekday_initial; 37 38 /** 39 * Stores the translated strings for the abbreviated weekday names. 40 * 41 * @since 2.1.0 42 * @var string[] 43 */ 44 public $weekday_abbrev; 45 46 /** 47 * Stores the translated strings for the full month names. 48 * 49 * @since 2.1.0 50 * @var string[] 51 */ 52 public $month; 53 54 /** 55 * Stores the translated strings for the month names in genitive case, if the locale specifies. 56 * 57 * @since 4.4.0 58 * @var string[] 59 */ 60 public $month_genitive; 61 62 /** 63 * Stores the translated strings for the abbreviated month names. 64 * 65 * @since 2.1.0 66 * @var string[] 67 */ 68 public $month_abbrev; 69 70 /** 71 * Stores the translated strings for 'am' and 'pm'. 72 * 73 * Also the capitalized versions. 74 * 75 * @since 2.1.0 76 * @var string[] 77 */ 78 public $meridiem; 79 80 /** 81 * The text direction of the locale language. 82 * 83 * Default is left to right 'ltr'. 84 * 85 * @since 2.1.0 86 * @var string 87 */ 88 public $text_direction = 'ltr'; 89 90 /** 91 * The thousands separator and decimal point values used for localizing numbers. 92 * 93 * @since 2.3.0 94 * @var array 95 */ 96 public $number_format; 97 98 /** 99 * The separator string used for localizing list item separator. 100 * 101 * @since 6.0.0 102 * @var string 103 */ 104 public $list_item_separator; 105 106 /** 107 * Constructor which calls helper methods to set up object variables. 108 * 109 * @since 2.1.0 110 */ 111 public function __construct() { 112 $this->init(); 113 $this->register_globals(); 114 } 115 116 /** 117 * Sets up the translated strings and object properties. 118 * 119 * The method creates the translatable strings for various 120 * calendar elements. Which allows for specifying locale 121 * specific calendar names and text direction. 122 * 123 * @since 2.1.0 124 * 125 * @global string $text_direction 126 * @global string $wp_version The WordPress version string. 127 */ 128 public function init() { 129 // The weekdays. 130 $this->weekday[0] = /* translators: Weekday. */ __( 'Sunday' ); 131 $this->weekday[1] = /* translators: Weekday. */ __( 'Monday' ); 132 $this->weekday[2] = /* translators: Weekday. */ __( 'Tuesday' ); 133 $this->weekday[3] = /* translators: Weekday. */ __( 'Wednesday' ); 134 $this->weekday[4] = /* translators: Weekday. */ __( 'Thursday' ); 135 $this->weekday[5] = /* translators: Weekday. */ __( 'Friday' ); 136 $this->weekday[6] = /* translators: Weekday. */ __( 'Saturday' ); 137 138 // The first letter of each day. 139 $this->weekday_initial[ $this->weekday[0] ] = /* translators: One-letter abbreviation of the weekday. */ _x( 'S', 'Sunday initial' ); 140 $this->weekday_initial[ $this->weekday[1] ] = /* translators: One-letter abbreviation of the weekday. */ _x( 'M', 'Monday initial' ); 141 $this->weekday_initial[ $this->weekday[2] ] = /* translators: One-letter abbreviation of the weekday. */ _x( 'T', 'Tuesday initial' ); 142 $this->weekday_initial[ $this->weekday[3] ] = /* translators: One-letter abbreviation of the weekday. */ _x( 'W', 'Wednesday initial' ); 143 $this->weekday_initial[ $this->weekday[4] ] = /* translators: One-letter abbreviation of the weekday. */ _x( 'T', 'Thursday initial' ); 144 $this->weekday_initial[ $this->weekday[5] ] = /* translators: One-letter abbreviation of the weekday. */ _x( 'F', 'Friday initial' ); 145 $this->weekday_initial[ $this->weekday[6] ] = /* translators: One-letter abbreviation of the weekday. */ _x( 'S', 'Saturday initial' ); 146 147 // Abbreviations for each day. 148 $this->weekday_abbrev[ $this->weekday[0] ] = /* translators: Three-letter abbreviation of the weekday. */ __( 'Sun' ); 149 $this->weekday_abbrev[ $this->weekday[1] ] = /* translators: Three-letter abbreviation of the weekday. */ __( 'Mon' ); 150 $this->weekday_abbrev[ $this->weekday[2] ] = /* translators: Three-letter abbreviation of the weekday. */ __( 'Tue' ); 151 $this->weekday_abbrev[ $this->weekday[3] ] = /* translators: Three-letter abbreviation of the weekday. */ __( 'Wed' ); 152 $this->weekday_abbrev[ $this->weekday[4] ] = /* translators: Three-letter abbreviation of the weekday. */ __( 'Thu' ); 153 $this->weekday_abbrev[ $this->weekday[5] ] = /* translators: Three-letter abbreviation of the weekday. */ __( 'Fri' ); 154 $this->weekday_abbrev[ $this->weekday[6] ] = /* translators: Three-letter abbreviation of the weekday. */ __( 'Sat' ); 155 156 // The months. 157 $this->month['01'] = /* translators: Month name. */ __( 'January' ); 158 $this->month['02'] = /* translators: Month name. */ __( 'February' ); 159 $this->month['03'] = /* translators: Month name. */ __( 'March' ); 160 $this->month['04'] = /* translators: Month name. */ __( 'April' ); 161 $this->month['05'] = /* translators: Month name. */ __( 'May' ); 162 $this->month['06'] = /* translators: Month name. */ __( 'June' ); 163 $this->month['07'] = /* translators: Month name. */ __( 'July' ); 164 $this->month['08'] = /* translators: Month name. */ __( 'August' ); 165 $this->month['09'] = /* translators: Month name. */ __( 'September' ); 166 $this->month['10'] = /* translators: Month name. */ __( 'October' ); 167 $this->month['11'] = /* translators: Month name. */ __( 'November' ); 168 $this->month['12'] = /* translators: Month name. */ __( 'December' ); 169 170 // The months, genitive. 171 $this->month_genitive['01'] = /* translators: Month name, genitive. */ _x( 'January', 'genitive' ); 172 $this->month_genitive['02'] = /* translators: Month name, genitive. */ _x( 'February', 'genitive' ); 173 $this->month_genitive['03'] = /* translators: Month name, genitive. */ _x( 'March', 'genitive' ); 174 $this->month_genitive['04'] = /* translators: Month name, genitive. */ _x( 'April', 'genitive' ); 175 $this->month_genitive['05'] = /* translators: Month name, genitive. */ _x( 'May', 'genitive' ); 176 $this->month_genitive['06'] = /* translators: Month name, genitive. */ _x( 'June', 'genitive' ); 177 $this->month_genitive['07'] = /* translators: Month name, genitive. */ _x( 'July', 'genitive' ); 178 $this->month_genitive['08'] = /* translators: Month name, genitive. */ _x( 'August', 'genitive' ); 179 $this->month_genitive['09'] = /* translators: Month name, genitive. */ _x( 'September', 'genitive' ); 180 $this->month_genitive['10'] = /* translators: Month name, genitive. */ _x( 'October', 'genitive' ); 181 $this->month_genitive['11'] = /* translators: Month name, genitive. */ _x( 'November', 'genitive' ); 182 $this->month_genitive['12'] = /* translators: Month name, genitive. */ _x( 'December', 'genitive' ); 183 184 // Abbreviations for each month. 185 $this->month_abbrev[ $this->month['01'] ] = /* translators: Three-letter abbreviation of the month. */ _x( 'Jan', 'January abbreviation' ); 186 $this->month_abbrev[ $this->month['02'] ] = /* translators: Three-letter abbreviation of the month. */ _x( 'Feb', 'February abbreviation' ); 187 $this->month_abbrev[ $this->month['03'] ] = /* translators: Three-letter abbreviation of the month. */ _x( 'Mar', 'March abbreviation' ); 188 $this->month_abbrev[ $this->month['04'] ] = /* translators: Three-letter abbreviation of the month. */ _x( 'Apr', 'April abbreviation' ); 189 $this->month_abbrev[ $this->month['05'] ] = /* translators: Three-letter abbreviation of the month. */ _x( 'May', 'May abbreviation' ); 190 $this->month_abbrev[ $this->month['06'] ] = /* translators: Three-letter abbreviation of the month. */ _x( 'Jun', 'June abbreviation' ); 191 $this->month_abbrev[ $this->month['07'] ] = /* translators: Three-letter abbreviation of the month. */ _x( 'Jul', 'July abbreviation' ); 192 $this->month_abbrev[ $this->month['08'] ] = /* translators: Three-letter abbreviation of the month. */ _x( 'Aug', 'August abbreviation' ); 193 $this->month_abbrev[ $this->month['09'] ] = /* translators: Three-letter abbreviation of the month. */ _x( 'Sep', 'September abbreviation' ); 194 $this->month_abbrev[ $this->month['10'] ] = /* translators: Three-letter abbreviation of the month. */ _x( 'Oct', 'October abbreviation' ); 195 $this->month_abbrev[ $this->month['11'] ] = /* translators: Three-letter abbreviation of the month. */ _x( 'Nov', 'November abbreviation' ); 196 $this->month_abbrev[ $this->month['12'] ] = /* translators: Three-letter abbreviation of the month. */ _x( 'Dec', 'December abbreviation' ); 197 198 // The meridiems. 199 $this->meridiem['am'] = __( 'am' ); 200 $this->meridiem['pm'] = __( 'pm' ); 201 $this->meridiem['AM'] = __( 'AM' ); 202 $this->meridiem['PM'] = __( 'PM' ); 203 204 // Numbers formatting. 205 // See https://www.php.net/number_format 206 207 /* translators: $thousands_sep argument for https://www.php.net/number_format, default is ',' */ 208 $thousands_sep = __( 'number_format_thousands_sep' ); 209 210 // Replace space with a non-breaking space to avoid wrapping. 211 $thousands_sep = str_replace( ' ', ' ', $thousands_sep ); 212 213 $this->number_format['thousands_sep'] = ( 'number_format_thousands_sep' === $thousands_sep ) ? ',' : $thousands_sep; 214 215 /* translators: $dec_point argument for https://www.php.net/number_format, default is '.' */ 216 $decimal_point = __( 'number_format_decimal_point' ); 217 218 $this->number_format['decimal_point'] = ( 'number_format_decimal_point' === $decimal_point ) ? '.' : $decimal_point; 219 220 /* translators: used between list items, there is a space after the comma */ 221 $this->list_item_separator = __( ', ' ); 222 223 // Set text direction. 224 if ( isset( $GLOBALS['text_direction'] ) ) { 225 $this->text_direction = $GLOBALS['text_direction']; 226 227 /* translators: 'rtl' or 'ltr'. This sets the text direction for WordPress. */ 228 } elseif ( 'rtl' === _x( 'ltr', 'text direction' ) ) { 229 $this->text_direction = 'rtl'; 230 } 231 } 232 233 /** 234 * Retrieves the full translated weekday word. 235 * 236 * Week starts on translated Sunday and can be fetched 237 * by using 0 (zero). So the week starts with 0 (zero) 238 * and ends on Saturday with is fetched by using 6 (six). 239 * 240 * @since 2.1.0 241 * 242 * @param int $weekday_number 0 for Sunday through 6 Saturday. 243 * @return string Full translated weekday. 244 */ 245 public function get_weekday( $weekday_number ) { 246 return $this->weekday[ $weekday_number ]; 247 } 248 249 /** 250 * Retrieves the translated weekday initial. 251 * 252 * The weekday initial is retrieved by the translated 253 * full weekday word. When translating the weekday initial 254 * pay attention to make sure that the starting letter does 255 * not conflict. 256 * 257 * @since 2.1.0 258 * 259 * @param string $weekday_name Full translated weekday word. 260 * @return string Translated weekday initial. 261 */ 262 public function get_weekday_initial( $weekday_name ) { 263 return $this->weekday_initial[ $weekday_name ]; 264 } 265 266 /** 267 * Retrieves the translated weekday abbreviation. 268 * 269 * The weekday abbreviation is retrieved by the translated 270 * full weekday word. 271 * 272 * @since 2.1.0 273 * 274 * @param string $weekday_name Full translated weekday word. 275 * @return string Translated weekday abbreviation. 276 */ 277 public function get_weekday_abbrev( $weekday_name ) { 278 return $this->weekday_abbrev[ $weekday_name ]; 279 } 280 281 /** 282 * Retrieves the full translated month by month number. 283 * 284 * The $month_number parameter has to be a string 285 * because it must have the '0' in front of any number 286 * that is less than 10. Starts from '01' and ends at 287 * '12'. 288 * 289 * You can use an integer instead and it will add the 290 * '0' before the numbers less than 10 for you. 291 * 292 * @since 2.1.0 293 * 294 * @param string|int $month_number '01' through '12'. 295 * @return string Translated full month name. 296 */ 297 public function get_month( $month_number ) { 298 return $this->month[ zeroise( $month_number, 2 ) ]; 299 } 300 301 /** 302 * Retrieves translated version of month abbreviation string. 303 * 304 * The $month_name parameter is expected to be the translated or 305 * translatable version of the month. 306 * 307 * @since 2.1.0 308 * 309 * @param string $month_name Translated month to get abbreviated version. 310 * @return string Translated abbreviated month. 311 */ 312 public function get_month_abbrev( $month_name ) { 313 return $this->month_abbrev[ $month_name ]; 314 } 315 316 /** 317 * Retrieves translated version of meridiem string. 318 * 319 * The $meridiem parameter is expected to not be translated. 320 * 321 * @since 2.1.0 322 * 323 * @param string $meridiem Either 'am', 'pm', 'AM', or 'PM'. Not translated version. 324 * @return string Translated version 325 */ 326 public function get_meridiem( $meridiem ) { 327 return $this->meridiem[ $meridiem ]; 328 } 329 330 /** 331 * Global variables are deprecated. 332 * 333 * For backward compatibility only. 334 * 335 * @deprecated For backward compatibility only. 336 * 337 * @global array $weekday 338 * @global array $weekday_initial 339 * @global array $weekday_abbrev 340 * @global array $month 341 * @global array $month_abbrev 342 * 343 * @since 2.1.0 344 */ 345 public function register_globals() { 346 $GLOBALS['weekday'] = $this->weekday; 347 $GLOBALS['weekday_initial'] = $this->weekday_initial; 348 $GLOBALS['weekday_abbrev'] = $this->weekday_abbrev; 349 $GLOBALS['month'] = $this->month; 350 $GLOBALS['month_abbrev'] = $this->month_abbrev; 351 } 352 353 /** 354 * Checks if current locale is RTL. 355 * 356 * @since 3.0.0 357 * @return bool Whether locale is RTL. 358 */ 359 public function is_rtl() { 360 return 'rtl' === $this->text_direction; 361 } 362 363 /** 364 * Registers date/time format strings for general POT. 365 * 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. 369 * 370 * @since 3.6.0 371 */ 372 public function _strings_for_pot() { 373 /* translators: Localized date format, see https://www.php.net/manual/datetime.format.php */ 374 __( 'F j, Y' ); 375 /* translators: Localized time format, see https://www.php.net/manual/datetime.format.php */ 376 __( 'g:i a' ); 377 /* translators: Localized date and time format, see https://www.php.net/manual/datetime.format.php */ 378 __( 'F j, Y g:i a' ); 379 } 380 381 /** 382 * Retrieves the localized list item separator. 383 * 384 * @since 6.0.0 385 * 386 * @return string Localized list item separator. 387 */ 388 public function get_list_item_separator() { 389 return $this->list_item_separator; 390 } 391 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Nov 21 01:00:03 2024 | Cross-referenced by PHPXref 0.7.1 |