wp/wp-includes/class-wp-locale.php
changeset 19 3d72ae0968f4
parent 18 be944660c56a
child 21 48c4eec2b7e6
equal deleted inserted replaced
18:be944660c56a 19:3d72ae0968f4
    16 class WP_Locale {
    16 class WP_Locale {
    17 	/**
    17 	/**
    18 	 * Stores the translated strings for the full weekday names.
    18 	 * Stores the translated strings for the full weekday names.
    19 	 *
    19 	 *
    20 	 * @since 2.1.0
    20 	 * @since 2.1.0
    21 	 * @var array
    21 	 * @var string[]
    22 	 */
    22 	 */
    23 	public $weekday;
    23 	public $weekday;
    24 
    24 
    25 	/**
    25 	/**
    26 	 * Stores the translated strings for the one character weekday names.
    26 	 * Stores the translated strings for the one character weekday names.
    29 	 * as Sunday and Saturday, don't conflict. See init() method for more.
    29 	 * as Sunday and Saturday, don't conflict. See init() method for more.
    30 	 *
    30 	 *
    31 	 * @see WP_Locale::init() for how to handle the hack.
    31 	 * @see WP_Locale::init() for how to handle the hack.
    32 	 *
    32 	 *
    33 	 * @since 2.1.0
    33 	 * @since 2.1.0
    34 	 * @var array
    34 	 * @var string[]
    35 	 */
    35 	 */
    36 	public $weekday_initial;
    36 	public $weekday_initial;
    37 
    37 
    38 	/**
    38 	/**
    39 	 * Stores the translated strings for the abbreviated weekday names.
    39 	 * Stores the translated strings for the abbreviated weekday names.
    40 	 *
    40 	 *
    41 	 * @since 2.1.0
    41 	 * @since 2.1.0
    42 	 * @var array
    42 	 * @var string[]
    43 	 */
    43 	 */
    44 	public $weekday_abbrev;
    44 	public $weekday_abbrev;
    45 
    45 
    46 	/**
    46 	/**
    47 	 * Stores the translated strings for the full month names.
    47 	 * Stores the translated strings for the full month names.
    48 	 *
    48 	 *
    49 	 * @since 2.1.0
    49 	 * @since 2.1.0
    50 	 * @var array
    50 	 * @var string[]
    51 	 */
    51 	 */
    52 	public $month;
    52 	public $month;
    53 
    53 
    54 	/**
    54 	/**
    55 	 * Stores the translated strings for the month names in genitive case, if the locale specifies.
    55 	 * Stores the translated strings for the month names in genitive case, if the locale specifies.
    56 	 *
    56 	 *
    57 	 * @since 4.4.0
    57 	 * @since 4.4.0
    58 	 * @var array
    58 	 * @var string[]
    59 	 */
    59 	 */
    60 	public $month_genitive;
    60 	public $month_genitive;
    61 
    61 
    62 	/**
    62 	/**
    63 	 * Stores the translated strings for the abbreviated month names.
    63 	 * Stores the translated strings for the abbreviated month names.
    64 	 *
    64 	 *
    65 	 * @since 2.1.0
    65 	 * @since 2.1.0
    66 	 * @var array
    66 	 * @var string[]
    67 	 */
    67 	 */
    68 	public $month_abbrev;
    68 	public $month_abbrev;
    69 
    69 
    70 	/**
    70 	/**
    71 	 * Stores the translated strings for 'am' and 'pm'.
    71 	 * Stores the translated strings for 'am' and 'pm'.
    72 	 *
    72 	 *
    73 	 * Also the capitalized versions.
    73 	 * Also the capitalized versions.
    74 	 *
    74 	 *
    75 	 * @since 2.1.0
    75 	 * @since 2.1.0
    76 	 * @var array
    76 	 * @var string[]
    77 	 */
    77 	 */
    78 	public $meridiem;
    78 	public $meridiem;
    79 
    79 
    80 	/**
    80 	/**
    81 	 * The text direction of the locale language.
    81 	 * The text direction of the locale language.
    92 	 *
    92 	 *
    93 	 * @since 2.3.0
    93 	 * @since 2.3.0
    94 	 * @var array
    94 	 * @var array
    95 	 */
    95 	 */
    96 	public $number_format;
    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;
    97 
   105 
    98 	/**
   106 	/**
    99 	 * Constructor which calls helper methods to set up object variables.
   107 	 * Constructor which calls helper methods to set up object variables.
   100 	 *
   108 	 *
   101 	 * @since 2.1.0
   109 	 * @since 2.1.0
   126 		$this->weekday[4] = /* translators: Weekday. */ __( 'Thursday' );
   134 		$this->weekday[4] = /* translators: Weekday. */ __( 'Thursday' );
   127 		$this->weekday[5] = /* translators: Weekday. */ __( 'Friday' );
   135 		$this->weekday[5] = /* translators: Weekday. */ __( 'Friday' );
   128 		$this->weekday[6] = /* translators: Weekday. */ __( 'Saturday' );
   136 		$this->weekday[6] = /* translators: Weekday. */ __( 'Saturday' );
   129 
   137 
   130 		// The first letter of each day.
   138 		// The first letter of each day.
   131 		$this->weekday_initial[ __( 'Sunday' ) ]    = /* translators: One-letter abbreviation of the weekday. */ _x( 'S', 'Sunday initial' );
   139 		$this->weekday_initial[ $this->weekday[0] ] = /* 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' );
   140 		$this->weekday_initial[ $this->weekday[1] ] = /* 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' );
   141 		$this->weekday_initial[ $this->weekday[2] ] = /* 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' );
   142 		$this->weekday_initial[ $this->weekday[3] ] = /* 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' );
   143 		$this->weekday_initial[ $this->weekday[4] ] = /* 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' );
   144 		$this->weekday_initial[ $this->weekday[5] ] = /* 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' );
   145 		$this->weekday_initial[ $this->weekday[6] ] = /* translators: One-letter abbreviation of the weekday. */ _x( 'S', 'Saturday initial' );
   138 
   146 
   139 		// Abbreviations for each day.
   147 		// Abbreviations for each day.
   140 		$this->weekday_abbrev[ __( 'Sunday' ) ]    = /* translators: Three-letter abbreviation of the weekday. */ __( 'Sun' );
   148 		$this->weekday_abbrev[ $this->weekday[0] ] = /* translators: Three-letter abbreviation of the weekday. */ __( 'Sun' );
   141 		$this->weekday_abbrev[ __( 'Monday' ) ]    = /* translators: Ttree-letter abbreviation of the weekday. */ __( 'Mon' );
   149 		$this->weekday_abbrev[ $this->weekday[1] ] = /* translators: Three-letter abbreviation of the weekday. */ __( 'Mon' );
   142 		$this->weekday_abbrev[ __( 'Tuesday' ) ]   = /* translators: Three-letter abbreviation of the weekday. */ __( 'Tue' );
   150 		$this->weekday_abbrev[ $this->weekday[2] ] = /* translators: Three-letter abbreviation of the weekday. */ __( 'Tue' );
   143 		$this->weekday_abbrev[ __( 'Wednesday' ) ] = /* translators: Three-letter abbreviation of the weekday. */ __( 'Wed' );
   151 		$this->weekday_abbrev[ $this->weekday[3] ] = /* translators: Three-letter abbreviation of the weekday. */ __( 'Wed' );
   144 		$this->weekday_abbrev[ __( 'Thursday' ) ]  = /* translators: Three-letter abbreviation of the weekday. */ __( 'Thu' );
   152 		$this->weekday_abbrev[ $this->weekday[4] ] = /* translators: Three-letter abbreviation of the weekday. */ __( 'Thu' );
   145 		$this->weekday_abbrev[ __( 'Friday' ) ]    = /* translators: Three-letter abbreviation of the weekday. */ __( 'Fri' );
   153 		$this->weekday_abbrev[ $this->weekday[5] ] = /* translators: Three-letter abbreviation of the weekday. */ __( 'Fri' );
   146 		$this->weekday_abbrev[ __( 'Saturday' ) ]  = /* translators: Three-letter abbreviation of the weekday. */ __( 'Sat' );
   154 		$this->weekday_abbrev[ $this->weekday[6] ] = /* translators: Three-letter abbreviation of the weekday. */ __( 'Sat' );
   147 
   155 
   148 		// The months.
   156 		// The months.
   149 		$this->month['01'] = /* translators: Month name. */ __( 'January' );
   157 		$this->month['01'] = /* translators: Month name. */ __( 'January' );
   150 		$this->month['02'] = /* translators: Month name. */ __( 'February' );
   158 		$this->month['02'] = /* translators: Month name. */ __( 'February' );
   151 		$this->month['03'] = /* translators: Month name. */ __( 'March' );
   159 		$this->month['03'] = /* translators: Month name. */ __( 'March' );
   172 		$this->month_genitive['10'] = /* translators: Month name, genitive. */ _x( 'October', 'genitive' );
   180 		$this->month_genitive['10'] = /* translators: Month name, genitive. */ _x( 'October', 'genitive' );
   173 		$this->month_genitive['11'] = /* translators: Month name, genitive. */ _x( 'November', 'genitive' );
   181 		$this->month_genitive['11'] = /* translators: Month name, genitive. */ _x( 'November', 'genitive' );
   174 		$this->month_genitive['12'] = /* translators: Month name, genitive. */ _x( 'December', 'genitive' );
   182 		$this->month_genitive['12'] = /* translators: Month name, genitive. */ _x( 'December', 'genitive' );
   175 
   183 
   176 		// Abbreviations for each month.
   184 		// Abbreviations for each month.
   177 		$this->month_abbrev[ __( 'January' ) ]   = /* translators: Three-letter abbreviation of the month. */ _x( 'Jan', 'January abbreviation' );
   185 		$this->month_abbrev[ $this->month['01'] ] = /* 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' );
   186 		$this->month_abbrev[ $this->month['02'] ] = /* 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' );
   187 		$this->month_abbrev[ $this->month['03'] ] = /* 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' );
   188 		$this->month_abbrev[ $this->month['04'] ] = /* 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' );
   189 		$this->month_abbrev[ $this->month['05'] ] = /* 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' );
   190 		$this->month_abbrev[ $this->month['06'] ] = /* 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' );
   191 		$this->month_abbrev[ $this->month['07'] ] = /* 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' );
   192 		$this->month_abbrev[ $this->month['08'] ] = /* 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' );
   193 		$this->month_abbrev[ $this->month['09'] ] = /* 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' );
   194 		$this->month_abbrev[ $this->month['10'] ] = /* 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' );
   195 		$this->month_abbrev[ $this->month['11'] ] = /* 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' );
   196 		$this->month_abbrev[ $this->month['12'] ] = /* translators: Three-letter abbreviation of the month. */ _x( 'Dec', 'December abbreviation' );
   189 
   197 
   190 		// The meridiems.
   198 		// The meridiems.
   191 		$this->meridiem['am'] = __( 'am' );
   199 		$this->meridiem['am'] = __( 'am' );
   192 		$this->meridiem['pm'] = __( 'pm' );
   200 		$this->meridiem['pm'] = __( 'pm' );
   193 		$this->meridiem['AM'] = __( 'AM' );
   201 		$this->meridiem['AM'] = __( 'AM' );
   207 		/* translators: $dec_point argument for https://www.php.net/number_format, default is '.' */
   215 		/* translators: $dec_point argument for https://www.php.net/number_format, default is '.' */
   208 		$decimal_point = __( 'number_format_decimal_point' );
   216 		$decimal_point = __( 'number_format_decimal_point' );
   209 
   217 
   210 		$this->number_format['decimal_point'] = ( 'number_format_decimal_point' === $decimal_point ) ? '.' : $decimal_point;
   218 		$this->number_format['decimal_point'] = ( 'number_format_decimal_point' === $decimal_point ) ? '.' : $decimal_point;
   211 
   219 
       
   220 		/* translators: used between list items, there is a space after the comma */
       
   221 		$this->list_item_separator = __( ', ' );
       
   222 
   212 		// Set text direction.
   223 		// Set text direction.
   213 		if ( isset( $GLOBALS['text_direction'] ) ) {
   224 		if ( isset( $GLOBALS['text_direction'] ) ) {
   214 			$this->text_direction = $GLOBALS['text_direction'];
   225 			$this->text_direction = $GLOBALS['text_direction'];
   215 
   226 
   216 			/* translators: 'rtl' or 'ltr'. This sets the text direction for WordPress. */
   227 			/* translators: 'rtl' or 'ltr'. This sets the text direction for WordPress. */
   218 			$this->text_direction = 'rtl';
   229 			$this->text_direction = 'rtl';
   219 		}
   230 		}
   220 	}
   231 	}
   221 
   232 
   222 	/**
   233 	/**
   223 	 * Retrieve the full translated weekday word.
   234 	 * Retrieves the full translated weekday word.
   224 	 *
   235 	 *
   225 	 * Week starts on translated Sunday and can be fetched
   236 	 * Week starts on translated Sunday and can be fetched
   226 	 * by using 0 (zero). So the week starts with 0 (zero)
   237 	 * by using 0 (zero). So the week starts with 0 (zero)
   227 	 * and ends on Saturday with is fetched by using 6 (six).
   238 	 * and ends on Saturday with is fetched by using 6 (six).
   228 	 *
   239 	 *
   234 	public function get_weekday( $weekday_number ) {
   245 	public function get_weekday( $weekday_number ) {
   235 		return $this->weekday[ $weekday_number ];
   246 		return $this->weekday[ $weekday_number ];
   236 	}
   247 	}
   237 
   248 
   238 	/**
   249 	/**
   239 	 * Retrieve the translated weekday initial.
   250 	 * Retrieves the translated weekday initial.
   240 	 *
   251 	 *
   241 	 * The weekday initial is retrieved by the translated
   252 	 * The weekday initial is retrieved by the translated
   242 	 * full weekday word. When translating the weekday initial
   253 	 * full weekday word. When translating the weekday initial
   243 	 * pay attention to make sure that the starting letter does
   254 	 * pay attention to make sure that the starting letter does
   244 	 * not conflict.
   255 	 * not conflict.
   251 	public function get_weekday_initial( $weekday_name ) {
   262 	public function get_weekday_initial( $weekday_name ) {
   252 		return $this->weekday_initial[ $weekday_name ];
   263 		return $this->weekday_initial[ $weekday_name ];
   253 	}
   264 	}
   254 
   265 
   255 	/**
   266 	/**
   256 	 * Retrieve the translated weekday abbreviation.
   267 	 * Retrieves the translated weekday abbreviation.
   257 	 *
   268 	 *
   258 	 * The weekday abbreviation is retrieved by the translated
   269 	 * The weekday abbreviation is retrieved by the translated
   259 	 * full weekday word.
   270 	 * full weekday word.
   260 	 *
   271 	 *
   261 	 * @since 2.1.0
   272 	 * @since 2.1.0
   266 	public function get_weekday_abbrev( $weekday_name ) {
   277 	public function get_weekday_abbrev( $weekday_name ) {
   267 		return $this->weekday_abbrev[ $weekday_name ];
   278 		return $this->weekday_abbrev[ $weekday_name ];
   268 	}
   279 	}
   269 
   280 
   270 	/**
   281 	/**
   271 	 * Retrieve the full translated month by month number.
   282 	 * Retrieves the full translated month by month number.
   272 	 *
   283 	 *
   273 	 * The $month_number parameter has to be a string
   284 	 * The $month_number parameter has to be a string
   274 	 * because it must have the '0' in front of any number
   285 	 * because it must have the '0' in front of any number
   275 	 * that is less than 10. Starts from '01' and ends at
   286 	 * that is less than 10. Starts from '01' and ends at
   276 	 * '12'.
   287 	 * '12'.
   286 	public function get_month( $month_number ) {
   297 	public function get_month( $month_number ) {
   287 		return $this->month[ zeroise( $month_number, 2 ) ];
   298 		return $this->month[ zeroise( $month_number, 2 ) ];
   288 	}
   299 	}
   289 
   300 
   290 	/**
   301 	/**
   291 	 * Retrieve translated version of month abbreviation string.
   302 	 * Retrieves translated version of month abbreviation string.
   292 	 *
   303 	 *
   293 	 * The $month_name parameter is expected to be the translated or
   304 	 * The $month_name parameter is expected to be the translated or
   294 	 * translatable version of the month.
   305 	 * translatable version of the month.
   295 	 *
   306 	 *
   296 	 * @since 2.1.0
   307 	 * @since 2.1.0
   301 	public function get_month_abbrev( $month_name ) {
   312 	public function get_month_abbrev( $month_name ) {
   302 		return $this->month_abbrev[ $month_name ];
   313 		return $this->month_abbrev[ $month_name ];
   303 	}
   314 	}
   304 
   315 
   305 	/**
   316 	/**
   306 	 * Retrieve translated version of meridiem string.
   317 	 * Retrieves translated version of meridiem string.
   307 	 *
   318 	 *
   308 	 * The $meridiem parameter is expected to not be translated.
   319 	 * The $meridiem parameter is expected to not be translated.
   309 	 *
   320 	 *
   310 	 * @since 2.1.0
   321 	 * @since 2.1.0
   311 	 *
   322 	 *
   348 	public function is_rtl() {
   359 	public function is_rtl() {
   349 		return 'rtl' === $this->text_direction;
   360 		return 'rtl' === $this->text_direction;
   350 	}
   361 	}
   351 
   362 
   352 	/**
   363 	/**
   353 	 * Register date/time format strings for general POT.
   364 	 * Registers date/time format strings for general POT.
   354 	 *
   365 	 *
   355 	 * Private, unused method to add some date/time formats translated
   366 	 * Private, unused method to add some date/time formats translated
   356 	 * on wp-admin/options-general.php to the general POT that would
   367 	 * on wp-admin/options-general.php to the general POT that would
   357 	 * otherwise be added to the admin POT.
   368 	 * otherwise be added to the admin POT.
   358 	 *
   369 	 *
   364 		/* translators: Localized time format, see https://www.php.net/manual/datetime.format.php */
   375 		/* translators: Localized time format, see https://www.php.net/manual/datetime.format.php */
   365 		__( 'g:i a' );
   376 		__( 'g:i a' );
   366 		/* translators: Localized date and time format, see https://www.php.net/manual/datetime.format.php */
   377 		/* translators: Localized date and time format, see https://www.php.net/manual/datetime.format.php */
   367 		__( 'F j, Y g:i a' );
   378 		__( 'F j, Y g:i a' );
   368 	}
   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 	}
   369 }
   391 }