From 37f7039ee633e01a6e59eb4b818cd9a48eca33a0 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Niklas=20Laxstr=C3=B6m?= Date: Sat, 2 Jul 2005 20:26:02 +0000 Subject: [PATCH] (bugs 2633, 2672) Fix Estonian, Portuguese and Finnish numeric formatting Little code cleanup --- RELEASE-NOTES | 2 +- languages/LanguageEt.php | 28 ++++++++++++++++++++++------ languages/LanguageFi.php | 34 ++++++++++++++++++++-------------- languages/LanguagePt.php | 35 +++++++++++++++++++---------------- 4 files changed, 62 insertions(+), 37 deletions(-) diff --git a/RELEASE-NOTES b/RELEASE-NOTES index e615075958..ffddb5a9c5 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -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 === diff --git a/languages/LanguageEt.php b/languages/LanguageEt.php index 1ef7d062e9..8c21faea98 100644 --- a/languages/LanguageEt.php +++ b/languages/LanguageEt.php @@ -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 $_; + } + } + } ?> diff --git a/languages/LanguageFi.php b/languages/LanguageFi.php index 6355871374..bf4757226a 100644 --- a/languages/LanguageFi.php +++ b/languages/LanguageFi.php @@ -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( - ',' => ' ', - '.' => ',' - ); + /** + * 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 diff --git a/languages/LanguagePt.php b/languages/LanguagePt.php index 41c34ca650..695c8a596b 100644 --- a/languages/LanguagePt.php +++ b/languages/LanguagePt.php @@ -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), '.,', ',.' ); + } + } ?> -- 2.20.1