[ Index ]

PHP Cross Reference of WordPress

title

Body

[close]

/wp-includes/ -> class-wp-locale.php (source)

   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 array
  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 array
  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 array
  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 array
  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 array
  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 array
  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 array
  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       * Constructor which calls helper methods to set up object variables.
 100       *
 101       * @since 2.1.0
 102       */
 103  	public function __construct() {
 104          $this->init();
 105          $this->register_globals();
 106      }
 107  
 108      /**
 109       * Sets up the translated strings and object properties.
 110       *
 111       * The method creates the translatable strings for various
 112       * calendar elements. Which allows for specifying locale
 113       * specific calendar names and text direction.
 114       *
 115       * @since 2.1.0
 116       *
 117       * @global string $text_direction
 118       * @global string $wp_version
 119       */
 120  	public function init() {
 121          // The Weekdays
 122          $this->weekday[0] = /* translators: Weekday. */ __( 'Sunday' );
 123          $this->weekday[1] = /* translators: Weekday. */ __( 'Monday' );
 124          $this->weekday[2] = /* translators: Weekday. */ __( 'Tuesday' );
 125          $this->weekday[3] = /* translators: Weekday. */ __( 'Wednesday' );
 126          $this->weekday[4] = /* translators: Weekday. */ __( 'Thursday' );
 127          $this->weekday[5] = /* translators: Weekday. */ __( 'Friday' );
 128          $this->weekday[6] = /* translators: Weekday. */ __( 'Saturday' );
 129  
 130          // The first letter of each day.
 131          $this->weekday_initial[ __( 'Sunday' ) ]    = /* translators: One-letter abbreviation of the weekday. */ _x( 'S', 'Sunday initial' );
 132          $this->weekday_initial[ __( 'Monday' ) ]    = /* translators: One-letter abbreviation of the weekday. */ _x( 'M', 'Monday initial' );
 133          $this->weekday_initial[ __( 'Tuesday' ) ]   = /* translators: One-letter abbreviation of the weekday. */ _x( 'T', 'Tuesday initial' );
 134          $this->weekday_initial[ __( 'Wednesday' ) ] = /* translators: One-letter abbreviation of the weekday. */ _x( 'W', 'Wednesday initial' );
 135          $this->weekday_initial[ __( 'Thursday' ) ]  = /* translators: One-letter abbreviation of the weekday. */ _x( 'T', 'Thursday initial' );
 136          $this->weekday_initial[ __( 'Friday' ) ]    = /* translators: One-letter abbreviation of the weekday. */ _x( 'F', 'Friday initial' );
 137          $this->weekday_initial[ __( 'Saturday' ) ]  = /* translators: One-letter abbreviation of the weekday. */ _x( 'S', 'Saturday initial' );
 138  
 139          // Abbreviations for each day.
 140          $this->weekday_abbrev[ __( 'Sunday' ) ]    = /* translators: Three-letter abbreviation of the weekday. */ __( 'Sun' );
 141          $this->weekday_abbrev[ __( 'Monday' ) ]    = /* translators: Ttree-letter abbreviation of the weekday. */ __( 'Mon' );
 142          $this->weekday_abbrev[ __( 'Tuesday' ) ]   = /* translators: Three-letter abbreviation of the weekday. */ __( 'Tue' );
 143          $this->weekday_abbrev[ __( 'Wednesday' ) ] = /* translators: Three-letter abbreviation of the weekday. */ __( 'Wed' );
 144          $this->weekday_abbrev[ __( 'Thursday' ) ]  = /* translators: Three-letter abbreviation of the weekday. */ __( 'Thu' );
 145          $this->weekday_abbrev[ __( 'Friday' ) ]    = /* translators: Three-letter abbreviation of the weekday. */ __( 'Fri' );
 146          $this->weekday_abbrev[ __( 'Saturday' ) ]  = /* translators: Three-letter abbreviation of the weekday. */ __( 'Sat' );
 147  
 148          // The Months
 149          $this->month['01'] = /* translators: Month name. */ __( 'January' );
 150          $this->month['02'] = /* translators: Month name. */ __( 'February' );
 151          $this->month['03'] = /* translators: Month name. */ __( 'March' );
 152          $this->month['04'] = /* translators: Month name. */ __( 'April' );
 153          $this->month['05'] = /* translators: Month name. */ __( 'May' );
 154          $this->month['06'] = /* translators: Month name. */ __( 'June' );
 155          $this->month['07'] = /* translators: Month name. */ __( 'July' );
 156          $this->month['08'] = /* translators: Month name. */ __( 'August' );
 157          $this->month['09'] = /* translators: Month name. */ __( 'September' );
 158          $this->month['10'] = /* translators: Month name. */ __( 'October' );
 159          $this->month['11'] = /* translators: Month name. */ __( 'November' );
 160          $this->month['12'] = /* translators: Month name. */ __( 'December' );
 161  
 162          // The Months, genitive
 163          $this->month_genitive['01'] = /* translators: Month name, genitive. */ _x( 'January', 'genitive' );
 164          $this->month_genitive['02'] = /* translators: Month name, genitive. */ _x( 'February', 'genitive' );
 165          $this->month_genitive['03'] = /* translators: Month name, genitive. */ _x( 'March', 'genitive' );
 166          $this->month_genitive['04'] = /* translators: Month name, genitive. */ _x( 'April', 'genitive' );
 167          $this->month_genitive['05'] = /* translators: Month name, genitive. */ _x( 'May', 'genitive' );
 168          $this->month_genitive['06'] = /* translators: Month name, genitive. */ _x( 'June', 'genitive' );
 169          $this->month_genitive['07'] = /* translators: Month name, genitive. */ _x( 'July', 'genitive' );
 170          $this->month_genitive['08'] = /* translators: Month name, genitive. */ _x( 'August', 'genitive' );
 171          $this->month_genitive['09'] = /* translators: Month name, genitive. */ _x( 'September', 'genitive' );
 172          $this->month_genitive['10'] = /* translators: Month name, genitive. */ _x( 'October', 'genitive' );
 173          $this->month_genitive['11'] = /* translators: Month name, genitive. */ _x( 'November', 'genitive' );
 174          $this->month_genitive['12'] = /* translators: Month name, genitive. */ _x( 'December', 'genitive' );
 175  
 176          // Abbreviations for each month.
 177          $this->month_abbrev[ __( 'January' ) ]   = /* translators: Three-letter abbreviation of the month. */ _x( 'Jan', 'January abbreviation' );
 178          $this->month_abbrev[ __( 'February' ) ]  = /* translators: Three-letter abbreviation of the month. */ _x( 'Feb', 'February abbreviation' );
 179          $this->month_abbrev[ __( 'March' ) ]     = /* translators: Three-letter abbreviation of the month. */ _x( 'Mar', 'March abbreviation' );
 180          $this->month_abbrev[ __( 'April' ) ]     = /* translators: Three-letter abbreviation of the month. */ _x( 'Apr', 'April abbreviation' );
 181          $this->month_abbrev[ __( 'May' ) ]       = /* translators: Three-letter abbreviation of the month. */ _x( 'May', 'May abbreviation' );
 182          $this->month_abbrev[ __( 'June' ) ]      = /* translators: Three-letter abbreviation of the month. */ _x( 'Jun', 'June abbreviation' );
 183          $this->month_abbrev[ __( 'July' ) ]      = /* translators: Three-letter abbreviation of the month. */ _x( 'Jul', 'July abbreviation' );
 184          $this->month_abbrev[ __( 'August' ) ]    = /* translators: Three-letter abbreviation of the month. */ _x( 'Aug', 'August abbreviation' );
 185          $this->month_abbrev[ __( 'September' ) ] = /* translators: Three-letter abbreviation of the month. */ _x( 'Sep', 'September abbreviation' );
 186          $this->month_abbrev[ __( 'October' ) ]   = /* translators: Three-letter abbreviation of the month. */ _x( 'Oct', 'October abbreviation' );
 187          $this->month_abbrev[ __( 'November' ) ]  = /* translators: Three-letter abbreviation of the month. */ _x( 'Nov', 'November abbreviation' );
 188          $this->month_abbrev[ __( 'December' ) ]  = /* translators: Three-letter abbreviation of the month. */ _x( 'Dec', 'December abbreviation' );
 189  
 190          // The Meridiems
 191          $this->meridiem['am'] = __( 'am' );
 192          $this->meridiem['pm'] = __( 'pm' );
 193          $this->meridiem['AM'] = __( 'AM' );
 194          $this->meridiem['PM'] = __( 'PM' );
 195  
 196          // Numbers formatting
 197          // See https://secure.php.net/number_format
 198  
 199          /* translators: $thousands_sep argument for https://secure.php.net/number_format, default is ',' */
 200          $thousands_sep = __( 'number_format_thousands_sep' );
 201  
 202          if ( version_compare( PHP_VERSION, '5.4', '>=' ) ) {
 203              // Replace space with a non-breaking space to avoid wrapping.
 204              $thousands_sep = str_replace( ' ', '&nbsp;', $thousands_sep );
 205          } else {
 206              // PHP < 5.4.0 does not support multiple bytes in thousands separator.
 207              $thousands_sep = str_replace( array( '&nbsp;', '&#160;' ), ' ', $thousands_sep );
 208          }
 209  
 210          $this->number_format['thousands_sep'] = ( 'number_format_thousands_sep' === $thousands_sep ) ? ',' : $thousands_sep;
 211  
 212          /* translators: $dec_point argument for https://secure.php.net/number_format, default is '.' */
 213          $decimal_point = __( 'number_format_decimal_point' );
 214  
 215          $this->number_format['decimal_point'] = ( 'number_format_decimal_point' === $decimal_point ) ? '.' : $decimal_point;
 216  
 217          // Set text direction.
 218          if ( isset( $GLOBALS['text_direction'] ) ) {
 219              $this->text_direction = $GLOBALS['text_direction'];
 220  
 221              /* translators: 'rtl' or 'ltr'. This sets the text direction for WordPress. */
 222          } elseif ( 'rtl' == _x( 'ltr', 'text direction' ) ) {
 223              $this->text_direction = 'rtl';
 224          }
 225      }
 226  
 227      /**
 228       * Retrieve the full translated weekday word.
 229       *
 230       * Week starts on translated Sunday and can be fetched
 231       * by using 0 (zero). So the week starts with 0 (zero)
 232       * and ends on Saturday with is fetched by using 6 (six).
 233       *
 234       * @since 2.1.0
 235       *
 236       * @param int $weekday_number 0 for Sunday through 6 Saturday.
 237       * @return string Full translated weekday.
 238       */
 239  	public function get_weekday( $weekday_number ) {
 240          return $this->weekday[ $weekday_number ];
 241      }
 242  
 243      /**
 244       * Retrieve the translated weekday initial.
 245       *
 246       * The weekday initial is retrieved by the translated
 247       * full weekday word. When translating the weekday initial
 248       * pay attention to make sure that the starting letter does
 249       * not conflict.
 250       *
 251       * @since 2.1.0
 252       *
 253       * @param string $weekday_name Full translated weekday word.
 254       * @return string Translated weekday initial.
 255       */
 256  	public function get_weekday_initial( $weekday_name ) {
 257          return $this->weekday_initial[ $weekday_name ];
 258      }
 259  
 260      /**
 261       * Retrieve the translated weekday abbreviation.
 262       *
 263       * The weekday abbreviation is retrieved by the translated
 264       * full weekday word.
 265       *
 266       * @since 2.1.0
 267       *
 268       * @param string $weekday_name Full translated weekday word.
 269       * @return string Translated weekday abbreviation.
 270       */
 271  	public function get_weekday_abbrev( $weekday_name ) {
 272          return $this->weekday_abbrev[ $weekday_name ];
 273      }
 274  
 275      /**
 276       * Retrieve the full translated month by month number.
 277       *
 278       * The $month_number parameter has to be a string
 279       * because it must have the '0' in front of any number
 280       * that is less than 10. Starts from '01' and ends at
 281       * '12'.
 282       *
 283       * You can use an integer instead and it will add the
 284       * '0' before the numbers less than 10 for you.
 285       *
 286       * @since 2.1.0
 287       *
 288       * @param string|int $month_number '01' through '12'.
 289       * @return string Translated full month name.
 290       */
 291  	public function get_month( $month_number ) {
 292          return $this->month[ zeroise( $month_number, 2 ) ];
 293      }
 294  
 295      /**
 296       * Retrieve translated version of month abbreviation string.
 297       *
 298       * The $month_name parameter is expected to be the translated or
 299       * translatable version of the month.
 300       *
 301       * @since 2.1.0
 302       *
 303       * @param string $month_name Translated month to get abbreviated version.
 304       * @return string Translated abbreviated month.
 305       */
 306  	public function get_month_abbrev( $month_name ) {
 307          return $this->month_abbrev[ $month_name ];
 308      }
 309  
 310      /**
 311       * Retrieve translated version of meridiem string.
 312       *
 313       * The $meridiem parameter is expected to not be translated.
 314       *
 315       * @since 2.1.0
 316       *
 317       * @param string $meridiem Either 'am', 'pm', 'AM', or 'PM'. Not translated version.
 318       * @return string Translated version
 319       */
 320  	public function get_meridiem( $meridiem ) {
 321          return $this->meridiem[ $meridiem ];
 322      }
 323  
 324      /**
 325       * Global variables are deprecated.
 326       *
 327       * For backward compatibility only.
 328       *
 329       * @deprecated For backward compatibility only.
 330       *
 331       * @global array $weekday
 332       * @global array $weekday_initial
 333       * @global array $weekday_abbrev
 334       * @global array $month
 335       * @global array $month_abbrev
 336       *
 337       * @since 2.1.0
 338       */
 339  	public function register_globals() {
 340          $GLOBALS['weekday']         = $this->weekday;
 341          $GLOBALS['weekday_initial'] = $this->weekday_initial;
 342          $GLOBALS['weekday_abbrev']  = $this->weekday_abbrev;
 343          $GLOBALS['month']           = $this->month;
 344          $GLOBALS['month_abbrev']    = $this->month_abbrev;
 345      }
 346  
 347      /**
 348       * Checks if current locale is RTL.
 349       *
 350       * @since 3.0.0
 351       * @return bool Whether locale is RTL.
 352       */
 353  	public function is_rtl() {
 354          return 'rtl' == $this->text_direction;
 355      }
 356  
 357      /**
 358       * Register date/time format strings for general POT.
 359       *
 360       * Private, unused method to add some date/time formats translated
 361       * on wp-admin/options-general.php to the general POT that would
 362       * otherwise be added to the admin POT.
 363       *
 364       * @since 3.6.0
 365       */
 366  	public function _strings_for_pot() {
 367          /* translators: Localized date format, see https://secure.php.net/date */
 368          __( 'F j, Y' );
 369          /* translators: Localized time format, see https://secure.php.net/date */
 370          __( 'g:i a' );
 371          /* translators: Localized date and time format, see https://secure.php.net/date */
 372          __( 'F j, Y g:i a' );
 373      }
 374  }


Generated: Tue Sep 17 01:00:03 2019 Cross-referenced by PHPXref 0.7.1