web/wp-includes/locale.php
changeset 194 32102edaa81b
parent 136 bde1974c263b
equal deleted inserted replaced
193:2f6f6f7551ca 194:32102edaa81b
    23 
    23 
    24 	/**
    24 	/**
    25 	 * Stores the translated strings for the one character weekday names.
    25 	 * Stores the translated strings for the one character weekday names.
    26 	 *
    26 	 *
    27 	 * There is a hack to make sure that Tuesday and Thursday, as well
    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.
    28 	 * as Sunday and Saturday, don't conflict. See init() method for more.
    29 	 *
    29 	 *
    30 	 * @see WP_Locale::init() for how to handle the hack.
    30 	 * @see WP_Locale::init() for how to handle the hack.
    31 	 *
    31 	 *
    32 	 * @since 2.1.0
    32 	 * @since 2.1.0
    33 	 * @var array
    33 	 * @var array
    63 	var $month_abbrev;
    63 	var $month_abbrev;
    64 
    64 
    65 	/**
    65 	/**
    66 	 * Stores the translated strings for 'am' and 'pm'.
    66 	 * Stores the translated strings for 'am' and 'pm'.
    67 	 *
    67 	 *
    68 	 * Also the capalized versions.
    68 	 * Also the capitalized versions.
    69 	 *
    69 	 *
    70 	 * @since 2.1.0
    70 	 * @since 2.1.0
    71 	 * @var array
    71 	 * @var array
    72 	 * @access private
    72 	 * @access private
    73 	 */
    73 	 */
    81 	 * @since 2.1.0
    81 	 * @since 2.1.0
    82 	 * @var string
    82 	 * @var string
    83 	 * @access private
    83 	 * @access private
    84 	 */
    84 	 */
    85 	var $text_direction = 'ltr';
    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 
    86 
    96 	/**
    87 	/**
    97 	 * Sets up the translated strings and object properties.
    88 	 * Sets up the translated strings and object properties.
    98 	 *
    89 	 *
    99 	 * The method creates the translatable strings for various
    90 	 * The method creates the translatable strings for various
   103 	 * @since 2.1.0
    94 	 * @since 2.1.0
   104 	 * @access private
    95 	 * @access private
   105 	 */
    96 	 */
   106 	function init() {
    97 	function init() {
   107 		// The Weekdays
    98 		// The Weekdays
   108 		$this->weekday[0] = __('Sunday');
    99 		$this->weekday[0] = /* translators: weekday */ __('Sunday');
   109 		$this->weekday[1] = __('Monday');
   100 		$this->weekday[1] = /* translators: weekday */ __('Monday');
   110 		$this->weekday[2] = __('Tuesday');
   101 		$this->weekday[2] = /* translators: weekday */ __('Tuesday');
   111 		$this->weekday[3] = __('Wednesday');
   102 		$this->weekday[3] = /* translators: weekday */ __('Wednesday');
   112 		$this->weekday[4] = __('Thursday');
   103 		$this->weekday[4] = /* translators: weekday */ __('Thursday');
   113 		$this->weekday[5] = __('Friday');
   104 		$this->weekday[5] = /* translators: weekday */ __('Friday');
   114 		$this->weekday[6] = __('Saturday');
   105 		$this->weekday[6] = /* translators: weekday */ __('Saturday');
   115 
   106 
   116 		// The first letter of each day.  The _%day%_initial suffix is a hack to make
   107 		// The first letter of each day. The _%day%_initial suffix is a hack to make
   117 		// sure the day initials are unique.
   108 		// sure the day initials are unique.
   118 		$this->weekday_initial[__('Sunday')]    = __('S_Sunday_initial');
   109 		$this->weekday_initial[__('Sunday')]    = /* translators: one-letter abbreviation of the weekday */ __('S_Sunday_initial');
   119 		$this->weekday_initial[__('Monday')]    = __('M_Monday_initial');
   110 		$this->weekday_initial[__('Monday')]    = /* translators: one-letter abbreviation of the weekday */ __('M_Monday_initial');
   120 		$this->weekday_initial[__('Tuesday')]   = __('T_Tuesday_initial');
   111 		$this->weekday_initial[__('Tuesday')]   = /* translators: one-letter abbreviation of the weekday */ __('T_Tuesday_initial');
   121 		$this->weekday_initial[__('Wednesday')] = __('W_Wednesday_initial');
   112 		$this->weekday_initial[__('Wednesday')] = /* translators: one-letter abbreviation of the weekday */ __('W_Wednesday_initial');
   122 		$this->weekday_initial[__('Thursday')]  = __('T_Thursday_initial');
   113 		$this->weekday_initial[__('Thursday')]  = /* translators: one-letter abbreviation of the weekday */ __('T_Thursday_initial');
   123 		$this->weekday_initial[__('Friday')]    = __('F_Friday_initial');
   114 		$this->weekday_initial[__('Friday')]    = /* translators: one-letter abbreviation of the weekday */ __('F_Friday_initial');
   124 		$this->weekday_initial[__('Saturday')]  = __('S_Saturday_initial');
   115 		$this->weekday_initial[__('Saturday')]  = /* translators: one-letter abbreviation of the weekday */ __('S_Saturday_initial');
   125 
   116 
   126 		foreach ($this->weekday_initial as $weekday_ => $weekday_initial_) {
   117 		foreach ($this->weekday_initial as $weekday_ => $weekday_initial_) {
   127 			$this->weekday_initial[$weekday_] = preg_replace('/_.+_initial$/', '', $weekday_initial_);
   118 			$this->weekday_initial[$weekday_] = preg_replace('/_.+_initial$/', '', $weekday_initial_);
   128 		}
   119 		}
   129 
   120 
   130 		// Abbreviations for each day.
   121 		// Abbreviations for each day.
   131 		$this->weekday_abbrev[__('Sunday')]    = __('Sun');
   122 		$this->weekday_abbrev[__('Sunday')]    = /* translators: three-letter abbreviation of the weekday */ __('Sun');
   132 		$this->weekday_abbrev[__('Monday')]    = __('Mon');
   123 		$this->weekday_abbrev[__('Monday')]    = /* translators: three-letter abbreviation of the weekday */ __('Mon');
   133 		$this->weekday_abbrev[__('Tuesday')]   = __('Tue');
   124 		$this->weekday_abbrev[__('Tuesday')]   = /* translators: three-letter abbreviation of the weekday */ __('Tue');
   134 		$this->weekday_abbrev[__('Wednesday')] = __('Wed');
   125 		$this->weekday_abbrev[__('Wednesday')] = /* translators: three-letter abbreviation of the weekday */ __('Wed');
   135 		$this->weekday_abbrev[__('Thursday')]  = __('Thu');
   126 		$this->weekday_abbrev[__('Thursday')]  = /* translators: three-letter abbreviation of the weekday */ __('Thu');
   136 		$this->weekday_abbrev[__('Friday')]    = __('Fri');
   127 		$this->weekday_abbrev[__('Friday')]    = /* translators: three-letter abbreviation of the weekday */ __('Fri');
   137 		$this->weekday_abbrev[__('Saturday')]  = __('Sat');
   128 		$this->weekday_abbrev[__('Saturday')]  = /* translators: three-letter abbreviation of the weekday */ __('Sat');
   138 
   129 
   139 		// The Months
   130 		// The Months
   140 		$this->month['01'] = __('January');
   131 		$this->month['01'] = /* translators: month name */ __('January');
   141 		$this->month['02'] = __('February');
   132 		$this->month['02'] = /* translators: month name */ __('February');
   142 		$this->month['03'] = __('March');
   133 		$this->month['03'] = /* translators: month name */ __('March');
   143 		$this->month['04'] = __('April');
   134 		$this->month['04'] = /* translators: month name */ __('April');
   144 		$this->month['05'] = __('May');
   135 		$this->month['05'] = /* translators: month name */ __('May');
   145 		$this->month['06'] = __('June');
   136 		$this->month['06'] = /* translators: month name */ __('June');
   146 		$this->month['07'] = __('July');
   137 		$this->month['07'] = /* translators: month name */ __('July');
   147 		$this->month['08'] = __('August');
   138 		$this->month['08'] = /* translators: month name */ __('August');
   148 		$this->month['09'] = __('September');
   139 		$this->month['09'] = /* translators: month name */ __('September');
   149 		$this->month['10'] = __('October');
   140 		$this->month['10'] = /* translators: month name */ __('October');
   150 		$this->month['11'] = __('November');
   141 		$this->month['11'] = /* translators: month name */ __('November');
   151 		$this->month['12'] = __('December');
   142 		$this->month['12'] = /* translators: month name */ __('December');
   152 
   143 
   153 		// Abbreviations for each month. Uses the same hack as above to get around the
   144 		// Abbreviations for each month. Uses the same hack as above to get around the
   154 		// 'May' duplication.
   145 		// 'May' duplication.
   155 		$this->month_abbrev[__('January')] = __('Jan_January_abbreviation');
   146 		$this->month_abbrev[__('January')] = /* translators: three-letter abbreviation of the month */ __('Jan_January_abbreviation');
   156 		$this->month_abbrev[__('February')] = __('Feb_February_abbreviation');
   147 		$this->month_abbrev[__('February')] = /* translators: three-letter abbreviation of the month */ __('Feb_February_abbreviation');
   157 		$this->month_abbrev[__('March')] = __('Mar_March_abbreviation');
   148 		$this->month_abbrev[__('March')] = /* translators: three-letter abbreviation of the month */ __('Mar_March_abbreviation');
   158 		$this->month_abbrev[__('April')] = __('Apr_April_abbreviation');
   149 		$this->month_abbrev[__('April')] = /* translators: three-letter abbreviation of the month */ __('Apr_April_abbreviation');
   159 		$this->month_abbrev[__('May')] = __('May_May_abbreviation');
   150 		$this->month_abbrev[__('May')] = /* translators: three-letter abbreviation of the month */ __('May_May_abbreviation');
   160 		$this->month_abbrev[__('June')] = __('Jun_June_abbreviation');
   151 		$this->month_abbrev[__('June')] = /* translators: three-letter abbreviation of the month */ __('Jun_June_abbreviation');
   161 		$this->month_abbrev[__('July')] = __('Jul_July_abbreviation');
   152 		$this->month_abbrev[__('July')] = /* translators: three-letter abbreviation of the month */ __('Jul_July_abbreviation');
   162 		$this->month_abbrev[__('August')] = __('Aug_August_abbreviation');
   153 		$this->month_abbrev[__('August')] = /* translators: three-letter abbreviation of the month */ __('Aug_August_abbreviation');
   163 		$this->month_abbrev[__('September')] = __('Sep_September_abbreviation');
   154 		$this->month_abbrev[__('September')] = /* translators: three-letter abbreviation of the month */ __('Sep_September_abbreviation');
   164 		$this->month_abbrev[__('October')] = __('Oct_October_abbreviation');
   155 		$this->month_abbrev[__('October')] = /* translators: three-letter abbreviation of the month */ __('Oct_October_abbreviation');
   165 		$this->month_abbrev[__('November')] = __('Nov_November_abbreviation');
   156 		$this->month_abbrev[__('November')] = /* translators: three-letter abbreviation of the month */ __('Nov_November_abbreviation');
   166 		$this->month_abbrev[__('December')] = __('Dec_December_abbreviation');
   157 		$this->month_abbrev[__('December')] = /* translators: three-letter abbreviation of the month */ __('Dec_December_abbreviation');
   167 
   158 
   168 		foreach ($this->month_abbrev as $month_ => $month_abbrev_) {
   159 		foreach ($this->month_abbrev as $month_ => $month_abbrev_) {
   169 			$this->month_abbrev[$month_] = preg_replace('/_.+_abbreviation$/', '', $month_abbrev_);
   160 			$this->month_abbrev[$month_] = preg_replace('/_.+_abbreviation$/', '', $month_abbrev_);
   170 		}
   161 		}
   171 
   162 
   176 		$this->meridiem['PM'] = __('PM');
   167 		$this->meridiem['PM'] = __('PM');
   177 
   168 
   178 		// Numbers formatting
   169 		// Numbers formatting
   179 		// See http://php.net/number_format
   170 		// See http://php.net/number_format
   180 
   171 
   181 		/* translators: $decimals argument for http://php.net/number_format, default is 0 */
   172 		/* translators: $thousands_sep argument for http://php.net/number_format, default is , */
   182 		$trans = __('number_format_decimals');
   173 		$trans = __('number_format_thousands_sep');
   183 		$this->number_format['decimals'] = ('number_format_decimals' == $trans) ? 0 : $trans;
   174 		$this->number_format['thousands_sep'] = ('number_format_thousands_sep' == $trans) ? ',' : $trans;
   184 
   175 
   185 		/* translators: $dec_point argument for http://php.net/number_format, default is . */
   176 		/* translators: $dec_point argument for http://php.net/number_format, default is . */
   186 		$trans = __('number_format_decimal_point');
   177 		$trans = __('number_format_decimal_point');
   187 		$this->number_format['decimal_point'] = ('number_format_decimal_point' == $trans) ? '.' : $trans;
   178 		$this->number_format['decimal_point'] = ('number_format_decimal_point' == $trans) ? '.' : $trans;
   188 
   179 
   189 		/* translators: $thousands_sep argument for http://php.net/number_format, default is , */
   180 		// Set text direction.
   190 		$trans = __('number_format_thousands_sep');
   181 		if ( isset( $GLOBALS['text_direction'] ) )
   191 		$this->number_format['thousands_sep'] = ('number_format_thousands_sep' == $trans) ? ',' : $trans;
   182 			$this->text_direction = $GLOBALS['text_direction'];
   192 
   183 		/* translators: 'rtl' or 'ltr'. This sets the text direction for WordPress. */
   193 		// Import global locale vars set during inclusion of $locale.php.
   184 		elseif ( 'rtl' == _x( 'ltr', 'text direction' ) )
   194 		foreach ( (array) $this->locale_vars as $var ) {
   185 			$this->text_direction = 'rtl';
   195 			if ( isset($GLOBALS[$var]) )
       
   196 				$this->$var = $GLOBALS[$var];
       
   197 		}
       
   198 
       
   199 	}
   186 	}
   200 
   187 
   201 	/**
   188 	/**
   202 	 * Retrieve the full translated weekday word.
   189 	 * Retrieve the full translated weekday word.
   203 	 *
   190 	 *
   316 		$GLOBALS['month']           = $this->month;
   303 		$GLOBALS['month']           = $this->month;
   317 		$GLOBALS['month_abbrev']    = $this->month_abbrev;
   304 		$GLOBALS['month_abbrev']    = $this->month_abbrev;
   318 	}
   305 	}
   319 
   306 
   320 	/**
   307 	/**
   321 	 * PHP4 style constructor which calls helper methods to set up object variables
   308 	 * Constructor which calls helper methods to set up object variables
   322 	 *
   309 	 *
   323 	 * @uses WP_Locale::init()
   310 	 * @uses WP_Locale::init()
   324 	 * @uses WP_Locale::register_globals()
   311 	 * @uses WP_Locale::register_globals()
   325 	 * @since 2.1.0
   312 	 * @since 2.1.0
   326 	 *
   313 	 *
   327 	 * @return WP_Locale
   314 	 * @return WP_Locale
   328 	 */
   315 	 */
   329 	function WP_Locale() {
   316 	function __construct() {
   330 		$this->init();
   317 		$this->init();
   331 		$this->register_globals();
   318 		$this->register_globals();
   332 	}
   319 	}
       
   320 
       
   321 	/**
       
   322 	 * Checks if current locale is RTL.
       
   323 	 *
       
   324 	 * @since 3.0.0
       
   325 	 * @return bool Whether locale is RTL.
       
   326 	 */
       
   327 	function is_rtl() {
       
   328 		return 'rtl' == $this->text_direction;
       
   329 	}
   333 }
   330 }
   334 
   331 
   335 ?>
   332 /**
       
   333  * Checks if current locale is RTL.
       
   334  *
       
   335  * @since 3.0.0
       
   336  * @return bool Whether locale is RTL.
       
   337  */
       
   338 function is_rtl() {
       
   339 	global $wp_locale;
       
   340 	return $wp_locale->is_rtl();
       
   341 }