WordPress.org

Make WordPress Core

Changeset 3676


Ignore:
Timestamp:
04/02/2006 12:20:11 AM (12 years ago)
Author:
ryan
Message:

WP_Locale. Props Sewar. fixes #2568

Location:
trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/admin-functions.php

    r3672 r3676  
    970970
    971971function touch_time($edit = 1, $for_post = 1) {
    972     global $month, $post, $comment;
     972    global $wp_locale, $post, $comment;
    973973
    974974    if ( $for_post )
     
    990990        echo "\t\t\t<option value=\"$i\"";
    991991        if ($i == $mm)
    992             echo " selected='selected'";
    993         if ($i < 10) {
    994             $ii = "0".$i;
    995         } else {
    996             $ii = "$i";
    997         }
    998         echo ">".$month["$ii"]."</option>\n";
     992            echo ' selected="selected"';
     993        echo '>' . $wp_locale->get_month($i) . "</option>\n";
    999994    }
    1000995?>
     
    10081003    if ( $edit ) {
    10091004        _e('Existing timestamp');
    1010         echo ": {$month[$mm]} $jj, $aa @ $hh:$mn";
     1005        //echo ': ' . $wp_locale->get_month($mm) . "$jj, $aa @ $hh:$mn";
     1006        echo sprintf(__(': %1$s %2$s, %3$s @ %4$s:%5$s'), $wp_locale->get_month($mm), $jj, $aa, $hh, $mn);
    10111007    }
    10121008?>
  • trunk/wp-admin/edit.php

    r3671 r3676  
    9494            $arc_year  = $arc_row->yyear;
    9595            $arc_month = $arc_row->mmonth;
    96 
    97             if( isset($_GET['m']) && $arc_year . zeroise($arc_month, 2) == (int) $_GET['m'] )
     96            $arc_month = zeroise($arc_month, 2);
     97
     98            if( isset($_GET['m']) && $arc_year . $arc_month == (int) $_GET['m'] )
    9899                $default = 'selected="selected"';
    99100            else
    100101                $default = null;
    101102
    102             echo "<option $default value=\"" . $arc_year.zeroise($arc_month, 2) . '">';
    103             echo $month[zeroise($arc_month, 2)] . " $arc_year";
     103            echo "<option $default value=\"" . $arc_year . $arc_month . '">';
     104            echo $wp_locale->get_month($arc_month) . " $arc_year";
    104105            echo "</option>\n";
    105106        }
  • trunk/wp-admin/options-general.php

    r3548 r3676  
    9595<?php
    9696for ($day_index = 0; $day_index <= 6; $day_index++) :
    97 if ($day_index == get_settings('start_of_week')) $selected = " selected='selected'";
    98 else $selected = '';
    99 echo "\n\t<option value='$day_index' $selected>$weekday[$day_index]</option>";
     97    $selected = (get_settings('start_of_week') == $day_index) ? 'selected="selected"' : '';
     98    echo "\n\t<option value='$day_index' $selected>" . $wp_locale->get_weekday($day_index) . '</option>';
    10099endfor;
    101100?>
  • trunk/wp-includes/functions.php

    r3670 r3676  
    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) ) {
     
    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->get_month(date('m', $i));
     34        $datemonth_abbrev = $wp_locale->get_month_abbrev($datemonth);
     35        $dateweekday = $wp_locale->get_weekday(date('w', $i));
     36        $dateweekday_abbrev = $wp_locale->get_weekday_abbrev($dateweekday);
     37        $datemeridiem = $wp_locale->get_meridiem(date('a', $i));
     38        $datemeridiem_capital = $wp_locale->get_meridiem(date('A', $i));
    3739        $dateformatstring = ' '.$dateformatstring;
    3840        $dateformatstring = preg_replace("/([^\\\])D/", "\${1}".backslashit($dateweekday_abbrev), $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);
     
    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->get_month(date('m', $i));
     77        $datemonth_abbrev = $wp_locale->get_month_abbrev($datemonth);
     78        $dateweekday = $wp_locale->get_weekday(date('w', $i));
     79        $dateweekday_abbrev = $wp_locale->get_weekday_abbrev($dateweekday);
     80        $datemeridiem = $wp_locale->get_meridiem(date('a', $i));
     81        $datemeridiem_capital = $wp_locale->get_meridiem(date('A', $i));
    7682        $dateformatstring = ' '.$dateformatstring;
    7783        $dateformatstring = preg_replace("/([^\\\])D/", "\${1}".backslashit($dateweekday_abbrev), $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) {
  • trunk/wp-includes/locale.php

    r2232 r3676  
    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 Meridiems
     82        $this->meridiem['am'] = __('am');
     83        $this->meridiem['pm'] = __('pm');
     84        $this->meridiem['AM'] = __('AM');
     85        $this->meridiem['PM'] = __('PM');
     86    }
     87
     88    function get_weekday($weekday_number) {
     89        return $this->weekday[$weekday_number];
     90    }
     91
     92    function get_weekday_initial($weekday_name) {
     93        return $this->weekday_initial[$weekday_name];
     94    }
     95
     96    function get_weekday_abbrev($weekday_name) {
     97        return $this->weekday_abbrev[$weekday_name];
     98    }
     99
     100    function get_month($month_number) {
     101        return $this->month[zeroise($month_number, 2)];
     102    }
     103
     104    function get_month_initial($month_name) {
     105        return $this->month_initial[$month_name];
     106    }
     107
     108    function get_month_abbrev($month_name) {
     109        return $this->month_abbrev[$month_name];
     110    }
     111
     112    function get_meridiem($meridiem) {
     113        return $this->meridiem[$meridiem];
     114    }
     115
     116    // Global variables are deprecated. For backwards compatibility only.
     117    function register_globals() {
     118        $GLOBALS['weekday']         = $this->weekday;
     119        $GLOBALS['weekday_initial'] = $this->weekday_initial;
     120        $GLOBALS['weekday_abbrev']  = $this->weekday_abbrev;
     121        $GLOBALS['month']           = $this->month;
     122        $GLOBALS['month_abbrev']    = $this->month_abbrev;
     123    }
     124
     125    function WP_Locale() {
     126        $this->init();
     127        $this->register_globals();
     128    }
    68129}
    69130
  • trunk/wp-includes/template-functions-general.php

    r3566 r3676  
    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');
     
    174174    if ( !empty($m) ) {
    175175        $my_year = substr($m, 0, 4);
    176         $my_month = $month[substr($m, 4, 2)];
     176        $my_month = $wp_locale->get_month($m);
    177177        $title = "$my_year $sep $my_month";
    178178    }
     
    181181        $title = $year;
    182182        if ( !empty($monthnum) )
    183             $title .= " $sep ".$month[zeroise($monthnum, 2)];
     183            $title .= " $sep ".$wp_locale->get_month($monthnum);
    184184        if ( !empty($day) )
    185185            $title .= " $sep ".zeroise($day, 2);
     
    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->get_month($monthnum);
    247247    } elseif ( !empty($m) ) {
    248248        $my_year = substr($m, 0, 4);
    249         $my_month = $month[substr($m, 4, 2)];
     249        $my_month = $wp_locale->get_month($m);
    250250    }
    251251
     
    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 )
     
    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->get_month($arcresult->month), $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->get_month($arcresult->month), $arcresult->year);
    337337                }
    338338                echo get_archives_link($url, $text, $format, $before, $after);
     
    394394
    395395
    396 function get_calendar($daylength = 1) {
    397     global $wpdb, $m, $monthnum, $year, $timedifference, $month, $month_abbrev, $weekday, $weekday_initial, $weekday_abbrev, $posts;
     396function get_calendar($initial = true) {
     397    global $wpdb, $m, $monthnum, $year, $timedifference, $wp_locale, $posts;
    398398
    399399    // Quick check. If we have no posts at all, abort!
     
    451451
    452452    echo '<table id="wp-calendar">
    453     <caption>' . $month[zeroise($thismonth, 2)] . ' ' . date('Y', $unixmonth) . '</caption>
     453    <caption>' . $wp_locale->get_month($thismonth) . ' ' . date('Y', $unixmonth) . '</caption>
    454454    <thead>
    455455    <tr>';
    456456
    457     $day_abbrev = $weekday_initial;
    458     if ( $daylength > 1 )
    459         $day_abbrev = $weekday_abbrev;
    460 
    461457    $myweek = array();
    462458
    463459    for ( $wdcount=0; $wdcount<=6; $wdcount++ ) {
    464         $myweek[]=$weekday[($wdcount+$week_begins)%7];
     460        $myweek[] = $wp_locale->get_weekday(($wdcount+$week_begins)%7);
    465461    }
    466462
    467463    foreach ( $myweek as $wd ) {
    468         echo "\n\t\t<th abbr=\"$wd\" scope=\"col\" title=\"$wd\">" . $day_abbrev[$wd] . '</th>';
     464        $day_name = (true == $initial) ? $wp_locale->get_weekday_initial($wd) : $wp_locale->get_weekday_abbrev($wd);
     465        echo "\n\t\t<th abbr=\"$wd\" scope=\"col\" title=\"$wd\">$day_name</th>";
    469466    }
    470467
     
    477474
    478475    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>';
     476        echo "\n\t\t".'<td abbr="' . $wp_locale->get_month($previous->month) . '" colspan="3" id="prev"><a href="' .
     477        get_month_link($previous->year, $previous->month) . '" title="' . sprintf(__('View posts for %1$s %2$s'), $wp_locale->get_month($previous->month),
     478            date('Y', mktime(0, 0 , 0, $previous->month, 1, $previous->year))) . '">&laquo; ' . $wp_locale->get_month_abbrev($wp_locale->get_month($previous->month)) . '</a></td>';
    482479    } else {
    483480        echo "\n\t\t".'<td colspan="3" id="prev" class="pad">&nbsp;</td>';
     
    487484
    488485    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>';
     486        echo "\n\t\t".'<td abbr="' . $wp_locale->get_month($next->month) . '" colspan="3" id="next"><a href="' .
     487        get_month_link($next->year, $next->month) . '" title="' . sprintf(__('View posts for %1$s %2$s'), $wp_locale->get_month($next->month),
     488            date('Y', mktime(0, 0 , 0, $next->month, 1, $next->year))) . '">' . $wp_locale->get_month_abbrev($wp_locale->get_month($next->month)) . ' &raquo;</a></td>';
    492489    } else {
    493490        echo "\n\t\t".'<td colspan="3" id="next" class="pad">&nbsp;</td>';
     
    676673
    677674function the_weekday() {
    678     global $weekday, $id, $post;
    679     $the_weekday = $weekday[mysql2date('w', $post->post_date)];
     675    global $wp_locale, $id, $post;
     676    $the_weekday = $wp_locale->get_weekday(mysql2date('w', $post->post_date));
    680677    $the_weekday = apply_filters('the_weekday', $the_weekday);
    681678    echo $the_weekday;
     
    684681
    685682function the_weekday_date($before='',$after='') {
    686     global $weekday, $id, $post, $day, $previousweekday;
     683    global $wp_locale, $id, $post, $day, $previousweekday;
    687684    $the_weekday_date = '';
    688685    if ( $day != $previousweekday ) {
    689686        $the_weekday_date .= $before;
    690         $the_weekday_date .= $weekday[mysql2date('w', $post->post_date)];
     687        $the_weekday_date .= $wp_locale->get_weekday(mysql2date('w', $post->post_date));
    691688        $the_weekday_date .= $after;
    692689        $previousweekday = $day;
  • trunk/wp-settings.php

    r3670 r3676  
    215215require_once(ABSPATH . WPINC . '/locale.php');
    216216
     217$wp_locale = new WP_Locale();
     218
    217219// Load functions for active theme.
    218220if ( file_exists(TEMPLATEPATH . "/functions.php") )
Note: See TracChangeset for help on using the changeset viewer.