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