added Minguo calendar support for the Taiwan Chinese language
authorShinjiman <shinjiman@users.mediawiki.org>
Tue, 19 May 2009 16:38:21 +0000 (16:38 +0000)
committerShinjiman <shinjiman@users.mediawiki.org>
Tue, 19 May 2009 16:38:21 +0000 (16:38 +0000)
languages/Language.php
languages/messages/MessagesZh_tw.php

index e296d90..aa96d6f 100644 (file)
@@ -567,6 +567,8 @@ class Language {
         *
         *    xkY  Y (full year) in Thai solar calendar. Months and days are
         *                       identical to the Gregorian calendar
+        *    xoY  Y (full year) in Minguo calendar. Months and days are
+        *                       identical to the Gregorian calendar
         *
         * Characters enclosed in double quotes will be considered literal (with
         * the quotes themselves removed). Unmatched quotes will be considered
@@ -598,6 +600,7 @@ class Language {
                $hebrew = false;
                $hijri = false;
                $thai = false;
+               $minguo = false;
                for ( $p = 0; $p < strlen( $format ); $p++ ) {
                        $num = false;
                        $code = $format[$p];
@@ -605,7 +608,7 @@ class Language {
                                $code .= $format[++$p];
                        }
 
-                       if ( ( $code === 'xi' || $code == 'xj' || $code == 'xk' || $code == 'xm' ) && $p < strlen( $format ) - 1 ) {
+                       if ( ( $code === 'xi' || $code == 'xj' || $code == 'xk' || $code == 'xm' || $code == 'xo' ) && $p < strlen( $format ) - 1 ) {
                                $code .= $format[++$p];
                        }
 
@@ -752,6 +755,10 @@ class Language {
                                        if ( !$thai ) $thai = self::tsToThai( $ts );
                                        $num = $thai[0];
                                        break;
+                               case 'xoY':
+                                       if ( !$minguo ) $minguo = self::tsToMinguo( $ts );
+                                       $num = $minguo[0];
+                                       break;
                                case 'y':
                                        $num = substr( $ts, 2, 2 );
                                        break;
@@ -1132,6 +1139,25 @@ class Language {
                return array( $gy_thai, $gm, $gd );
        }
 
+       /**
+        * Algorithm to convert Gregorian dates to Minguo dates.
+        *
+        * Link: http://en.wikipedia.org/wiki/Minguo_calendar
+        *
+        * @param $ts String: 14-character timestamp
+        * @return array converted year, month, day
+        */
+       private static function tsToMinguo( $ts ) {
+               $gy = substr( $ts, 0, 4 );
+               $gm = substr( $ts, 4, 2 );
+               $gd = substr( $ts, 6, 2 );
+
+               # Deduct 1911 years from the Gregorian calendar
+               # Months and days are identical
+               $gy_minguo = $gy - 1911;
+
+               return array( $gy_minguo, $gm, $gd );
+       }
 
        /**
         * Roman number formatting up to 3000
index a39a7d9..a83a503 100644 (file)
@@ -38,6 +38,29 @@ $namespaceNames = array(
        NS_CATEGORY_TALK    => '分類討論'
 );
 
+$datePreferences = array(
+       'default',
+       'minguo',
+       'CNS 7648',
+       'ISO 8601',
+);
+
+$defaultDateFormat = 'zh';
+
+$dateFormats = array(
+       'zh time' => 'H:i',
+       'zh date' => 'Y年n月j日 (l)',
+       'zh both' => 'Y年n月j日 (D) H:i',
+
+       'minguo time' => 'H:i',
+       'minguo date' => 'xoY年n月j日 (l)',
+       'minguo both' => 'xoY年n月j日 (D) H:i',
+
+       'CNS 7648 time' => 'H:i',
+       'CNS 7648 date' => 'R.O.C. xoY-m-d (l)',
+       'CNS 7648 both' => 'R.O.C. xoY-m-d (D) H:i',
+);
+
 $messages = array(
 # User preference toggles
 'tog-underline'            => '鏈結標注底線',