BB_Locale

Class that loads the calendar locale.

Defined (1)

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

/bp-forums/bbpress/bb-includes/class.bb-locale.php  
  1. class BB_Locale { 
  2. /** 
  3. * Stores the translated strings for the full weekday names. 
  4. * @var array 
  5. * @access private 
  6. */ 
  7. var $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 BB_Locale::init() for how to handle the hack. 
  14. * @var array 
  15. * @access private 
  16. */ 
  17. var $weekday_initial; 
  18.  
  19. /** 
  20. * Stores the translated strings for the abbreviated weekday names. 
  21. * @var array 
  22. * @access private 
  23. */ 
  24. var $weekday_abbrev; 
  25.  
  26. /** 
  27. * Stores the translated strings for the full month names. 
  28. * @var array 
  29. * @access private 
  30. */ 
  31. var $month; 
  32.  
  33. /** 
  34. * Stores the translated strings for the abbreviated month names. 
  35. * @var array 
  36. * @access private 
  37. */ 
  38. var $month_abbrev; 
  39.  
  40. /** 
  41. * Stores the translated strings for 'am' and 'pm'. 
  42. * Also the capitalized versions. 
  43. * @var array 
  44. * @access private 
  45. */ 
  46. var $meridiem; 
  47.  
  48. /** 
  49. * Stores number formatting rules. 
  50. * @var array 
  51. * @access public 
  52. */ 
  53. var $number_format; 
  54.  
  55. /** 
  56. * Stores date and time formatting strings. 
  57. * @var array 
  58. * @access public 
  59. */ 
  60. var $datetime_formatstring; 
  61.  
  62. /** 
  63. * The text direction of the locale language. 
  64. * Default is left to right 'ltr'. 
  65. * @var string 
  66. * @access private 
  67. */ 
  68. var $text_direction = ''; 
  69.  
  70. /** 
  71. * Imports the global version to the class property. 
  72. * @var array 
  73. * @access private 
  74. */ 
  75. var $locale_vars = array('text_direction'); 
  76.  
  77. /** 
  78. * Sets up the translated strings and object properties. 
  79. * The method creates the translatable strings for various 
  80. * calendar elements. Which allows for specifying locale 
  81. * specific calendar names and text direction. 
  82. * @access private 
  83. */ 
  84. function init() { 
  85. // The Weekdays 
  86. $this->weekday[0] = __('Sunday'); 
  87. $this->weekday[1] = __('Monday'); 
  88. $this->weekday[2] = __('Tuesday'); 
  89. $this->weekday[3] = __('Wednesday'); 
  90. $this->weekday[4] = __('Thursday'); 
  91. $this->weekday[5] = __('Friday'); 
  92. $this->weekday[6] = __('Saturday'); 
  93.  
  94. // The first letter of each day. The _%day%_initial suffix is a hack to make 
  95. // sure the day initials are unique. 
  96. $this->weekday_initial[__('Sunday')] = __('S_Sunday_initial'); 
  97. $this->weekday_initial[__('Monday')] = __('M_Monday_initial'); 
  98. $this->weekday_initial[__('Tuesday')] = __('T_Tuesday_initial'); 
  99. $this->weekday_initial[__('Wednesday')] = __('W_Wednesday_initial'); 
  100. $this->weekday_initial[__('Thursday')] = __('T_Thursday_initial'); 
  101. $this->weekday_initial[__('Friday')] = __('F_Friday_initial'); 
  102. $this->weekday_initial[__('Saturday')] = __('S_Saturday_initial'); 
  103.  
  104. foreach ($this->weekday_initial as $weekday_ => $weekday_initial_) { 
  105. $this->weekday_initial[$weekday_] = preg_replace('/_.+_initial$/', '', $weekday_initial_); 
  106.  
  107. // Abbreviations for each day. 
  108. $this->weekday_abbrev[__('Sunday')] = __('Sun'); 
  109. $this->weekday_abbrev[__('Monday')] = __('Mon'); 
  110. $this->weekday_abbrev[__('Tuesday')] = __('Tue'); 
  111. $this->weekday_abbrev[__('Wednesday')] = __('Wed'); 
  112. $this->weekday_abbrev[__('Thursday')] = __('Thu'); 
  113. $this->weekday_abbrev[__('Friday')] = __('Fri'); 
  114. $this->weekday_abbrev[__('Saturday')] = __('Sat'); 
  115.  
  116. // The Months 
  117. $this->month['01'] = __('January'); 
  118. $this->month['02'] = __('February'); 
  119. $this->month['03'] = __('March'); 
  120. $this->month['04'] = __('April'); 
  121. $this->month['05'] = __('May'); 
  122. $this->month['06'] = __('June'); 
  123. $this->month['07'] = __('July'); 
  124. $this->month['08'] = __('August'); 
  125. $this->month['09'] = __('September'); 
  126. $this->month['10'] = __('October'); 
  127. $this->month['11'] = __('November'); 
  128. $this->month['12'] = __('December'); 
  129.  
  130. // Abbreviations for each month. Uses the same hack as above to get around the 
  131. // 'May' duplication. 
  132. $this->month_abbrev[__('January')] = __('Jan_January_abbreviation'); 
  133. $this->month_abbrev[__('February')] = __('Feb_February_abbreviation'); 
  134. $this->month_abbrev[__('March')] = __('Mar_March_abbreviation'); 
  135. $this->month_abbrev[__('April')] = __('Apr_April_abbreviation'); 
  136. $this->month_abbrev[__('May')] = __('May_May_abbreviation'); 
  137. $this->month_abbrev[__('June')] = __('Jun_June_abbreviation'); 
  138. $this->month_abbrev[__('July')] = __('Jul_July_abbreviation'); 
  139. $this->month_abbrev[__('August')] = __('Aug_August_abbreviation'); 
  140. $this->month_abbrev[__('September')] = __('Sep_September_abbreviation'); 
  141. $this->month_abbrev[__('October')] = __('Oct_October_abbreviation'); 
  142. $this->month_abbrev[__('November')] = __('Nov_November_abbreviation'); 
  143. $this->month_abbrev[__('December')] = __('Dec_December_abbreviation'); 
  144.  
  145. foreach ($this->month_abbrev as $month_ => $month_abbrev_) { 
  146. $this->month_abbrev[$month_] = preg_replace('/_.+_abbreviation$/', '', $month_abbrev_); 
  147.  
  148. // The Meridiems 
  149. $this->meridiem['am'] = __('am'); 
  150. $this->meridiem['pm'] = __('pm'); 
  151. $this->meridiem['AM'] = __('AM'); 
  152. $this->meridiem['PM'] = __('PM'); 
  153.  
  154. // Numbers formatting 
  155. // See http://php.net/number_format 
  156.  
  157. /** translators: $decimals argument for http://php.net/number_format, default is 0 */ 
  158. $trans = __('number_format_decimals'); 
  159. $this->number_format['decimals'] = ('number_format_decimals' == $trans) ? 0 : $trans; 
  160.  
  161. /** translators: $dec_point argument for http://php.net/number_format, default is . */ 
  162. $trans = __('number_format_decimal_point'); 
  163. $this->number_format['decimal_point'] = ('number_format_decimal_point' == $trans) ? '.' : $trans; 
  164.  
  165. /** translators: $thousands_sep argument for http://php.net/number_format, default is , */ 
  166. $trans = __('number_format_thousands_sep'); 
  167. $this->number_format['thousands_sep'] = ('number_format_thousands_sep' == $trans) ? ', ' : $trans; 
  168.  
  169. // Date/Time formatting 
  170. $this->datetime_formatstring['datetime'] = __('F j, Y - h:i A'); 
  171. $this->datetime_formatstring['date'] = __('F j, Y'); 
  172. $this->datetime_formatstring['time'] = __('h:i A'); 
  173.  
  174. $this->_load_locale_data(); 
  175.  
  176. /** 
  177. * Imports global locale vars set during inclusion of $locale.php. 
  178. * @access private 
  179. */ 
  180. function _load_locale_data() { 
  181. $locale = bb_get_locale(); 
  182. $locale_file = BB_LANG_DIR . $locale . '.php'; 
  183. if ( !is_file( $locale_file ) ) { 
  184. return; 
  185.  
  186. include( $locale_file ); 
  187.  
  188. foreach ( $this->locale_vars as $var ) { 
  189. $this->$var = $$var; 
  190.  
  191. /** 
  192. * Retrieve the full translated weekday word. 
  193. * Week starts on translated Sunday and can be fetched 
  194. * by using 0 (zero). So the week starts with 0 (zero) 
  195. * and ends on Saturday with is fetched by using 6 (six). 
  196. * @access public 
  197. * @param int $weekday_number 0 for Sunday through 6 Saturday 
  198. * @return string Full translated weekday 
  199. */ 
  200. function get_weekday($weekday_number) { 
  201. return $this->weekday[$weekday_number]; 
  202.  
  203. /** 
  204. * Retrieve the translated weekday initial. 
  205. * The weekday initial is retrieved by the translated 
  206. * full weekday word. When translating the weekday initial 
  207. * pay attention to make sure that the starting letter does 
  208. * not conflict. 
  209. * @access public 
  210. * @param string $weekday_name 
  211. * @return string 
  212. */ 
  213. function get_weekday_initial($weekday_name) { 
  214. return $this->weekday_initial[$weekday_name]; 
  215.  
  216. /** 
  217. * Retrieve the translated weekday abbreviation. 
  218. * The weekday abbreviation is retrieved by the translated 
  219. * full weekday word. 
  220. * @access public 
  221. * @param string $weekday_name Full translated weekday word 
  222. * @return string Translated weekday abbreviation 
  223. */ 
  224. function get_weekday_abbrev($weekday_name) { 
  225. return $this->weekday_abbrev[$weekday_name]; 
  226.  
  227. /** 
  228. * Retrieve the full translated month by month number. 
  229. * The $month_number parameter has to be a string 
  230. * because it must have the '0' in front of any number 
  231. * that is less than 10. Starts from '01' and ends at 
  232. * '12'. 
  233. * You can use an integer instead and it will add the 
  234. * '0' before the numbers less than 10 for you. 
  235. * @access public 
  236. * @param string|int $month_number '01' through '12' 
  237. * @return string Translated full month name 
  238. */ 
  239. function get_month($month_number) { 
  240. return $this->month[zeroise($month_number, 2)]; 
  241.  
  242. function get_month_initial($month_name) { 
  243. return $this->month_initial[$month_name]; 
  244.  
  245. /** 
  246. * Retrieve translated version of month abbreviation string. 
  247. * The $month_name parameter is expected to be the translated or 
  248. * translatable version of the month. 
  249. * @access public 
  250. * @param string $month_name Translated month to get abbreviated version 
  251. * @return string Translated abbreviated month 
  252. */ 
  253. function get_month_abbrev($month_name) { 
  254. return $this->month_abbrev[$month_name]; 
  255.  
  256. /** 
  257. * Retrieve translated version of meridiem string. 
  258. * The $meridiem parameter is expected to not be translated. 
  259. * @access public 
  260. * @param string $meridiem Either 'am', 'pm', 'AM', or 'PM'. Not translated version. 
  261. * @return string Translated version 
  262. */ 
  263. function get_meridiem($meridiem) { 
  264. return $this->meridiem[$meridiem]; 
  265.  
  266. function get_datetime_formatstring($type = 'datetime') { 
  267. return $this->datetime_formatstring[$type]; 
  268.  
  269. /** 
  270. * Global variables are deprecated. For backwards compatibility only. 
  271. * @deprecated For backwards compatibility only. 
  272. * @access private 
  273. */ 
  274. function register_globals() { 
  275. $GLOBALS['weekday'] = $this->weekday; 
  276. $GLOBALS['weekday_initial'] = $this->weekday_initial; 
  277. $GLOBALS['weekday_abbrev'] = $this->weekday_abbrev; 
  278. $GLOBALS['month'] = $this->month; 
  279. $GLOBALS['month_abbrev'] = $this->month_abbrev; 
  280.  
  281. /** 
  282. * PHP4 style constructor which calls helper methods to set up object variables 
  283. * @uses BB_Locale::init() 
  284. * @uses BB_Locale::register_globals() 
  285. * @return BB_Locale 
  286. */ 
  287. function __construct() { 
  288. $this->init(); 
  289. $this->register_globals(); 
  290.  
  291. function BB_Locale() { 
  292. $this->__construct();