Zend - The PHP Company




Translation

Add Code


Date translation into lithuanian and russian languages  

Type: class
Added by: MOPO3_3
Entered: 20/05/2003
Last modified: 09/12/2002
Rating: - (fewer than 3 votes)
Views: 4520
This class formats data in english, lithuanian and russian languages. Exp. Monday, 12 April, 2003. Gets lang parameter from URL. Also there are function to compare two dates.


<?php
/*****************************************************************************************************************/
/************************************************  DATE FORMAT CLASS   **********************************************/
/*****************************************************************************************************************/
/**
* @author Pavel Zheltakov <PavelZ@5ci.lt>
* @version v1.5 2003.05.16
* @copyright Copyright � 2003, Pavel Zheltakov
*
* This class formats data in english, lithuanian and russian languages. Exp. Monday, 12 April, 2003.
* Compares two dates in format mm/dd/yyyy
*/

class date_format
{
    
/* Class vars */
    
var $yearT;
    var 
$month;
    var 
$monthT;
    var 
$month_r;
    var 
$month_l;
    var 
$monthdayT;
    var 
$weekday;
    var 
$weekdayT;
    var 
$weekday_r;
    var 
$weekday_l;
    var 
$data_full;
    
    
/* Constructor*/
    
function date_format ()
    {
        
$this->yearT date("Y");
        
$this->monthT date("n");
        
$this->monthdayT date("j");
        
$this->weekdayT date("w");
    }
    
    
/* Gets current date */
    
function get_tooday($lang)
    {
        
$this->lang $lang;
        
/* Array of weekdays */
        
$this->weekday = array(
                                                
=> "Sunday"
                                                
=> "Monday"
                                                
=> "Tuesday"
                                                
=> "Wednesday"
                                                
=> "Thursday"
                                                
=> "Friday"
                                                
=> "Saturday"
                                                
);
        
$this->weekday_r = array(
                                                    
=> "?????�?�??�"
                                                    
=> "???���?�???"
                                                    
=> "???????"
                                                    
=> "??��?"
                                                    
=> "��??�??"
                                                    
=> "?????�?"
                                                    
=> "?�?????"
                                                    
);
        
$this->weekday_l = array(
                                                    
=> "Sekmadienis"
                                                    
=> "Pirmadienis"
                                                    
=> "Antradienis"
                                                    
=> "Tre?iadienis"
                                                    
=> "Ketvirtadienis"
                                                    
=> "Penktadienis"
                                                    
=> "?e?tadienis"
                                                    );
        
/* Arrays of months */
        
$this->month = array(
                                            
=> "January"
                                            
=> "February"
                                            
=> "March"
                                            
=> "April"
                                            
=> "May"
                                            
=> "June"
                                            
=> "July"
                                            
=> "August"
                                            
=> "September"
                                            
10 => "October"
                                            
11 => "November"
                                            
12 => "December"
                                            
);
        
$this->month_r = array(
                                            
=> "�?????"
                                            
=> "?�?????"
                                            
=> "?????"
                                            
=> "???�??"
                                            
=> "???"
                                            
=> "????"
                                            
=> "????"
                                            
=> "???�???"
                                            
=> "?�??????"
                                            
10 => "???????"
                                            
11 => "??????"
                                            
12 => "��?????"
                                            
);
        
$this->month_l = array(
                                            
=> "Sausio"
                                            
=> "Vasario"
                                            
=> "Kovo"
                                            
=> "Baland?io"
                                            
=> "Gegu??s"
                                            
=> "Bir?elio"
                                            
=> "Liepos"
                                            
=> "Rugpj??io"
                                            
=> "Rugs?jo"
                                            
10 => "Spalio"
                                            
11 => "Lapkri?io"
                                            
12 => "Gruod?io"
                                            
);
        
/* do the concatenation for showing full date */
        
switch($this->lang)
        {
            case 
"lit" :
                
$this->data_full $this->weekday_l[$this->weekdayT].", ".$this->yearT." m. ".$this->month_l[$this->monthT]." ".$this->monthdayT." d.";
            break;
            case 
"eng" :
                
$this->data_full $this->weekday[$this->weekdayT].", ".$this->yearT." y. ".$this->month[$this->monthT]." ".$this->monthdayT." d.";
            break;
            case 
"rus" :
                
$this->data_full $this->weekday_r[$this->weekdayT].", ".$this->monthdayT." ".$this->month_r[$this->monthT]." ".$this->yearT." ??.";
            break;
            default :
                
$this->data_full $this->weekday_l[$this->weekdayT].", ".$this->yearT." ".$this->month_l[$this->monthT]." ".$this->monthdayT;
            break;
        }
        return 
$data_full;
    }
    
    
/* Do the comparison of two dates in format :  mm/dd/yyyy */
    
function compare_two_dates($data1$data2)
    {
        
$this->data1 $data1;
        
$this->data2 $data2;
        
        list(
$this->month1$this->day1$this->year1) = explode("/"$this->data1);
        list(
$this->month2$this->day2$this->year2) = explode("/"$this->data2);
        
        
$this->timestamp1 mktime(000$this->month1$this->day1$this->year1);
        
$this->timestamp2 mktime(000$this->month2$this->day2$this->year2);
        
        if(
$this->timestamp1 $this->timestamp2)
        {
            print 
"The bigger date is : ".$this->data1;
        }
        else
        {
            print 
"The bigger date is : ".$this->data2;
        }
    }
    
    
/* Prints current date depending on selected lang */
    
function show_date()
    {
        print 
$this->data_full;
    }
}
?>


Usage Example


See the example


Rate This Script





Search



This Category All Categories