(bugs 2633, 2672) Fix Estonian, Portuguese and Finnish numeric formatting
authorNiklas Laxström <nikerabbit@users.mediawiki.org>
Sat, 2 Jul 2005 20:26:02 +0000 (20:26 +0000)
committerNiklas Laxström <nikerabbit@users.mediawiki.org>
Sat, 2 Jul 2005 20:26:02 +0000 (20:26 +0000)
Little code cleanup

RELEASE-NOTES
languages/LanguageEt.php
languages/LanguageFi.php
languages/LanguagePt.php

index e615075..ffddb5a 100644 (file)
@@ -443,7 +443,7 @@ Various bugfixes, small features, and a few experimental things:
 * (bug 2629) Automatically capitalize usernames again instead of
   rejecting lowercase with a useless error message
 * (bug 2661) Fix link generation in contribs
-
+* (bugs 2633, 2672) Fix Estonian, Portuguese and Finnish numeric formatting
 
 === Caveats ===
 
index 1ef7d06..8c21fae 100644 (file)
@@ -1083,20 +1083,17 @@ class LanguageEt extends LanguageUtf8 {
                return $wgSkinNamesEt;
        }
 
-       function getValidSpecialPages()
-       {
+       function getValidSpecialPages() {
                global $wgValidSpecialPagesEt;
                return $wgValidSpecialPagesEt;
        }
 
-       function getSysopSpecialPages()
-       {
+       function getSysopSpecialPages() {
                global $wgSysopSpecialPagesEt;
                return $wgSysopSpecialPagesEt;
        }
 
-       function getDeveloperSpecialPages()
-       {
+       function getDeveloperSpecialPages() {
                global $wgDeveloperSpecialPagesEt;
                return $wgDeveloperSpecialPagesEt;
        }
@@ -1110,5 +1107,24 @@ class LanguageEt extends LanguageUtf8 {
                }
        }
 
+       /**
+        * Estonian numeric formatting is 123 456,78.
+        * Notice that the space is non-breaking.
+        */
+       function formatNum( $number, $year = false ) {
+               return $year ? $number : strtr($this->commafy($number), '.,', ", " );
+       }
+
+       /**
+        * Avoid grouping whole numbers between 0 to 9999
+        */
+       function commafy($_) {
+               if (!preg_match('/^\d{1,4}$/',$_)) {
+                       return strrev((string)preg_replace('/(\d{3})(?=\d)(?!\d*\.)/','$1,',strrev($_)));
+               } else {
+                       return $_;
+               }
+       }
+
 }
 ?>
index 6355871..bf47572 100644 (file)
@@ -1324,8 +1324,7 @@ class LanguageFi extends LanguageUtf8 {
     return $wgSkinNamesFi;
   }
 
-  function date( $ts, $adj = false )
-  {
+  function date( $ts, $adj = false ) {
     if ( $adj ) { $ts = $this->userAdjust( $ts ); }
 
     $d = (0 + substr( $ts, 6, 2 )) . '. ' .
@@ -1333,8 +1332,7 @@ class LanguageFi extends LanguageUtf8 {
     return $d;
   }
 
-  function time( $ts, $adj = false, $seconds = true )
-  {
+  function time( $ts, $adj = false, $seconds = true ) {
     if ( $adj ) { $ts = $this->userAdjust( $ts ); }
 
     $t = substr( $ts, 8, 2 ) . ':' . substr( $ts, 10, 2 );
@@ -1344,13 +1342,11 @@ class LanguageFi extends LanguageUtf8 {
     return $t;
   }
 
-  function timeanddate( $ts, $adj = false )
-  {
+  function timeanddate( $ts, $adj = false ) {
     return $this->date( $ts, $adj ) . ' kello ' . $this->time( $ts, $adj );
   }
 
-  function getMessage( $key )
-  {
+  function getMessage( $key ) {
     global $wgAllMessagesFi;
     if( isset( $wgAllMessagesFi[$key] ) ) {
       return $wgAllMessagesFi[$key];
@@ -1359,13 +1355,23 @@ class LanguageFi extends LanguageUtf8 {
     }
   }
 
-  var $digitTransTable = array(
-    ',' => '&nbsp;',
-    '.' => ','
-  );
+  /**
+   * Finnish numeric formatting is 123 456,78.
+   * Notice that the space is non-breaking.
+   */
+  function formatNum( $number, $year = false ) {
+    return $year ? $number : strtr($this->commafy($number), '.,', ", " );
+  }
 
-  function formatNum( $number ) {
-    return strtr($number, $this->digitTransTable );
+  /**
+   * Avoid grouping whole numbers between 0 to 9999
+   */
+  function commafy($_) {
+    if (!preg_match('/^\d{1,4}$/',$_)) {
+      return strrev((string)preg_replace('/(\d{3})(?=\d)(?!\d*\.)/','$1,',strrev($_)));
+    } else {
+      return $_;
+    }
   }
 
   # Convert from the nominative form of a noun to some other case
index 41c34ca..695c8a5 100644 (file)
@@ -954,38 +954,41 @@ class LanguagePt extends LanguageUtf8 {
         return $wgDateFormatsPt;
     }
 
-    function timeanddate( $ts, $adj = false )
-    {
+    function timeanddate( $ts, $adj = false ) {
         return $this->time( $ts, $adj ) . ", " . $this->date( $ts, $adj );
     }
 
-    function getValidSpecialPages()
-    {
+    function getValidSpecialPages() {
         global $wgValidSpecialPagesPt;
         return $wgValidSpecialPagesPt;
     }
 
-    function getSysopSpecialPages()
-    {
+    function getSysopSpecialPages() {
         global $wgSysopSpecialPagesPt;
         return $wgSysopSpecialPagesPt;
     }
 
-    function getDeveloperSpecialPages()
-    {
+    function getDeveloperSpecialPages() {
         global $wgDeveloperSpecialPagesPt;
         return $wgDeveloperSpecialPagesPt;
     }
 
-    function getMessage( $key )
-    {
-        global $wgAllMessagesPt;
-               if( isset( $wgAllMessagesPt[$key] ) ) {
-                       return $wgAllMessagesPt[$key];
-               } else {
-                       return parent::getMessage( $key );
-               }
+    function getMessage( $key ) {
+         global $wgAllMessagesPt;
+         if( isset( $wgAllMessagesPt[$key] ) ) {
+             return $wgAllMessagesPt[$key];
+         } else {
+             return parent::getMessage( $key );
+        }
     }
+
+    /**
+     * Portuguese numeric format is 123.456,78
+     */
+    function formatNum( $number, $year = false ) {
+        return $year ? $number : strtr($this->commafy($number), '.,', ',.' );
+    }
+
 }
 
 ?>