PageRenderTime 24ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-includes/class-wp-locale.php

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