Localisation updates from Betawiki.
[lhc/web/wiklou.git] / languages / Language.php
index 9248362..338c348 100644 (file)
@@ -8,18 +8,6 @@ if( !defined( 'MEDIAWIKI' ) ) {
        exit( 1 );
 }
 
-#
-# In general you should not make customizations in these language files
-# directly, but should use the MediaWiki: special namespace to customize
-# user interface messages through the wiki.
-# See http://meta.wikipedia.org/wiki/MediaWiki_namespace
-#
-# NOTE TO TRANSLATORS: Do not copy this whole file when making translations!
-# A lot of common constants and a base class with inheritable methods are
-# defined here, which should not be redefined. See the other LanguageXx.php
-# files for examples.
-#
-
 # Read language names
 global $wgLanguageNames;
 require_once( dirname(__FILE__) . '/Names.php' ) ;
@@ -102,6 +90,13 @@ class Language {
                'sep', 'oct', 'nov', 'dec'
        );
 
+       static public $mIranianCalendarMonthMsgs = array(
+               'iranian-calendar-m1', 'iranian-calendar-m2', 'iranian-calendar-m3',
+               'iranian-calendar-m4', 'iranian-calendar-m5', 'iranian-calendar-m6',
+               'iranian-calendar-m7', 'iranian-calendar-m8', 'iranian-calendar-m9',
+               'iranian-calendar-m10', 'iranian-calendar-m11', 'iranian-calendar-m12'
+       );
+
        /**
         * Create a language object for a given language code
         */
@@ -405,6 +400,11 @@ class Language {
                return $this->getMessageFromDB( self::$mWeekdayAbbrevMsgs[$key-1] );
        }
 
+       function getIranianCalendarMonthName( $key ) {
+               return $this->getMessageFromDB( self::$mIranianCalendarMonthMsgs[$key-1] );
+       }
+
+
        /**
         * Used by date() and time() to adjust the time output.
         * @public
@@ -476,6 +476,11 @@ class Language {
         *    xx   Literal x
         *    xg   Genitive month name
         *
+        *    xij  j (day number) in Iranian calendar
+        *    xiF  F (month name) in Iranian calendar
+        *    xin  n (month number) in Iranian calendar
+        *    xiY  Y (full year) in Iranian calendar
+        *
         * Characters enclosed in double quotes will be considered literal (with
         * the quotes themselves removed). Unmatched quotes will be considered
         * literal quotes. Example:
@@ -499,13 +504,18 @@ class Language {
                $roman = false;
                $unix = false;
                $rawToggle = false;
+               $iranian = false;
                for ( $p = 0; $p < strlen( $format ); $p++ ) {
                        $num = false;
                        $code = $format[$p];
                        if ( $code == 'x' && $p < strlen( $format ) - 1 ) {
                                $code .= $format[++$p];
                        }
-                       
+
+                       if ( $code === 'xi' && $p < strlen( $format ) - 1 ) {
+                               $code .= $format[++$p];
+                       }
+
                        switch ( $code ) {
                                case 'xx':
                                        $s .= 'x';
@@ -532,6 +542,10 @@ class Language {
                                case 'j':
                                        $num = intval( substr( $ts, 6, 2 ) );
                                        break;
+                               case 'xij':
+                                       if ( !$iranian ) $iranian = self::tsToIranian( $ts );
+                                       $num = $iranian[2];
+                                       break;
                                case 'l':
                                        if ( !$unix ) $unix = wfTimestamp( TS_UNIX, $ts );
                                        $s .= $this->getWeekdayName( gmdate( 'w', $unix ) + 1 );
@@ -552,10 +566,14 @@ class Language {
                                case 'W':
                                        if ( !$unix ) $unix = wfTimestamp( TS_UNIX, $ts );
                                        $num = gmdate( 'W', $unix );
-                                       break;                                  
+                                       break;
                                case 'F':
                                        $s .= $this->getMonthName( substr( $ts, 4, 2 ) );
                                        break;
+                               case 'xiF':
+                                       if ( !$iranian ) $iranian = self::tsToIranian( $ts );
+                                       $s .= $this->getIranianCalendarMonthName( $iranian[1] );
+                                       break;
                                case 'm':
                                        $num = substr( $ts, 4, 2 );
                                        break;
@@ -565,6 +583,10 @@ class Language {
                                case 'n':
                                        $num = intval( substr( $ts, 4, 2 ) );
                                        break;
+                               case 'xin':
+                                       if ( !$iranian ) $iranian = self::tsToIranian( $ts );
+                                       $num = $iranian[1];
+                                       break;
                                case 't':
                                        if ( !$unix ) $unix = wfTimestamp( TS_UNIX, $ts );
                                        $num = gmdate( 't', $unix );
@@ -572,10 +594,14 @@ class Language {
                                case 'L':
                                        if ( !$unix ) $unix = wfTimestamp( TS_UNIX, $ts );
                                        $num = gmdate( 'L', $unix );
-                                       break;                                  
+                                       break;
                                case 'Y':
                                        $num = substr( $ts, 0, 4 );
                                        break;
+                               case 'xiY':
+                                       if ( !$iranian ) $iranian = self::tsToIranian( $ts );
+                                       $num = $iranian[0];
+                                       break;
                                case 'y':
                                        $num = substr( $ts, 2, 2 );
                                        break;
@@ -660,6 +686,64 @@ class Language {
                return $s;
        }
 
+       private static $GREG_DAYS = array( 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 );
+       private static $IRANIAN_DAYS = array( 31, 31, 31, 31, 31, 31, 30, 30, 30, 30, 30, 29 );
+       /**
+        * Algorithm by Roozbeh Pournader and Mohammad Toossi to convert 
+        * Gregorian dates to Iranian dates. Originally written in C, it
+        * is released under the terms of GNU Lesser General Public
+        * License. Conversion to PHP was performed by Niklas Laxström.
+        * 
+        * Link: http://www.farsiweb.info/jalali/jalali.c
+        */
+       private static function tsToIranian( $ts ) {
+               $gy = substr( $ts, 0, 4 ) -1600;
+               $gm = substr( $ts, 4, 2 ) -1;
+               $gd = substr( $ts, 6, 2 ) -1;
+
+               # Days passed from the beginning (including leap years)
+               $gDayNo = 365*$gy
+                       + floor(($gy+3) / 4)
+                       - floor(($gy+99) / 100)
+                       + floor(($gy+399) / 400);
+
+
+               // Add days of the past months of this year
+               for( $i = 0; $i < $gm; $i++ ) {
+                       $gDayNo += self::$GREG_DAYS[$i];
+               }
+
+               // Leap years
+               if ( $gm > 1 && (($gy%4===0 && $gy%100!==0 || ($gy%400==0)))) {
+                       $gDayNo++;
+               }
+
+               // Days passed in current month
+               $gDayNo += $gd;
+               
+               $jDayNo = $gDayNo - 79;
+
+               $jNp = floor($jDayNo / 12053);
+               $jDayNo %= 12053;
+
+               $jy = 979 + 33*$jNp + 4*floor($jDayNo/1461);
+               $jDayNo %= 1461;
+
+               if ( $jDayNo >= 366 ) {
+                       $jy += floor(($jDayNo-1)/365);
+                       $jDayNo = floor(($jDayNo-1)%365);
+               }
+
+               for ( $i = 0; $i < 11 && $jDayNo >= self::$IRANIAN_DAYS[$i]; $i++ ) {
+                       $jDayNo -= self::$IRANIAN_DAYS[$i];
+               }
+
+               $jm= $i+1;
+               $jd= $jDayNo+1;
+
+               return array($jy, $jm, $jd);
+       }
+
        /**
         * Roman number formatting up to 3000
         */
@@ -1187,7 +1271,7 @@ class Language {
                $this->load();
                if ( !isset( $this->mExtendedSpecialPageAliases ) ) {
                        $this->mExtendedSpecialPageAliases = $this->specialPageAliases;
-                       wfRunHooks( 'LangugeGetSpecialPageAliases', 
+                       wfRunHooks( 'LanguageGetSpecialPageAliases', 
                                array( &$this->mExtendedSpecialPageAliases, $this->getCode() ) );
                }
                return $this->mExtendedSpecialPageAliases;
@@ -1363,7 +1447,7 @@ class Language {
 
        /**
         * Plural form transformations, needed for some languages.
-        * For example, where are 3 form of plural in Russian and Polish,
+        * For example, there are 3 form of plural in Russian and Polish,
         * depending on "count mod 10". See [[w:Plural]]
         * For English it is pretty simple.
         *
@@ -1922,6 +2006,3 @@ class Language {
                return str_replace( '$1', $this->formatNum( $size ), $text );
        }
 }
-
-
-