11 * Core class used to store translated data for a locale. |
11 * Core class used to store translated data for a locale. |
12 * |
12 * |
13 * @since 2.1.0 |
13 * @since 2.1.0 |
14 * @since 4.6.0 Moved to its own file from wp-includes/locale.php. |
14 * @since 4.6.0 Moved to its own file from wp-includes/locale.php. |
15 */ |
15 */ |
|
16 #[AllowDynamicProperties] |
16 class WP_Locale { |
17 class WP_Locale { |
17 /** |
18 /** |
18 * Stores the translated strings for the full weekday names. |
19 * Stores the translated strings for the full weekday names. |
19 * |
20 * |
20 * @since 2.1.0 |
21 * @since 2.1.0 |
21 * @var string[] |
22 * @since 6.2.0 Initialized to an empty array. |
22 */ |
23 * @var string[] |
23 public $weekday; |
24 */ |
|
25 public $weekday = array(); |
24 |
26 |
25 /** |
27 /** |
26 * Stores the translated strings for the one character weekday names. |
28 * Stores the translated strings for the one character weekday names. |
27 * |
29 * |
28 * There is a hack to make sure that Tuesday and Thursday, as well |
30 * 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. |
31 * as Sunday and Saturday, don't conflict. See init() method for more. |
30 * |
32 * |
31 * @see WP_Locale::init() for how to handle the hack. |
33 * @see WP_Locale::init() for how to handle the hack. |
32 * |
34 * |
33 * @since 2.1.0 |
35 * @since 2.1.0 |
34 * @var string[] |
36 * @since 6.2.0 Initialized to an empty array. |
35 */ |
37 * @var string[] |
36 public $weekday_initial; |
38 */ |
|
39 public $weekday_initial = array(); |
37 |
40 |
38 /** |
41 /** |
39 * Stores the translated strings for the abbreviated weekday names. |
42 * Stores the translated strings for the abbreviated weekday names. |
40 * |
43 * |
41 * @since 2.1.0 |
44 * @since 2.1.0 |
42 * @var string[] |
45 * @since 6.2.0 Initialized to an empty array. |
43 */ |
46 * @var string[] |
44 public $weekday_abbrev; |
47 */ |
|
48 public $weekday_abbrev = array(); |
45 |
49 |
46 /** |
50 /** |
47 * Stores the translated strings for the full month names. |
51 * Stores the translated strings for the full month names. |
48 * |
52 * |
49 * @since 2.1.0 |
53 * @since 2.1.0 |
50 * @var string[] |
54 * @since 6.2.0 Initialized to an empty array. |
51 */ |
55 * @var string[] |
52 public $month; |
56 */ |
|
57 public $month = array(); |
53 |
58 |
54 /** |
59 /** |
55 * Stores the translated strings for the month names in genitive case, if the locale specifies. |
60 * Stores the translated strings for the month names in genitive case, if the locale specifies. |
56 * |
61 * |
57 * @since 4.4.0 |
62 * @since 4.4.0 |
58 * @var string[] |
63 * @since 6.2.0 Initialized to an empty array. |
59 */ |
64 * @var string[] |
60 public $month_genitive; |
65 */ |
|
66 public $month_genitive = array(); |
61 |
67 |
62 /** |
68 /** |
63 * Stores the translated strings for the abbreviated month names. |
69 * Stores the translated strings for the abbreviated month names. |
64 * |
70 * |
65 * @since 2.1.0 |
71 * @since 2.1.0 |
66 * @var string[] |
72 * @since 6.2.0 Initialized to an empty array. |
67 */ |
73 * @var string[] |
68 public $month_abbrev; |
74 */ |
|
75 public $month_abbrev = array(); |
69 |
76 |
70 /** |
77 /** |
71 * Stores the translated strings for 'am' and 'pm'. |
78 * Stores the translated strings for 'am' and 'pm'. |
72 * |
79 * |
73 * Also the capitalized versions. |
80 * Also the capitalized versions. |
74 * |
81 * |
75 * @since 2.1.0 |
82 * @since 2.1.0 |
76 * @var string[] |
83 * @since 6.2.0 Initialized to an empty array. |
77 */ |
84 * @var string[] |
78 public $meridiem; |
85 */ |
|
86 public $meridiem = array(); |
79 |
87 |
80 /** |
88 /** |
81 * The text direction of the locale language. |
89 * The text direction of the locale language. |
82 * |
90 * |
83 * Default is left to right 'ltr'. |
91 * Default is left to right 'ltr'. |
89 |
97 |
90 /** |
98 /** |
91 * The thousands separator and decimal point values used for localizing numbers. |
99 * The thousands separator and decimal point values used for localizing numbers. |
92 * |
100 * |
93 * @since 2.3.0 |
101 * @since 2.3.0 |
|
102 * @since 6.2.0 Initialized to an empty array. |
94 * @var array |
103 * @var array |
95 */ |
104 */ |
96 public $number_format; |
105 public $number_format = array(); |
97 |
106 |
98 /** |
107 /** |
99 * The separator string used for localizing list item separator. |
108 * The separator string used for localizing list item separator. |
100 * |
109 * |
101 * @since 6.0.0 |
110 * @since 6.0.0 |
102 * @var string |
111 * @var string |
103 */ |
112 */ |
104 public $list_item_separator; |
113 public $list_item_separator; |
|
114 |
|
115 /** |
|
116 * The word count type of the locale language. |
|
117 * |
|
118 * Default is 'words'. |
|
119 * |
|
120 * @since 6.2.0 |
|
121 * @var string |
|
122 */ |
|
123 public $word_count_type; |
105 |
124 |
106 /** |
125 /** |
107 * Constructor which calls helper methods to set up object variables. |
126 * Constructor which calls helper methods to set up object variables. |
108 * |
127 * |
109 * @since 2.1.0 |
128 * @since 2.1.0 |
121 * specific calendar names and text direction. |
140 * specific calendar names and text direction. |
122 * |
141 * |
123 * @since 2.1.0 |
142 * @since 2.1.0 |
124 * |
143 * |
125 * @global string $text_direction |
144 * @global string $text_direction |
126 * @global string $wp_version The WordPress version string. |
|
127 */ |
145 */ |
128 public function init() { |
146 public function init() { |
129 // The weekdays. |
147 // The weekdays. |
130 $this->weekday[0] = /* translators: Weekday. */ __( 'Sunday' ); |
148 $this->weekday[0] = /* translators: Weekday. */ __( 'Sunday' ); |
131 $this->weekday[1] = /* translators: Weekday. */ __( 'Monday' ); |
149 $this->weekday[1] = /* translators: Weekday. */ __( 'Monday' ); |
199 $this->meridiem['am'] = __( 'am' ); |
217 $this->meridiem['am'] = __( 'am' ); |
200 $this->meridiem['pm'] = __( 'pm' ); |
218 $this->meridiem['pm'] = __( 'pm' ); |
201 $this->meridiem['AM'] = __( 'AM' ); |
219 $this->meridiem['AM'] = __( 'AM' ); |
202 $this->meridiem['PM'] = __( 'PM' ); |
220 $this->meridiem['PM'] = __( 'PM' ); |
203 |
221 |
204 // Numbers formatting. |
222 /* |
205 // See https://www.php.net/number_format |
223 * Numbers formatting. |
|
224 * See https://www.php.net/number_format |
|
225 */ |
206 |
226 |
207 /* translators: $thousands_sep argument for https://www.php.net/number_format, default is ',' */ |
227 /* translators: $thousands_sep argument for https://www.php.net/number_format, default is ',' */ |
208 $thousands_sep = __( 'number_format_thousands_sep' ); |
228 $thousands_sep = __( 'number_format_thousands_sep' ); |
209 |
229 |
210 // Replace space with a non-breaking space to avoid wrapping. |
230 // Replace space with a non-breaking space to avoid wrapping. |
215 /* translators: $dec_point argument for https://www.php.net/number_format, default is '.' */ |
235 /* translators: $dec_point argument for https://www.php.net/number_format, default is '.' */ |
216 $decimal_point = __( 'number_format_decimal_point' ); |
236 $decimal_point = __( 'number_format_decimal_point' ); |
217 |
237 |
218 $this->number_format['decimal_point'] = ( 'number_format_decimal_point' === $decimal_point ) ? '.' : $decimal_point; |
238 $this->number_format['decimal_point'] = ( 'number_format_decimal_point' === $decimal_point ) ? '.' : $decimal_point; |
219 |
239 |
220 /* translators: used between list items, there is a space after the comma */ |
240 /* translators: Used between list items, there is a space after the comma. */ |
221 $this->list_item_separator = __( ', ' ); |
241 $this->list_item_separator = __( ', ' ); |
222 |
242 |
223 // Set text direction. |
243 // Set text direction. |
224 if ( isset( $GLOBALS['text_direction'] ) ) { |
244 if ( isset( $GLOBALS['text_direction'] ) ) { |
225 $this->text_direction = $GLOBALS['text_direction']; |
245 $this->text_direction = $GLOBALS['text_direction']; |
226 |
246 |
227 /* translators: 'rtl' or 'ltr'. This sets the text direction for WordPress. */ |
247 /* translators: 'rtl' or 'ltr'. This sets the text direction for WordPress. */ |
228 } elseif ( 'rtl' === _x( 'ltr', 'text direction' ) ) { |
248 } elseif ( 'rtl' === _x( 'ltr', 'text direction' ) ) { |
229 $this->text_direction = 'rtl'; |
249 $this->text_direction = 'rtl'; |
230 } |
250 } |
|
251 |
|
252 // Set the word count type. |
|
253 $this->word_count_type = $this->get_word_count_type(); |
231 } |
254 } |
232 |
255 |
233 /** |
256 /** |
234 * Retrieves the full translated weekday word. |
257 * Retrieves the full translated weekday word. |
235 * |
258 * |
330 /** |
353 /** |
331 * Global variables are deprecated. |
354 * Global variables are deprecated. |
332 * |
355 * |
333 * For backward compatibility only. |
356 * For backward compatibility only. |
334 * |
357 * |
|
358 * @since 2.1.0 |
335 * @deprecated For backward compatibility only. |
359 * @deprecated For backward compatibility only. |
336 * |
360 * |
337 * @global array $weekday |
361 * @global array $weekday |
338 * @global array $weekday_initial |
362 * @global array $weekday_initial |
339 * @global array $weekday_abbrev |
363 * @global array $weekday_abbrev |
340 * @global array $month |
364 * @global array $month |
341 * @global array $month_abbrev |
365 * @global array $month_abbrev |
342 * |
|
343 * @since 2.1.0 |
|
344 */ |
366 */ |
345 public function register_globals() { |
367 public function register_globals() { |
346 $GLOBALS['weekday'] = $this->weekday; |
368 $GLOBALS['weekday'] = $this->weekday; |
347 $GLOBALS['weekday_initial'] = $this->weekday_initial; |
369 $GLOBALS['weekday_initial'] = $this->weekday_initial; |
348 $GLOBALS['weekday_abbrev'] = $this->weekday_abbrev; |
370 $GLOBALS['weekday_abbrev'] = $this->weekday_abbrev; |
386 * @return string Localized list item separator. |
408 * @return string Localized list item separator. |
387 */ |
409 */ |
388 public function get_list_item_separator() { |
410 public function get_list_item_separator() { |
389 return $this->list_item_separator; |
411 return $this->list_item_separator; |
390 } |
412 } |
|
413 |
|
414 /** |
|
415 * Retrieves the localized word count type. |
|
416 * |
|
417 * @since 6.2.0 |
|
418 * |
|
419 * @return string Localized word count type. Possible values are `characters_excluding_spaces`, |
|
420 * `characters_including_spaces`, or `words`. Defaults to `words`. |
|
421 */ |
|
422 public function get_word_count_type() { |
|
423 |
|
424 /* |
|
425 * translators: If your word count is based on single characters (e.g. East Asian characters), |
|
426 * enter 'characters_excluding_spaces' or 'characters_including_spaces'. Otherwise, enter 'words'. |
|
427 * Do not translate into your own language. |
|
428 */ |
|
429 $word_count_type = is_null( $this->word_count_type ) ? _x( 'words', 'Word count type. Do not translate!' ) : $this->word_count_type; |
|
430 |
|
431 // Check for valid types. |
|
432 if ( 'characters_excluding_spaces' !== $word_count_type && 'characters_including_spaces' !== $word_count_type ) { |
|
433 // Defaults to 'words'. |
|
434 $word_count_type = 'words'; |
|
435 } |
|
436 |
|
437 return $word_count_type; |
|
438 } |
391 } |
439 } |