WP_Locale

Core class used to store translated data for a locale.

Defined (1)

The class is defined in the following location(s).

/wp-includes/class-wp-locale.php  
  1. class WP_Locale { 
  2. /** 
  3. * Stores the translated strings for the full weekday names. 
  4. * @since 2.1.0 
  5. * @var array 
  6. */ 
  7. public $weekday; 
  8.  
  9. /** 
  10. * Stores the translated strings for the one character weekday names. 
  11. * There is a hack to make sure that Tuesday and Thursday, as well 
  12. * as Sunday and Saturday, don't conflict. See init() method for more. 
  13. * @see WP_Locale::init() for how to handle the hack. 
  14. * @since 2.1.0 
  15. * @var array 
  16. */ 
  17. public $weekday_initial; 
  18.  
  19. /** 
  20. * Stores the translated strings for the abbreviated weekday names. 
  21. * @since 2.1.0 
  22. * @var array 
  23. */ 
  24. public $weekday_abbrev; 
  25.  
  26. /** 
  27. * Stores the default start of the week. 
  28. * @since 4.4.0 
  29. * @var string 
  30. */ 
  31. public $start_of_week; 
  32.  
  33. /** 
  34. * Stores the translated strings for the full month names. 
  35. * @since 2.1.0 
  36. * @var array 
  37. */ 
  38. public $month; 
  39.  
  40. /** 
  41. * Stores the translated strings for the month names in genitive case, if the locale specifies. 
  42. * @since 4.4.0 
  43. * @var array 
  44. */ 
  45. public $month_genitive; 
  46.  
  47. /** 
  48. * Stores the translated strings for the abbreviated month names. 
  49. * @since 2.1.0 
  50. * @var array 
  51. */ 
  52. public $month_abbrev; 
  53.  
  54. /** 
  55. * Stores the translated strings for 'am' and 'pm'. 
  56. * Also the capitalized versions. 
  57. * @since 2.1.0 
  58. * @var array 
  59. */ 
  60. public $meridiem; 
  61.  
  62. /** 
  63. * The text direction of the locale language. 
  64. * Default is left to right 'ltr'. 
  65. * @since 2.1.0 
  66. * @var string 
  67. */ 
  68. public $text_direction = 'ltr'; 
  69.  
  70. /** 
  71. * The thousands separator and decimal point values used for localizing numbers. 
  72. * @since 2.3.0 
  73. * @access public 
  74. * @var array 
  75. */ 
  76. public $number_format; 
  77.  
  78. /** 
  79. * Constructor which calls helper methods to set up object variables. 
  80. * @since 2.1.0 
  81. */ 
  82. public function __construct() { 
  83. $this->init(); 
  84. $this->register_globals(); 
  85.  
  86. /** 
  87. * Sets up the translated strings and object properties. 
  88. * The method creates the translatable strings for various 
  89. * calendar elements. Which allows for specifying locale 
  90. * specific calendar names and text direction. 
  91. * @since 2.1.0 
  92. * @access private 
  93. * @global string $text_direction 
  94. */ 
  95. public function init() { 
  96. // The Weekdays 
  97. $this->weekday[0] = /** translators: weekday */ __('Sunday'); 
  98. $this->weekday[1] = /** translators: weekday */ __('Monday'); 
  99. $this->weekday[2] = /** translators: weekday */ __('Tuesday'); 
  100. $this->weekday[3] = /** translators: weekday */ __('Wednesday'); 
  101. $this->weekday[4] = /** translators: weekday */ __('Thursday'); 
  102. $this->weekday[5] = /** translators: weekday */ __('Friday'); 
  103. $this->weekday[6] = /** translators: weekday */ __('Saturday'); 
  104.  
  105. // The first letter of each day. 
  106. $this->weekday_initial[ __( 'Sunday' ) ] = /** translators: one-letter abbreviation of the weekday */ _x( 'S', 'Sunday initial' ); 
  107. $this->weekday_initial[ __( 'Monday' ) ] = /** translators: one-letter abbreviation of the weekday */ _x( 'M', 'Monday initial' ); 
  108. $this->weekday_initial[ __( 'Tuesday' ) ] = /** translators: one-letter abbreviation of the weekday */ _x( 'T', 'Tuesday initial' ); 
  109. $this->weekday_initial[ __( 'Wednesday' ) ] = /** translators: one-letter abbreviation of the weekday */ _x( 'W', 'Wednesday initial' ); 
  110. $this->weekday_initial[ __( 'Thursday' ) ] = /** translators: one-letter abbreviation of the weekday */ _x( 'T', 'Thursday initial' ); 
  111. $this->weekday_initial[ __( 'Friday' ) ] = /** translators: one-letter abbreviation of the weekday */ _x( 'F', 'Friday initial' ); 
  112. $this->weekday_initial[ __( 'Saturday' ) ] = /** translators: one-letter abbreviation of the weekday */ _x( 'S', 'Saturday initial' ); 
  113.  
  114. // Abbreviations for each day. 
  115. $this->weekday_abbrev[__('Sunday')] = /** translators: three-letter abbreviation of the weekday */ __('Sun'); 
  116. $this->weekday_abbrev[__('Monday')] = /** translators: three-letter abbreviation of the weekday */ __('Mon'); 
  117. $this->weekday_abbrev[__('Tuesday')] = /** translators: three-letter abbreviation of the weekday */ __('Tue'); 
  118. $this->weekday_abbrev[__('Wednesday')] = /** translators: three-letter abbreviation of the weekday */ __('Wed'); 
  119. $this->weekday_abbrev[__('Thursday')] = /** translators: three-letter abbreviation of the weekday */ __('Thu'); 
  120. $this->weekday_abbrev[__('Friday')] = /** translators: three-letter abbreviation of the weekday */ __('Fri'); 
  121. $this->weekday_abbrev[__('Saturday')] = /** translators: three-letter abbreviation of the weekday */ __('Sat'); 
  122.  
  123. // The Months 
  124. $this->month['01'] = /** translators: month name */ __( 'January' ); 
  125. $this->month['02'] = /** translators: month name */ __( 'February' ); 
  126. $this->month['03'] = /** translators: month name */ __( 'March' ); 
  127. $this->month['04'] = /** translators: month name */ __( 'April' ); 
  128. $this->month['05'] = /** translators: month name */ __( 'May' ); 
  129. $this->month['06'] = /** translators: month name */ __( 'June' ); 
  130. $this->month['07'] = /** translators: month name */ __( 'July' ); 
  131. $this->month['08'] = /** translators: month name */ __( 'August' ); 
  132. $this->month['09'] = /** translators: month name */ __( 'September' ); 
  133. $this->month['10'] = /** translators: month name */ __( 'October' ); 
  134. $this->month['11'] = /** translators: month name */ __( 'November' ); 
  135. $this->month['12'] = /** translators: month name */ __( 'December' ); 
  136.  
  137. // The Months, genitive 
  138. $this->month_genitive['01'] = /** translators: month name, genitive */ _x( 'January', 'genitive' ); 
  139. $this->month_genitive['02'] = /** translators: month name, genitive */ _x( 'February', 'genitive' ); 
  140. $this->month_genitive['03'] = /** translators: month name, genitive */ _x( 'March', 'genitive' ); 
  141. $this->month_genitive['04'] = /** translators: month name, genitive */ _x( 'April', 'genitive' ); 
  142. $this->month_genitive['05'] = /** translators: month name, genitive */ _x( 'May', 'genitive' ); 
  143. $this->month_genitive['06'] = /** translators: month name, genitive */ _x( 'June', 'genitive' ); 
  144. $this->month_genitive['07'] = /** translators: month name, genitive */ _x( 'July', 'genitive' ); 
  145. $this->month_genitive['08'] = /** translators: month name, genitive */ _x( 'August', 'genitive' ); 
  146. $this->month_genitive['09'] = /** translators: month name, genitive */ _x( 'September', 'genitive' ); 
  147. $this->month_genitive['10'] = /** translators: month name, genitive */ _x( 'October', 'genitive' ); 
  148. $this->month_genitive['11'] = /** translators: month name, genitive */ _x( 'November', 'genitive' ); 
  149. $this->month_genitive['12'] = /** translators: month name, genitive */ _x( 'December', 'genitive' ); 
  150.  
  151. // Abbreviations for each month. 
  152. $this->month_abbrev[ __( 'January' ) ] = /** translators: three-letter abbreviation of the month */ _x( 'Jan', 'January abbreviation' ); 
  153. $this->month_abbrev[ __( 'February' ) ] = /** translators: three-letter abbreviation of the month */ _x( 'Feb', 'February abbreviation' ); 
  154. $this->month_abbrev[ __( 'March' ) ] = /** translators: three-letter abbreviation of the month */ _x( 'Mar', 'March abbreviation' ); 
  155. $this->month_abbrev[ __( 'April' ) ] = /** translators: three-letter abbreviation of the month */ _x( 'Apr', 'April abbreviation' ); 
  156. $this->month_abbrev[ __( 'May' ) ] = /** translators: three-letter abbreviation of the month */ _x( 'May', 'May abbreviation' ); 
  157. $this->month_abbrev[ __( 'June' ) ] = /** translators: three-letter abbreviation of the month */ _x( 'Jun', 'June abbreviation' ); 
  158. $this->month_abbrev[ __( 'July' ) ] = /** translators: three-letter abbreviation of the month */ _x( 'Jul', 'July abbreviation' ); 
  159. $this->month_abbrev[ __( 'August' ) ] = /** translators: three-letter abbreviation of the month */ _x( 'Aug', 'August abbreviation' ); 
  160. $this->month_abbrev[ __( 'September' ) ] = /** translators: three-letter abbreviation of the month */ _x( 'Sep', 'September abbreviation' ); 
  161. $this->month_abbrev[ __( 'October' ) ] = /** translators: three-letter abbreviation of the month */ _x( 'Oct', 'October abbreviation' ); 
  162. $this->month_abbrev[ __( 'November' ) ] = /** translators: three-letter abbreviation of the month */ _x( 'Nov', 'November abbreviation' ); 
  163. $this->month_abbrev[ __( 'December' ) ] = /** translators: three-letter abbreviation of the month */ _x( 'Dec', 'December abbreviation' ); 
  164.  
  165. // The Meridiems 
  166. $this->meridiem['am'] = __('am'); 
  167. $this->meridiem['pm'] = __('pm'); 
  168. $this->meridiem['AM'] = __('AM'); 
  169. $this->meridiem['PM'] = __('PM'); 
  170.  
  171. // Numbers formatting 
  172. // See https://secure.php.net/number_format 
  173.  
  174. /** translators: $thousands_sep argument for https://secure.php.net/number_format, default is , */ 
  175. $thousands_sep = __( 'number_format_thousands_sep' ); 
  176.  
  177. if ( version_compare( PHP_VERSION, '5.4', '>=' ) ) { 
  178. // Replace space with a non-breaking space to avoid wrapping. 
  179. $thousands_sep = str_replace( ' ', ' ', $thousands_sep ); 
  180. } else { 
  181. // PHP < 5.4.0 does not support multiple bytes in thousands separator. 
  182. $thousands_sep = str_replace( array( ' ', ' ' ), ' ', $thousands_sep ); 
  183.  
  184. $this->number_format['thousands_sep'] = ( 'number_format_thousands_sep' === $thousands_sep ) ? ', ' : $thousands_sep; 
  185.  
  186. /** translators: $dec_point argument for https://secure.php.net/number_format, default is . */ 
  187. $decimal_point = __( 'number_format_decimal_point' ); 
  188.  
  189. $this->number_format['decimal_point'] = ( 'number_format_decimal_point' === $decimal_point ) ? '.' : $decimal_point; 
  190.  
  191. // Set text direction. 
  192. if ( isset( $GLOBALS['text_direction'] ) ) 
  193. $this->text_direction = $GLOBALS['text_direction']; 
  194. /** translators: 'rtl' or 'ltr'. This sets the text direction for WordPress. */ 
  195. elseif ( 'rtl' == _x( 'ltr', 'text direction' ) ) 
  196. $this->text_direction = 'rtl'; 
  197.  
  198. if ( 'rtl' === $this->text_direction && strpos( get_bloginfo( 'version' ), '-src' ) ) { 
  199. $this->text_direction = 'ltr'; 
  200. add_action( 'all_admin_notices', array( $this, 'rtl_src_admin_notice' ) ); 
  201.  
  202. /** 
  203. * Outputs an admin notice if the /build directory must be used for RTL. 
  204. * @since 3.8.0 
  205. * @access public 
  206. */ 
  207. public function rtl_src_admin_notice() { 
  208. /** translators: %s: Name of the directory (build) */ 
  209. echo '<div class="error"><p>' . sprintf( __( 'The %s directory of the develop repository must be used for RTL.' ), '<code>build</code>' ) . '</p></div>'; 
  210.  
  211. /** 
  212. * Retrieve the full translated weekday word. 
  213. * Week starts on translated Sunday and can be fetched 
  214. * by using 0 (zero). So the week starts with 0 (zero) 
  215. * and ends on Saturday with is fetched by using 6 (six). 
  216. * @since 2.1.0 
  217. * @access public 
  218. * @param int $weekday_number 0 for Sunday through 6 Saturday 
  219. * @return string Full translated weekday 
  220. */ 
  221. public function get_weekday($weekday_number) { 
  222. return $this->weekday[$weekday_number]; 
  223.  
  224. /** 
  225. * Retrieve the translated weekday initial. 
  226. * The weekday initial is retrieved by the translated 
  227. * full weekday word. When translating the weekday initial 
  228. * pay attention to make sure that the starting letter does 
  229. * not conflict. 
  230. * @since 2.1.0 
  231. * @access public 
  232. * @param string $weekday_name 
  233. * @return string 
  234. */ 
  235. public function get_weekday_initial($weekday_name) { 
  236. return $this->weekday_initial[$weekday_name]; 
  237.  
  238. /** 
  239. * Retrieve the translated weekday abbreviation. 
  240. * The weekday abbreviation is retrieved by the translated 
  241. * full weekday word. 
  242. * @since 2.1.0 
  243. * @access public 
  244. * @param string $weekday_name Full translated weekday word 
  245. * @return string Translated weekday abbreviation 
  246. */ 
  247. public function get_weekday_abbrev($weekday_name) { 
  248. return $this->weekday_abbrev[$weekday_name]; 
  249.  
  250. /** 
  251. * Retrieve the full translated month by month number. 
  252. * The $month_number parameter has to be a string 
  253. * because it must have the '0' in front of any number 
  254. * that is less than 10. Starts from '01' and ends at 
  255. * '12'. 
  256. * You can use an integer instead and it will add the 
  257. * '0' before the numbers less than 10 for you. 
  258. * @since 2.1.0 
  259. * @access public 
  260. * @param string|int $month_number '01' through '12' 
  261. * @return string Translated full month name 
  262. */ 
  263. public function get_month($month_number) { 
  264. return $this->month[zeroise($month_number, 2)]; 
  265.  
  266. /** 
  267. * Retrieve translated version of month abbreviation string. 
  268. * The $month_name parameter is expected to be the translated or 
  269. * translatable version of the month. 
  270. * @since 2.1.0 
  271. * @access public 
  272. * @param string $month_name Translated month to get abbreviated version 
  273. * @return string Translated abbreviated month 
  274. */ 
  275. public function get_month_abbrev($month_name) { 
  276. return $this->month_abbrev[$month_name]; 
  277.  
  278. /** 
  279. * Retrieve translated version of meridiem string. 
  280. * The $meridiem parameter is expected to not be translated. 
  281. * @since 2.1.0 
  282. * @access public 
  283. * @param string $meridiem Either 'am', 'pm', 'AM', or 'PM'. Not translated version. 
  284. * @return string Translated version 
  285. */ 
  286. public function get_meridiem($meridiem) { 
  287. return $this->meridiem[$meridiem]; 
  288.  
  289. /** 
  290. * Global variables are deprecated. 
  291. * For backward compatibility only. 
  292. * @deprecated For backward compatibility only. 
  293. * @access private 
  294. * @global array $weekday 
  295. * @global array $weekday_initial 
  296. * @global array $weekday_abbrev 
  297. * @global array $month 
  298. * @global array $month_abbrev 
  299. * @since 2.1.0 
  300. */ 
  301. public function register_globals() { 
  302. $GLOBALS['weekday'] = $this->weekday; 
  303. $GLOBALS['weekday_initial'] = $this->weekday_initial; 
  304. $GLOBALS['weekday_abbrev'] = $this->weekday_abbrev; 
  305. $GLOBALS['month'] = $this->month; 
  306. $GLOBALS['month_abbrev'] = $this->month_abbrev; 
  307.  
  308. /** 
  309. * Checks if current locale is RTL. 
  310. * @since 3.0.0 
  311. * @return bool Whether locale is RTL. 
  312. */ 
  313. public function is_rtl() { 
  314. return 'rtl' == $this->text_direction; 
  315.  
  316. /** 
  317. * Register date/time format strings for general POT. 
  318. * Private, unused method to add some date/time formats translated 
  319. * on wp-admin/options-general.php to the general POT that would 
  320. * otherwise be added to the admin POT. 
  321. * @since 3.6.0 
  322. */ 
  323. public function _strings_for_pot() { 
  324. /** translators: localized date format, see https://secure.php.net/date */ 
  325. __( 'F j, Y' ); 
  326. /** translators: localized time format, see https://secure.php.net/date */ 
  327. __( 'g:i a' ); 
  328. /** translators: localized date and time format, see https://secure.php.net/date */ 
  329. __( 'F j, Y g:i a' );