WordPress.org

Make WordPress Core

Ticket #2568: wp_locale.diff

File wp_locale.diff, 16.9 KB (added by Sewar, 12 years ago)

patch for WP_Locale class

  • E:/PHP/WordPress/SVN/wp-includes/functions.php

     
    1616}
    1717
    1818function mysql2date($dateformatstring, $mysqlstring, $translate = true) {
    19         global $month, $weekday, $month_abbrev, $weekday_abbrev;
     19        global $wp_locale;
    2020        $m = $mysqlstring;
    2121        if ( empty($m) ) {
    2222                return false;
     
    2929        if ( -1 == $i || false == $i )
    3030                $i = 0;
    3131
    32         if ( !empty($month) && !empty($weekday) && $translate ) {
    33                 $datemonth = $month[date('m', $i)];
    34                 $datemonth_abbrev = $month_abbrev[$datemonth];
    35                 $dateweekday = $weekday[date('w', $i)];
    36                 $dateweekday_abbrev = $weekday_abbrev[$dateweekday];
     32        if ( !empty($wp_locale->month) && !empty($wp_locale->weekday) && $translate ) {
     33                $datemonth = $wp_locale->month[date('m', $i)];
     34                $datemonth_abbrev = $wp_locale->month_abbrev[$datemonth];
     35                $dateweekday = $wp_locale->weekday[date('w', $i)];
     36                $dateweekday_abbrev = $wp_locale->weekday_abbrev[$dateweekday];
     37                $datemeridiem = $wp_locale->meridiem[date('a', $i)];
     38                $datemeridiem_capital = $wp_locale->meridiem[date('A', $i)];
    3739                $dateformatstring = ' '.$dateformatstring;
    3840                $dateformatstring = preg_replace("/([^\\\])D/", "\\1".backslashit($dateweekday_abbrev), $dateformatstring);
    3941                $dateformatstring = preg_replace("/([^\\\])F/", "\\1".backslashit($datemonth), $dateformatstring);
    4042                $dateformatstring = preg_replace("/([^\\\])l/", "\\1".backslashit($dateweekday), $dateformatstring);
    4143                $dateformatstring = preg_replace("/([^\\\])M/", "\\1".backslashit($datemonth_abbrev), $dateformatstring);
     44                $dateformatstring = preg_replace("/([^\\\])a/", "\\1".backslashit($datemeridiem), $dateformatstring);
     45                $dateformatstring = preg_replace("/([^\\\])A/", "\\1".backslashit($datemeridiem_capital), $dateformatstring);
    4246
    4347                $dateformatstring = substr($dateformatstring, 1, strlen($dateformatstring)-1);
    4448        }
     
    6670}
    6771
    6872function date_i18n($dateformatstring, $unixtimestamp) {
    69         global $month, $weekday, $month_abbrev, $weekday_abbrev;
     73        global $wp_locale;
    7074        $i = $unixtimestamp;
    71         if ( (!empty($month)) && (!empty($weekday)) ) {
    72                 $datemonth = $month[date('m', $i)];
    73                 $datemonth_abbrev = $month_abbrev[$datemonth];
    74                 $dateweekday = $weekday[date('w', $i)];
    75                 $dateweekday_abbrev = $weekday_abbrev[$dateweekday];
     75        if ( (!empty($wp_locale->month)) && (!empty($wp_locale->weekday)) ) {
     76                $datemonth = $wp_locale->month[date('m', $i)];
     77                $datemonth_abbrev = $wp_locale->month_abbrev[$datemonth];
     78                $dateweekday = $wp_locale->weekday[date('w', $i)];
     79                $dateweekday_abbrev = $wp_locale->weekday_abbrev[$dateweekday];
     80                $datemeridiem = $wp_locale->meridiem[date('a', $i)];
     81                $datemeridiem_capital = $wp_locale->meridiem[date('A', $i)];
    7682                $dateformatstring = ' '.$dateformatstring;
    7783                $dateformatstring = preg_replace("/([^\\\])D/", "\${1}".backslashit($dateweekday_abbrev), $dateformatstring);
    7884                $dateformatstring = preg_replace("/([^\\\])F/", "\${1}".backslashit($datemonth), $dateformatstring);
    7985                $dateformatstring = preg_replace("/([^\\\])l/", "\${1}".backslashit($dateweekday), $dateformatstring);
    8086                $dateformatstring = preg_replace("/([^\\\])M/", "\${1}".backslashit($datemonth_abbrev), $dateformatstring);
     87                $dateformatstring = preg_replace("/([^\\\])a/", "\${1}".backslashit($datemeridiem), $dateformatstring);
     88                $dateformatstring = preg_replace("/([^\\\])A/", "\${1}".backslashit($datemeridiem_capital), $dateformatstring);
     89
    8190                $dateformatstring = substr($dateformatstring, 1, strlen($dateformatstring)-1);
    8291        }
    8392        $j = @date($dateformatstring, $i);
    8493        return $j;
    85         }
     94}
    8695
    8796function get_weekstartend($mysqlstring, $start_of_week) {
    8897        $my = substr($mysqlstring,0,4);
  • E:/PHP/WordPress/SVN/wp-includes/locale.php

     
    11<?php
     2
    23// Date and Time
    34
    4 // The Weekdays
    5 $weekday[0] = __('Sunday');
    6 $weekday[1] = __('Monday');
    7 $weekday[2] = __('Tuesday');
    8 $weekday[3] = __('Wednesday');
    9 $weekday[4] = __('Thursday');
    10 $weekday[5] = __('Friday');
    11 $weekday[6] = __('Saturday');
     5class WP_Locale {
     6        var $weekday;
     7        var $weekday_initial;
     8        var $weekday_abbrev;
    129
    13 // The first letter of each day.  The _%day%_initial suffix is a hack to make
    14 // sure the day initials are unique.  They should be translated to a one
    15 // letter initial. 
    16 $weekday_initial[__('Sunday')]    = __('S_Sunday_initial');
    17 $weekday_initial[__('Monday')]    = __('M_Monday_initial');
    18 $weekday_initial[__('Tuesday')]   = __('T_Tuesday_initial');
    19 $weekday_initial[__('Wednesday')] = __('W_Wednesday_initial');
    20 $weekday_initial[__('Thursday')]  = __('T_Thursday_initial');
    21 $weekday_initial[__('Friday')]    = __('F_Friday_initial');
    22 $weekday_initial[__('Saturday')]  = __('S_Saturday_initial');
     10        var $month;
     11        var $month_abbrev;
    2312
    24 foreach ($weekday_initial as $weekday_ => $weekday_initial_) {
    25   $weekday_initial[$weekday_] = preg_replace('/_.+_initial$/', '', $weekday_initial_);
    26 }
     13        var $meridiem;
    2714
    28 // Abbreviations for each day.
    29 $weekday_abbrev[__('Sunday')]    = __('Sun');
    30 $weekday_abbrev[__('Monday')]    = __('Mon');
    31 $weekday_abbrev[__('Tuesday')]   = __('Tue');
    32 $weekday_abbrev[__('Wednesday')] = __('Wed');
    33 $weekday_abbrev[__('Thursday')]  = __('Thu');
    34 $weekday_abbrev[__('Friday')]    = __('Fri');
    35 $weekday_abbrev[__('Saturday')]  = __('Sat');
     15        function init() {
     16                // The Weekdays
     17                $this->weekday[0] = __('Sunday');
     18                $this->weekday[1] = __('Monday');
     19                $this->weekday[2] = __('Tuesday');
     20                $this->weekday[3] = __('Wednesday');
     21                $this->weekday[4] = __('Thursday');
     22                $this->weekday[5] = __('Friday');
     23                $this->weekday[6] = __('Saturday');
    3624
    37 // The Months
    38 $month['01'] = __('January');
    39 $month['02'] = __('February');
    40 $month['03'] = __('March');
    41 $month['04'] = __('April');
    42 $month['05'] = __('May');
    43 $month['06'] = __('June');
    44 $month['07'] = __('July');
    45 $month['08'] = __('August');
    46 $month['09'] = __('September');
    47 $month['10'] = __('October');
    48 $month['11'] = __('November');
    49 $month['12'] = __('December');
     25                // The first letter of each day.  The _%day%_initial suffix is a hack to make
     26                // sure the day initials are unique.
     27                $this->weekday_initial[__('Sunday')]    = __('S_Sunday_initial');
     28                $this->weekday_initial[__('Monday')]    = __('M_Monday_initial');
     29                $this->weekday_initial[__('Tuesday')]   = __('T_Tuesday_initial');
     30                $this->weekday_initial[__('Wednesday')] = __('W_Wednesday_initial');
     31                $this->weekday_initial[__('Thursday')]  = __('T_Thursday_initial');
     32                $this->weekday_initial[__('Friday')]    = __('F_Friday_initial');
     33                $this->weekday_initial[__('Saturday')]  = __('S_Saturday_initial');
    5034
    51 // Abbreviations for each month. Uses the same hack as above to get around the
    52 // 'May' duplication.
    53 $month_abbrev[__('January')] = __('Jan_January_abbreviation');
    54 $month_abbrev[__('February')] = __('Feb_February_abbreviation');
    55 $month_abbrev[__('March')] = __('Mar_March_abbreviation');
    56 $month_abbrev[__('April')] = __('Apr_April_abbreviation');
    57 $month_abbrev[__('May')] = __('May_May_abbreviation');
    58 $month_abbrev[__('June')] = __('Jun_June_abbreviation');
    59 $month_abbrev[__('July')] = __('Jul_July_abbreviation');
    60 $month_abbrev[__('August')] = __('Aug_August_abbreviation');
    61 $month_abbrev[__('September')] = __('Sep_September_abbreviation');
    62 $month_abbrev[__('October')] = __('Oct_October_abbreviation');
    63 $month_abbrev[__('November')] = __('Nov_November_abbreviation');
    64 $month_abbrev[__('December')] = __('Dec_December_abbreviation');
     35                foreach ($this->weekday_initial as $weekday_ => $weekday_initial_) {
     36                        $this->weekday_initial[$weekday_] = preg_replace('/_.+_initial$/', '', $weekday_initial_);
     37                }
    6538
    66 foreach ($month_abbrev as $month_ => $month_abbrev_) {
    67   $month_abbrev[$month_] = preg_replace('/_.+_abbreviation$/', '', $month_abbrev_);
     39                // Abbreviations for each day.
     40                $this->weekday_abbrev[__('Sunday')]    = __('Sun');
     41                $this->weekday_abbrev[__('Monday')]    = __('Mon');
     42                $this->weekday_abbrev[__('Tuesday')]   = __('Tue');
     43                $this->weekday_abbrev[__('Wednesday')] = __('Wed');
     44                $this->weekday_abbrev[__('Thursday')]  = __('Thu');
     45                $this->weekday_abbrev[__('Friday')]    = __('Fri');
     46                $this->weekday_abbrev[__('Saturday')]  = __('Sat');
     47
     48                // The Months
     49                $this->month['01'] = __('January');
     50                $this->month['02'] = __('February');
     51                $this->month['03'] = __('March');
     52                $this->month['04'] = __('April');
     53                $this->month['05'] = __('May');
     54                $this->month['06'] = __('June');
     55                $this->month['07'] = __('July');
     56                $this->month['08'] = __('August');
     57                $this->month['09'] = __('September');
     58                $this->month['10'] = __('October');
     59                $this->month['11'] = __('November');
     60                $this->month['12'] = __('December');
     61
     62                // Abbreviations for each month. Uses the same hack as above to get around the
     63                // 'May' duplication.
     64                $this->month_abbrev[__('January')] = __('Jan_January_abbreviation');
     65                $this->month_abbrev[__('February')] = __('Feb_February_abbreviation');
     66                $this->month_abbrev[__('March')] = __('Mar_March_abbreviation');
     67                $this->month_abbrev[__('April')] = __('Apr_April_abbreviation');
     68                $this->month_abbrev[__('May')] = __('May_May_abbreviation');
     69                $this->month_abbrev[__('June')] = __('Jun_June_abbreviation');
     70                $this->month_abbrev[__('July')] = __('Jul_July_abbreviation');
     71                $this->month_abbrev[__('August')] = __('Aug_August_abbreviation');
     72                $this->month_abbrev[__('September')] = __('Sep_September_abbreviation');
     73                $this->month_abbrev[__('October')] = __('Oct_October_abbreviation');
     74                $this->month_abbrev[__('November')] = __('Nov_November_abbreviation');
     75                $this->month_abbrev[__('December')] = __('Dec_December_abbreviation');
     76
     77                foreach ($this->month_abbrev as $month_ => $month_abbrev_) {
     78                        $this->month_abbrev[$month_] = preg_replace('/_.+_abbreviation$/', '', $month_abbrev_);
     79                }
     80
     81                // The Meridiem
     82                $this->meridiem['am'] = __('am');
     83                $this->meridiem['pm'] = __('pm');
     84                $this->meridiem['AM'] = __('AM');
     85                $this->meridiem['PM'] = __('PM');
     86        }
     87
     88        function WP_Locale() {
     89                $this->init();
     90        }
    6891}
    6992
    7093?>
     94 No newline at end of file
  • E:/PHP/WordPress/SVN/wp-includes/template-functions-general.php

     
    134134
    135135function wp_title($sep = '&raquo;', $display = true) {
    136136        global $wpdb;
    137         global $m, $year, $monthnum, $day, $category_name, $month, $posts;
     137        global $m, $year, $monthnum, $day, $category_name, $wp_locale, $posts;
    138138
    139139        $cat = get_query_var('cat');
    140140        $p = get_query_var('p');
     
    173173        // If there's a month
    174174        if ( !empty($m) ) {
    175175                $my_year = substr($m, 0, 4);
    176                 $my_month = $month[substr($m, 4, 2)];
     176                $my_month = $wp_locale->month[substr($m, 4, 2)];
    177177                $title = "$my_year $sep $my_month";
    178178        }
    179179
    180180        if ( !empty($year) ) {
    181181                $title = $year;
    182182                if ( !empty($monthnum) )
    183                         $title .= " $sep ".$month[zeroise($monthnum, 2)];
     183                        $title .= " $sep ".$wp_locale->month[zeroise($monthnum, 2)];
    184184                if ( !empty($day) )
    185185                        $title .= " $sep ".zeroise($day, 2);
    186186        }
     
    240240
    241241
    242242function single_month_title($prefix = '', $display = true ) {
    243         global $m, $monthnum, $month, $year;
     243        global $m, $monthnum, $wp_locale, $year;
    244244        if ( !empty($monthnum) && !empty($year) ) {
    245245                $my_year = $year;
    246                 $my_month = $month[str_pad($monthnum, 2, '0', STR_PAD_LEFT)];
     246                $my_month = $wp_locale->month[str_pad($monthnum, 2, '0', STR_PAD_LEFT)];
    247247        } elseif ( !empty($m) ) {
    248248                $my_year = substr($m, 0, 4);
    249                 $my_month = $month[substr($m, 4, 2)];
     249                $my_month = $wp_locale->month[substr($m, 4, 2)];
    250250        }
    251251
    252252        if ( !empty($my_month) && $display )
     
    292292
    293293
    294294function get_archives($type='', $limit='', $format='html', $before = '', $after = '', $show_post_count = false) {
    295         global $month, $wpdb;
     295        global $wp_locale, $wpdb;
    296296
    297297        if ( '' == $type )
    298298                $type = 'monthly';
     
    330330                        foreach ( $arcresults as $arcresult ) {
    331331                                $url    = get_month_link($arcresult->year,      $arcresult->month);
    332332                                if ( $show_post_count ) {
    333                                         $text = sprintf('%s %d', $month[zeroise($arcresult->month,2)], $arcresult->year);
     333                                        $text = sprintf('%s %d', $wp_locale->month[zeroise($arcresult->month,2)], $arcresult->year);
    334334                                        $after = '&nbsp;('.$arcresult->posts.')' . $afterafter;
    335335                                } else {
    336                                         $text = sprintf('%s %d', $month[zeroise($arcresult->month,2)], $arcresult->year);
     336                                        $text = sprintf('%s %d', $wp_locale->month[zeroise($arcresult->month,2)], $arcresult->year);
    337337                                }
    338338                                echo get_archives_link($url, $text, $format, $before, $after);
    339339                        }
     
    394394
    395395
    396396function get_calendar($daylength = 1) {
    397         global $wpdb, $m, $monthnum, $year, $timedifference, $month, $month_abbrev, $weekday, $weekday_initial, $weekday_abbrev, $posts;
     397        global $wpdb, $m, $monthnum, $year, $timedifference, $wp_locale, $posts;
    398398
    399399        // Quick check. If we have no posts at all, abort!
    400400        if ( !$posts ) {
     
    450450                        LIMIT 1");
    451451
    452452        echo '<table id="wp-calendar">
    453         <caption>' . $month[zeroise($thismonth, 2)] . ' ' . date('Y', $unixmonth) . '</caption>
     453        <caption>' . $wp_locale->month[zeroise($thismonth, 2)] . ' ' . date('Y', $unixmonth) . '</caption>
    454454        <thead>
    455455        <tr>';
    456456
    457         $day_abbrev = $weekday_initial;
     457        $day_abbrev = $wp_locale->weekday_initial;
    458458        if ( $daylength > 1 )
    459                 $day_abbrev = $weekday_abbrev;
     459                $day_abbrev = $wp_locale->weekday_abbrev;
    460460
    461461        $myweek = array();
    462462
    463463        for ( $wdcount=0; $wdcount<=6; $wdcount++ ) {
    464                 $myweek[]=$weekday[($wdcount+$week_begins)%7];
     464                $myweek[]=$wp_locale->weekday[($wdcount+$week_begins)%7];
    465465        }
    466466
    467467        foreach ( $myweek as $wd ) {
     
    476476        <tr>';
    477477
    478478        if ( $previous ) {
    479                 echo "\n\t\t".'<td abbr="' . $month[zeroise($previous->month, 2)] . '" colspan="3" id="prev"><a href="' .
    480                 get_month_link($previous->year, $previous->month) . '" title="' . sprintf(__('View posts for %1$s %2$s'), $month[zeroise($previous->month, 2)],
    481                         date('Y', mktime(0, 0 , 0, $previous->month, 1, $previous->year))) . '">&laquo; ' . $month_abbrev[$month[zeroise($previous->month, 2)]] . '</a></td>';
     479                echo "\n\t\t".'<td abbr="' . $wp_locale->month[zeroise($previous->month, 2)] . '" colspan="3" id="prev"><a href="' .
     480                get_month_link($previous->year, $previous->month) . '" title="' . sprintf(__('View posts for %1$s %2$s'), $wp_locale->month[zeroise($previous->month, 2)],
     481                        date('Y', mktime(0, 0 , 0, $previous->month, 1, $previous->year))) . '">&laquo; ' . $wp_locale->month_abbrev[$wp_locale->month[zeroise($previous->month, 2)]] . '</a></td>';
    482482        } else {
    483483                echo "\n\t\t".'<td colspan="3" id="prev" class="pad">&nbsp;</td>';
    484484        }
     
    486486        echo "\n\t\t".'<td class="pad">&nbsp;</td>';
    487487
    488488        if ( $next ) {
    489                 echo "\n\t\t".'<td abbr="' . $month[zeroise($next->month, 2)] . '" colspan="3" id="next"><a href="' .
    490                 get_month_link($next->year, $next->month) . '" title="' . sprintf(__('View posts for %1$s %2$s'), $month[zeroise($next->month, 2)],
    491                         date('Y', mktime(0, 0 , 0, $next->month, 1, $next->year))) . '">' . $month_abbrev[$month[zeroise($next->month, 2)]] . ' &raquo;</a></td>';
     489                echo "\n\t\t".'<td abbr="' . $wp_locale->month[zeroise($next->month, 2)] . '" colspan="3" id="next"><a href="' .
     490                get_month_link($next->year, $next->month) . '" title="' . sprintf(__('View posts for %1$s %2$s'), $wp_locale->month[zeroise($next->month, 2)],
     491                        date('Y', mktime(0, 0 , 0, $next->month, 1, $next->year))) . '">' . $wp_locale->month_abbrev[$wp_locale->month[zeroise($next->month, 2)]] . ' &raquo;</a></td>';
    492492        } else {
    493493                echo "\n\t\t".'<td colspan="3" id="next" class="pad">&nbsp;</td>';
    494494        }
     
    675675
    676676
    677677function the_weekday() {
    678         global $weekday, $id, $post;
    679         $the_weekday = $weekday[mysql2date('w', $post->post_date)];
     678        global $wp_locale, $id, $post;
     679        $the_weekday = $wp_locale->weekday[mysql2date('w', $post->post_date)];
    680680        $the_weekday = apply_filters('the_weekday', $the_weekday);
    681681        echo $the_weekday;
    682682}
    683683
    684684
    685685function the_weekday_date($before='',$after='') {
    686         global $weekday, $id, $post, $day, $previousweekday;
     686        global $wp_locale, $id, $post, $day, $previousweekday;
    687687        $the_weekday_date = '';
    688688        if ( $day != $previousweekday ) {
    689689                $the_weekday_date .= $before;
    690                 $the_weekday_date .= $weekday[mysql2date('w', $post->post_date)];
     690                $the_weekday_date .= $wp_locale->weekday[mysql2date('w', $post->post_date)];
    691691                $the_weekday_date .= $after;
    692692                $previousweekday = $day;
    693693        }
  • E:/PHP/WordPress/SVN/wp-settings.php

     
    216216// Pull in locale data after loading text domain.
    217217require_once(ABSPATH . WPINC . '/locale.php');
    218218
     219$wp_locale = new WP_Locale();
     220
    219221// Load functions for active theme.
    220222if ( file_exists(TEMPLATEPATH . "/functions.php") )
    221223        include(TEMPLATEPATH . "/functions.php");